Skip to content

Commit dc2941c

Browse files
committed
---
yaml --- r: 205822 b: refs/heads/beta c: dd24070 h: refs/heads/master v: v3
1 parent db87de0 commit dc2941c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+381
-995
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: 7397bdc9c516f3f714ad4974ecdd27f567d03d05
32+
refs/heads/beta: dd240707999216a64e7914c2290cb59c54d9c60c
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a

branches/beta/src/grammar/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ javac *.java
1212
rustc -O verify.rs
1313
for file in ../*/**.rs; do
1414
echo $file;
15-
grun RustLexer tokens -tokens < "$file" | ./verify "$file" RustLexer.tokens || break
15+
grun RustLexer tokens -tokens < $file | ./verify $file RustLexer.tokens || break
1616
done
1717
```
1818

branches/beta/src/grammar/RustLexer.g4

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
lexer grammar RustLexer;
22

3-
@lexer::members {
4-
public boolean is_at(int pos) {
5-
return _input.index() == pos;
6-
}
7-
}
8-
9-
103
tokens {
114
EQ, LT, LE, EQEQ, NE, GE, GT, ANDAND, OROR, NOT, TILDE, PLUT,
125
MINUS, STAR, SLASH, PERCENT, CARET, AND, OR, SHL, SHR, BINOP,
@@ -15,10 +8,14 @@ tokens {
158
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR,
169
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BINARY,
1710
LIT_BINARY_RAW, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
18-
COMMENT, SHEBANG
11+
COMMENT
1912
}
2013

21-
import xidstart , xidcontinue;
14+
/* Note: due to antlr limitations, we can't represent XID_start and
15+
* XID_continue properly. ASCII-only substitute. */
16+
17+
fragment XID_start : [_a-zA-Z] ;
18+
fragment XID_continue : [_a-zA-Z0-9] ;
2219

2320

