Add chars

main
trivernis 4 months ago
parent 18fe0c6a18
commit 50b3cf41ad
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -13,9 +13,10 @@ operator = { "+" | "-" | "*" | "/" | "&&" | "||" }
ident = @{ ALPHABETIC ~ (ALPHABETIC | NUMBER | "_")* | quoted_indent } ident = @{ ALPHABETIC ~ (ALPHABETIC | NUMBER | "_")* | quoted_indent }
quoted_indent = _{ "`" ~ (!"`" ~ ANY)+ ~ "`" } quoted_indent = _{ "`" ~ (!"`" ~ ANY)+ ~ "`" }
literal = { string | number | boolean } literal = { string | number | boolean | char }
string = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" } string = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" }
char = { "'" ~ !"'" ~ ANY ~ "'" }
number = _{ byte | float | integer } number = _{ byte | float | integer }
integer = @{ "-"? ~ ASCII_DIGIT+ } integer = @{ "-"? ~ ASCII_DIGIT+ }
float = @{ float = @{

@ -75,6 +75,20 @@ fn it_parses_strings() {
]); ]);
} }
#[test]
fn it_parses_chars() {
parses_to!(parser: SnekParser, input: "'c'", rule: Rule::literal, tokens: [
literal(0, 3, [
char(0, 3)
])
]);
parses_to!(parser: SnekParser, input: r"'\''", rule: Rule::literal, tokens: [
literal(0, 3, [
char(0, 3)
])
]);
}
#[test] #[test]
fn it_parses_booleans() { fn it_parses_booleans() {
parses_to!(parser: SnekParser, input: "true", rule: Rule::literal, tokens: [ parses_to!(parser: SnekParser, input: "true", rule: Rule::literal, tokens: [

Loading…
Cancel
Save