Skip to content

Commit

Permalink
Fix negative numbers parsing as strings
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed May 11, 2019
1 parent 9449701 commit b1d00a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion syntax/src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ string_literal = ${ "'" ~ single_quote_inner ~ "'" | symbol }
single_quote_inner = ${ ("\\'" | !"'" ~ ANY)* }

// Numbers are floating point.
number_literal = ${ "." ~ ASCII_DIGIT+ | ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT+)? }
number_literal = ${ "-"? ~ ("." ~ ASCII_DIGIT+ | ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT+)?) }

// A symbol is an unquoted string, usually used for identifying variable names.
symbol = ${ !ASCII_DIGIT ~ (!member_operator ~ (ASCII_ALPHANUMERIC | "_" | "-" | "?" | "!" | "." | "/"))+ }
Expand Down
11 changes: 11 additions & 0 deletions syntax/tests/parser/number-literals.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source = '''
println 100
println 102.5
println .25
println -255
'''
ast = '''
Block(
Expand Down Expand Up @@ -37,6 +38,16 @@ Block(
],
),
]),
Pipeline([
NamedCall(
function: VariablePath([
"println",
]),
args: [
-255,
],
),
]),
],
)
'''

0 comments on commit b1d00a5

Please sign in to comment.