Skip to content

Commit 7586abf

Browse files
committed
Adjust Antlr4 lexer to include suffixes.
This makes the formal lexical grammar (more closely) reflect the one implemented by the compiler.
1 parent 606a309 commit 7586abf

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

src/grammar/RustLexer.g4

+15-29
Original file line numberDiff line numberDiff line change
@@ -92,49 +92,35 @@ fragment CHAR_ESCAPE
9292
| 'U' HEXIT HEXIT HEXIT HEXIT HEXIT HEXIT HEXIT HEXIT
9393
;
9494
95-
LIT_CHAR
96-
: '\'' ( '\\' CHAR_ESCAPE | ~[\\'\n\t\r] ) '\''
95+
fragment SUFFIX
96+
: IDENT
9797
;
9898
99-
LIT_BYTE
100-
: 'b\'' ( '\\' ( [xX] HEXIT HEXIT | [nrt\\'"0] ) | ~[\\'\n\t\r] ) '\''
99+
LIT_CHAR
100+
: '\'' ( '\\' CHAR_ESCAPE | ~[\\'\n\t\r] ) '\'' SUFFIX?
101101
;
102102

103-
fragment INT_SUFFIX
104-
: 'i'
105-
| 'i8'
106-
| 'i16'
107-
| 'i32'
108-
| 'i64'
109-
| 'u'
110-
| 'u8'
111-
| 'u16'
112-
| 'u32'
113-
| 'u64'
103+
LIT_BYTE
104+
: 'b\'' ( '\\' ( [xX] HEXIT HEXIT | [nrt\\'"0] ) | ~[\\'\n\t\r] ) '\'' SUFFIX?
114105
;
115106

116107
LIT_INTEGER
117-
: [0-9][0-9_]* INT_SUFFIX?
118-
| '0b' [01][01_]* INT_SUFFIX?
119-
| '0o' [0-7][0-7_]* INT_SUFFIX?
120-
| '0x' [0-9a-fA-F][0-9a-fA-F_]* INT_SUFFIX?
121-
;
122-
123-
fragment FLOAT_SUFFIX
124-
: 'f32'
125-
| 'f64'
108+
: [0-9][0-9_]* SUFFIX?
109+
| '0b' [01][01_]* SUFFIX?
110+
| '0o' [0-7][0-7_]* SUFFIX?
111+
| '0x' [0-9a-fA-F][0-9a-fA-F_]* SUFFIX?
126112
;
127113

128114
LIT_FLOAT
129-
: [0-9][0-9_]* ('.' | ('.' [0-9][0-9_]*)? ([eE] [-+]? [0-9][0-9_]*)? FLOAT_SUFFIX?)
115+
: [0-9][0-9_]* ('.' | ('.' [0-9][0-9_]*)? ([eE] [-+]? [0-9][0-9_]*)? SUFFIX?)
130116
;
131117

132118
LIT_STR
133-
: '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"'
119+
: '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"' SUFFIX?
134120
;
135121

136-
LIT_BINARY : 'b' LIT_STR ;
137-
LIT_BINARY_RAW : 'rb' LIT_STR_RAW ;
122+
LIT_BINARY : 'b' LIT_STR SUFFIX?;
123+
LIT_BINARY_RAW : 'rb' LIT_STR_RAW SUFFIX?;
138124

139125
/* this is a bit messy */
140126

@@ -148,7 +134,7 @@ fragment LIT_STR_RAW_INNER2
148134
;
149135

150136
LIT_STR_RAW
151-
: 'r' LIT_STR_RAW_INNER
137+
: 'r' LIT_STR_RAW_INNER SUFFIX?
152138
;
153139

154140
IDENT : XID_start XID_continue* ;

0 commit comments

Comments
 (0)