2421
/* Expression-operator symbols */
@@ -93,63 +90,94 @@ fragment CHAR_ESCAPE
9390
| [xX] HEXIT HEXIT
9491
| 'u' HEXIT HEXIT HEXIT HEXIT
9592
| 'U' HEXIT HEXIT HEXIT HEXIT HEXIT HEXIT HEXIT HEXIT
96-
| 'u{' HEXIT '}'
97-
| 'u{' HEXIT HEXIT '}'
98-
| 'u{' HEXIT HEXIT HEXIT '}'
99-
| 'u{' HEXIT HEXIT HEXIT HEXIT '}'
100-
| 'u{' HEXIT HEXIT HEXIT HEXIT HEXIT '}'
101-
| 'u{' HEXIT HEXIT HEXIT HEXIT HEXIT HEXIT '}'
10293
;
10394
10495
fragment SUFFIX
10596
: IDENT
10697
;
10798
108-
fragment INTEGER_SUFFIX
109-
: { _input.LA(1) != 'e' && _input.LA(1) != 'E' }? SUFFIX
110-
;
111-
11299
LIT_CHAR
113-
: '\'' ( '\\' CHAR_ESCAPE
114-
| ~[\\'\n\t\r]
115-
| '\ud800' .. '\udbff' '\udc00' .. '\udfff'
116-
)
117-
'\'' SUFFIX?
100+
: '\'' ( '\\' CHAR_ESCAPE | ~[\\'\n\t\r] ) '\'' SUFFIX?
118101
;
119102

120103
LIT_BYTE
121-
: 'b\'' ( '\\' ( [xX] HEXIT HEXIT
122-
| [nrt\\'"0] )
123-
| ~[\\'\n\t\r] '\udc00'..'\udfff'?
124-
)
125-
'\'' SUFFIX?
104+
: 'b\'' ( '\\' ( [xX] HEXIT HEXIT | [nrt\\'"0] ) | ~[\\'\n\t\r] ) '\'' SUFFIX?
126105
;
127106

128107
LIT_INTEGER
129-
130-
: [0-9][0-9_]* INTEGER_SUFFIX?
131-
| '0b' [01_]+ INTEGER_SUFFIX?
132-
| '0o' [0-7_]+ INTEGER_SUFFIX?
133-
| '0x' [0-9a-fA-F_]+ INTEGER_SUFFIX?
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?
134112
;
135113

136114
LIT_FLOAT
137115
: [0-9][0-9_]* ('.' {
138-
/* dot followed by another dot is a range, not a float */
116+
/* dot followed by another dot is a range, no float */
139117
_input.LA(1) != '.' &&
140-
/* dot followed by an identifier is an integer with a function call, not a float */
118+
/* dot followed by an identifier is an integer with a function call, no float */
141119
_input.LA(1) != '_' &&
142-
!(_input.LA(1) >= 'a' && _input.LA(1) <= 'z') &&
143-
!(_input.LA(1) >= 'A' && _input.LA(1) <= 'Z')
120+
_input.LA(1) != 'a' &&
121+
_input.LA(1) != 'b' &&
122+
_input.LA(1) != 'c' &&
123+
_input.LA(1) != 'd' &&
124+
_input.LA(1) != 'e' &&
125+
_input.LA(1) != 'f' &&
126+
_input.LA(1) != 'g' &&
127+
_input.LA(1) != 'h' &&
128+
_input.LA(1) != 'i' &&
129+
_input.LA(1) != 'j' &&
130+
_input.LA(1) != 'k' &&
131+
_input.LA(1) != 'l' &&
132+
_input.LA(1) != 'm' &&
133+
_input.LA(1) != 'n' &&
134+
_input.LA(1) != 'o' &&
135+
_input.LA(1) != 'p' &&
136+
_input.LA(1) != 'q' &&
137+
_input.LA(1) != 'r' &&
138+
_input.LA(1) != 's' &&
139+
_input.LA(1) != 't' &&
140+
_input.LA(1) != 'u' &&
141+
_input.LA(1) != 'v' &&
142+
_input.LA(1) != 'w' &&
143+
_input.LA(1) != 'x' &&
144+
_input.LA(1) != 'y' &&
145+
_input.LA(1) != 'z' &&
146+
_input.LA(1) != 'A' &&
147+
_input.LA(1) != 'B' &&
148+
_input.LA(1) != 'C' &&
149+
_input.LA(1) != 'D' &&
150+
_input.LA(1) != 'E' &&
151+
_input.LA(1) != 'F' &&
152+
_input.LA(1) != 'G' &&
153+
_input.LA(1) != 'H' &&
154+
_input.LA(1) != 'I' &&
155+
_input.LA(1) != 'J' &&
156+
_input.LA(1) != 'K' &&
157+
_input.LA(1) != 'L' &&
158+
_input.LA(1) != 'M' &&
159+
_input.LA(1) != 'N' &&
160+
_input.LA(1) != 'O' &&
161+
_input.LA(1) != 'P' &&
162+
_input.LA(1) != 'Q' &&
163+
_input.LA(1) != 'R' &&
164+
_input.LA(1) != 'S' &&
165+
_input.LA(1) != 'T' &&
166+
_input.LA(1) != 'U' &&
167+
_input.LA(1) != 'V' &&
168+
_input.LA(1) != 'W' &&
169+
_input.LA(1) != 'X' &&
170+
_input.LA(1) != 'Y' &&
171+
_input.LA(1) != 'Z'
144172
}? | ('.' [0-9][0-9_]*)? ([eE] [-+]? [0-9][0-9_]*)? SUFFIX?)
145173
;
146174

147175
LIT_STR
148176
: '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"' SUFFIX?
149177
;
150178

151-
LIT_BINARY : 'b' LIT_STR ;
152-
LIT_BINARY_RAW : 'b' LIT_STR_RAW ;
179+
LIT_BINARY : 'b' LIT_STR SUFFIX?;
180+
LIT_BINARY_RAW : 'rb' LIT_STR_RAW SUFFIX?;
153181

154182
/* this is a bit messy */
155183

@@ -169,27 +197,21 @@ LIT_STR_RAW
169197

170198
QUESTION : '?';
171199

172-
IDENT : XID_Start XID_Continue* ;
200+
IDENT : XID_start XID_continue* ;
173201

174202
fragment QUESTION_IDENTIFIER : QUESTION? IDENT;
175203

176204
LIFETIME : '\'' IDENT ;
177205

178206
WHITESPACE : [ \r\n\t]+ ;
179207

180-
UNDOC_COMMENT : '////' ~[\n]* -> type(COMMENT) ;
208+
UNDOC_COMMENT : '////' ~[\r\n]* -> type(COMMENT) ;
181209
YESDOC_COMMENT : '///' ~[\r\n]* -> type(DOC_COMMENT) ;
182210
OUTER_DOC_COMMENT : '//!' ~[\r\n]* -> type(DOC_COMMENT) ;
183-
LINE_COMMENT : '//' ( ~[/\n] ~[\n]* )? -> type(COMMENT) ;
211+
LINE_COMMENT : '//' ~[\r\n]* -> type(COMMENT) ;
184212

185213
DOC_BLOCK_COMMENT
186214
: ('/**' ~[*] | '/*!') (DOC_BLOCK_COMMENT | .)*? '*/' -> type(DOC_COMMENT)
187215
;
188216

189217
BLOCK_COMMENT : '/*' (BLOCK_COMMENT | .)*? '*/' -> type(COMMENT) ;
190-
191-
/* these appear at the beginning of a file */
192-
193-
SHEBANG : '#!' { is_at(2) && _input.LA(1) != '[' }? ~[\r\n]* -> type(SHEBANG) ;
194-
195-
UTF8_BOM : '\ufeff' { is_at(1) }? -> skip ;

branches/beta/src/grammar/check.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ failed=0
1818
skipped=0
1919

2020
check() {
21-
grep --silent "// ignore-lexer-test" "$1";
21+
grep --silent "// ignore-lexer-test" $1;
2222

2323
# if it's *not* found...
2424
if [ $? -eq 1 ]; then
2525
cd $2 # This `cd` is so java will pick up RustLexer.class. I couldn't
26-
# figure out how to wrangle the CLASSPATH, just adding build/grammar
27-
# didn't seem to have any effect.
26+
# figure out how to wrangle the CLASSPATH, just adding build/grammr didn't
27+
# seem to have anny effect.
2828
if $3 RustLexer tokens -tokens < $1 | $4 $1 $5; then
2929
echo "pass: $1"
3030
passed=`expr $passed + 1`
@@ -39,7 +39,7 @@ check() {
3939
}
4040

4141
for file in $(find $1 -iname '*.rs' ! -path '*/test/compile-fail*'); do
42-
check "$file" $2 $3 $4 $5
42+
check $file $2 $3 $4 $5
4343
done
4444

4545
printf "\ntest result: "

0 commit comments

Comments
 (0)