diff --git a/CHANGES.md b/CHANGES.md index ca64d78..873b684 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/src/lexer.ml b/src/lexer.ml index 0468cb2..c02c9df 100644 --- a/src/lexer.ml +++ b/src/lexer.ml @@ -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) diff --git a/test/parse.ml b/test/parse.ml index 9e7dad4..b568d1a 100644 --- a/test/parse.ml +++ b/test/parse.ml @@ -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|};