diff options
| author | Corey Richardson <corey@octayn.net> | 2014-07-04 22:30:39 -0700 |
|---|---|---|
| committer | Corey Richardson <corey@octayn.net> | 2014-07-09 00:06:29 -0700 |
| commit | f512779554a436d11dd9ffde4c198da6241dfd58 (patch) | |
| tree | 6431e33802c11c3ba27484028fb93d2451e3373e /src/libsyntax/parse/token.rs | |
| parent | cc4213418e3ab225867d8e3911f592481b1bbffc (diff) | |
| download | rust-f512779554a436d11dd9ffde4c198da6241dfd58.tar.gz rust-f512779554a436d11dd9ffde4c198da6241dfd58.zip | |
lexer: lex WS/COMMENT/SHEBANG rather than skipping
Now, the lexer will categorize every byte in its input according to the grammar. The parser skips over these while parsing, thus avoiding their presence in the input to syntax extensions.
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 83d373d033b..e65f9f208a3 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -97,8 +97,18 @@ pub enum Token { /* For interpolation */ INTERPOLATED(Nonterminal), - DOC_COMMENT(Ident), + + // Junk. These carry no data because we don't really care about the data + // they *would* carry, and don't really want to allocate a new ident for + // them. Instead, users could extract that from the associated span. + + /// Whitespace + WS, + /// Comment + COMMENT, + SHEBANG(Ident), + EOF, } @@ -231,6 +241,10 @@ pub fn to_string(t: &Token) -> String { /* Other */ DOC_COMMENT(s) => get_ident(s).get().to_string(), EOF => "<eof>".to_string(), + WS => " ".to_string(), + COMMENT => "/* */".to_string(), + SHEBANG(s) => format!("/* shebang: {}*/", s.as_str()), + INTERPOLATED(ref nt) => { match nt { &NtExpr(ref e) => ::print::pprust::expr_to_string(&**e), |
