Skip to content

Commit

Permalink
Parse numbers as part of the concrete syntax tree, even when incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Mar 3, 2024
1 parent 8bad971 commit 1706945
Show file tree
Hide file tree
Showing 8 changed files with 3,271 additions and 3,039 deletions.
5 changes: 5 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ module.exports = grammar({
$.external_command,
$.identifier,
$.string,
$.numeric_error,
seq("(", $.expression, ")"),
),
),
Expand Down Expand Up @@ -328,6 +329,10 @@ module.exports = grammar({

identifier: (_) => /[a-zA-Z_][a-zA-Z0-9_-]*/,

// Numbers aren't allowed as values, but we capture them anyway as errors so
// they don't mess up the whole syntax
numeric_error: (_) => /(\d+\.\d*|\d+)/,

// `# ...` comment
comment: (_) => token(prec(-1, /#.*/)),
},
Expand Down
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ errors_expected := '''
# Files used for testing that Just itself might not understand
no_just_parsing := '''
test/readme.just
test/highlight/invalid-syntax.just
'''

# List all recipes
Expand Down
3 changes: 3 additions & 0 deletions queries-src/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@
"windows-powershell"
"windows-shell"
)))

; Numbers are part of the syntax tree, even if disallowed
(numeric_error) @error
3 changes: 3 additions & 0 deletions queries/just/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@
"windows-powershell"
"windows-shell"
)))

; Numbers are part of the syntax tree, even if disallowed
(numeric_error) @error
8 changes: 8 additions & 0 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1706945

Please sign in to comment.