Skip to content

Commit

Permalink
don't let ids start with a number (#161)
Browse files Browse the repository at this point in the history
Fixes #159

Co-authored-by: Li Haoyi <[email protected]>
  • Loading branch information
nicklan and lihaoyi-databricks authored May 30, 2023
1 parent 1b4a5c0 commit f4bed42
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sjsonnet/src/sjsonnet/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Parser(val currentFile: Path) {
def Pos[_: P]: P[Position] = Index.map(offset => new Position(fileScope, offset))

def id[_: P] = P(
CharIn("_a-zA-Z0-9") ~~
CharIn("_a-zA-Z") ~~
CharsWhileIn("_a-zA-Z0-9", 0)
).!.filter(s => !keywords.contains(s))

Expand Down
3 changes: 3 additions & 0 deletions sjsonnet/test/src/sjsonnet/ParserTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ object ParserTests extends TestSuite{
test("givenDuplicateFieldsInListComprehension_expectError") {
parseErr("""{ ["bar"]: x for x in [1, 2]}""") ==> """Expected no duplicate field: "bar" :1:29, found "}""""
}
test("id starts with number") {
parseErr("""{1_n: "foo",}""") ==> """Expected "}":1:2, found "1_n: \"foo\"""""
}
}
}

0 comments on commit f4bed42

Please sign in to comment.