Skip to content

Commit

Permalink
Disallow r# at the start of identifiers (kdl v2)
Browse files Browse the repository at this point in the history
  • Loading branch information
eilvelia committed Oct 15, 2023
1 parent f06e010 commit 42ec069
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- Updated to KDL v2.0:
- - Added Line Tabulation U+000B to whitespace characters
- - Removed `\/` from escape sequences
- Dropped support for OCaml < 4.10.0.
- - Identifiers cannot start with `r#` anymore
- Dropped support for OCaml < 4.10.0

## 0.1.0 (2022-10-01)

Expand Down
1 change: 1 addition & 0 deletions src/lexer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ let rec main lexbuf =
Buffer.reset string_buffer;
set_string_start lexbuf;
string lexbuf
| "r#", Star identchar -> error "An identifier cannot start with r#"
| '-', startident, Star identchar -> IDENT (Sedlexing.Utf8.lexeme lexbuf)
| '-' -> IDENT "-"
| Sub (startident, '-'), Star identchar -> IDENT (Sedlexing.Utf8.lexeme lexbuf)
Expand Down
17 changes: 17 additions & 0 deletions test/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ let%expect_test "(raw) string literals as a property name" =
test {|- "key\n"="value" r##"key\t"##=true|};
[%expect {| (- ("key\n" (string value)) ("key\\t" true)) |}]

let%expect_test "identifiers cannot start with r#" =
test {|- r#=0|};
test {|- r#a=1|};
test {|- r#<=1|};
[%expect {|
Error: :1:3-1:5: An identifier cannot start with r#
Error: :1:3-1:6: An identifier cannot start with r#
Error: :1:3-1:5: An identifier cannot start with r# |}]

let%expect_test "identifiers cannot contain special characters (<, etc.)" =
test {|- a<=1|};
[%expect {| Error: :1:4-1:5: Illegal character '<' |}]

let%expect_test "-- as an identifier" =
test {|- --=0|};
[%expect {| (- (-- (int 0))) |}]

let%expect_test "single-line comments" =
test {|node // comment // commment
// comment node|};
Expand Down

0 comments on commit 42ec069

Please sign in to comment.