Lexical syntax simplification - #90
Conversation
|
Another benefit of this is that the output of the lexer can be only spans and their associated token type, rather than having to do any work. |
There was a problem hiding this comment.
This can't just be 'r' LIT_STR_RAW_INNER2? (and the inner tokens should probably be swapped).
|
This needs to take into account rust-lang/rust#14400 still. |
There was a problem hiding this comment.
The exponent [0-9]* part—should it be [0-9_]*?
Also I think this will be tightening what is accepted; at present, for example, 1. is acceptable (but not 1.f32 for clear reasons), but this change will break that. Is that deliberate? Desirable? &c.
There was a problem hiding this comment.
Good catch. That was not deliberate, I didn't mean to change the float literal syntax at all.
|
+1, sounds like an improvement for |
|
@kballard is the CRLF stuff correct? I extended the places that accept newline to also accept '\r\n', but not '\r', and I've removed '\r' from the whitespace skipping. |
|
@cmr My patch actually allows bare |
There was a problem hiding this comment.
Shouldn't [^'\n\t\r] be ~['\n\t\r]?
There was a problem hiding this comment.
Also the character set needs to include \\ or else invalid character escapes will end up matching anyway.
|
This grammar is wildly ambiguous. Identifiers, numbers and operators can be tokenized in multiple ways. |
|
@zwarich do you have an example of an ambiguous sequence of tokens? |
|
"12.12" could be INTEGER(12) DOT INTEGER(12) |
|
etc. will be relatively easy to fix. |
|
Doesn't antlr4 pick the longest matching token? |
|
(Yeah, isn't the maximal munch principal the standard way to resolve "ambiguities" like this?) |
|
I like the idea of keeping comments after lexing so pretty-printers / refactoring tools can use the same lexer as the compiler, but how about we just make comment dropping a micropass between the lexer and parser instead of adding to the parser workload? |
|
Sure, whatever. |
|
Fixed most things, and verified that it works as I expect. |
|
cc @nikomatsakis @pcwalton @brson I've updated this. It behaves as I expect for the code I've run it against, and accepts/rejects everything it should in the compiler/libs/testsuite/servo. |
|
Accepted as RFC 21 per https://github.com/mozilla/rust/wiki/Meeting-weekly-2014-05-27#lexer-changes |
Fix typo in tutorial
Rendered