Add ident expression

main
trivernis 4 months ago
parent 2d6d8b6e51
commit eb3048b4f4
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -2,7 +2,7 @@ file = { "hello world" }
expr = { infix_expr | term }
term = _{ literal | "(" ~ expr ~ ")" }
term = _{ ident | literal | "(" ~ expr ~ ")" }
infix_expr = {
#lhs = term ~ operator ~ #rhs = expr
@ -10,20 +10,18 @@ infix_expr = {
operator = { "+" | "-" | "*" | "/" | "&&" | "||" }
literal = { string | number | boolean }
string = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" }
ident = @{ ALPHABETIC ~ (ALPHABETIC | NUMBER | "_")* | quoted_indent }
quoted_indent = _{ "`" ~ (!"`" ~ ANY)+ ~ "`" }
number = _{ byte | float | integer }
literal = { string | number | boolean }
string = { "\"" ~ (!"\"" ~ ANY)* ~ "\"" }
number = _{ byte | float | integer }
integer = @{ "-"? ~ ASCII_DIGIT+ }
float = @{
float = @{
"-"? ~ (ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT* | ASCII_DIGIT* ~ "." ~ ASCII_DIGIT+)
}
byte = @{ "0x" ~ ASCII_HEX_DIGIT{1, 2} | "0b" ~ ASCII_BIN_DIGIT{0, 8} }
byte = @{ "0x" ~ ASCII_HEX_DIGIT{1, 2} | "0b" ~ ASCII_BIN_DIGIT{0, 8} }
boolean = @{ "true" | "false" }
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }

@ -21,6 +21,21 @@ fn it_parses_addition() {
]);
}
#[test]
fn it_parses_addition_with_variables() {
parses_to!(parser: SnekParser, input: "first + second", rule: Rule::expr, tokens: [
expr(0, 14, [
infix_expr(0, 14, [
ident(0, 5),
operator(6, 7),
expr(8, 14, [
ident(8, 14)
])
])
])
]);
}
#[test]
fn it_parses_subtraction() {
parses_to!(parser: SnekParser, input: "1.0 - 1.1", rule: Rule::expr, tokens: [

Loading…
Cancel
Save