Quoted strings and octal character literals in ocamllex actions#1912
Quoted strings and octal character literals in ocamllex actions#1912gasche merged 8 commits intoocaml:trunkfrom
Conversation
|
One thing I wonder is if we could simply reuse parsing/lexer.mll directly. That would avoid having to maintain two lexers and would ensure that the lexical conventions are always the same. |
That counts as a bug-fix. |
damiendoligez
left a comment
There was a problem hiding this comment.
Pretty good, but the assert false question needs to be addressed.
lex/lexer.mll
Outdated
| warning lexbuf | ||
| (Printf.sprintf | ||
| "illegal uchar escape in string: '\\u{%s}'" s); | ||
| store_string_uchar (Uchar.unsafe_of_int v); |
There was a problem hiding this comment.
Unless I'm mistaken, this will assert false in buffer.ml (after printing the warning) if v is too large or negative.
There was a problem hiding this comment.
I'll make the warning an error. Decimal escape sequences have the same problem (e.g. "\256").
lex/lexer.mll
Outdated
|
|
||
| (* | ||
| Lexers comment and action are quite similar, | ||
| they should lex both strings and characters, |
There was a problem hiding this comment.
You should update this comment.
lex/lexer.mll
Outdated
| | '{' (['a'-'z' '_'] * as delim) '|' | ||
| { quoted_string delim lexbuf; | ||
| comment lexbuf } | ||
| | '\'' |
There was a problem hiding this comment.
You change this one from "'" to '\'' but not the one in [action] (line 321). Why?
There was a problem hiding this comment.
I found it more logical, but apparently "'" is more used in this file.
In that case, I suppose octal escape sequences should be allowed in characters too? |
|
Looks good now. |
This contains the same fix as #1901, but for ocamllex actions. Without this, actions like
would not compile, while they contain valid ocaml code.
The changes are
I tried to keep it a bugfix, not a language change. But as a side effect, octal and unicode escape sequences are now allowed in ocamllex strings too.