Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 7715f95

Browse files
(fix) update Lexer to reflect GraphQL "greedy" RFC (#4)
1 parent d8e27e3 commit 7715f95

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

graphite_language/lib/src/lexer/lexer.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,13 @@ class Lexer {
257257
}
258258
}
259259

260+
final code = _peek();
261+
262+
if (code == 0x2e /* . */ || code == 0x45 /* E */ || code == 0x65 /* e */) {
263+
throw _createSyntaxException(
264+
getUnexpectedCharExceptionMessage(code), Spanning(start, _position));
265+
}
266+
260267
return Token(
261268
isFloat ? TokenKind.floatValue : TokenKind.integerValue,
262269
Spanning(start, _position),

graphite_language/test/lexer_test.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void main() {
114114
Position(offset: 1, line: 1, column: 2)),
115115
value: '0'));
116116

117+
expect(() => lexOne('01'), throwsA(const TypeMatcher<SyntaxException>()));
118+
expect(() => lexOne('01.23'), throwsA(const TypeMatcher<SyntaxException>()));
119+
117120
expect(
118121
lexOne('52321'),
119122
const Token(
@@ -212,7 +215,10 @@ void main() {
212215
() => lexOne('2e++32'), throwsA(const TypeMatcher<SyntaxException>()));
213216
expect(() => lexOne('2.'), throwsA(const TypeMatcher<SyntaxException>()));
214217
expect(() => lexOne('.1'), throwsA(const TypeMatcher<SyntaxException>()));
215-
expect(() => lexOne('1.F'), throwsA(const TypeMatcher<SyntaxException>()));
218+
expect(() => lexOne('1.E'), throwsA(const TypeMatcher<SyntaxException>()));
219+
expect(() => lexOne('1.2e3e'), throwsA(const TypeMatcher<SyntaxException>()));
220+
expect(() => lexOne('1.2e3.4'), throwsA(const TypeMatcher<SyntaxException>()));
221+
expect(() => lexOne('1.23.4'), throwsA(const TypeMatcher<SyntaxException>()));
216222
});
217223

218224
group('String', () {
@@ -240,6 +246,11 @@ void main() {
240246
Spanning(Position(offset: 0, line: 1, column: 1),
241247
Position(offset: 14, line: 1, column: 15)),
242248
value: ' with space '));
249+
250+
expect(
251+
() => lexOne('"""'), throwsA(const TypeMatcher<SyntaxException>()));
252+
expect(
253+
() => lexOne('""""'), throwsA(const TypeMatcher<SyntaxException>()));
243254
});
244255

245256
test('lexes escape sequence', () {
@@ -345,7 +356,8 @@ void main() {
345356
'1| query {\n'
346357
'2| user(username: "\\u123") {\n'
347358
' ^^^^^\n'
348-
'3| firstName,\n\n')), skip: true);
359+
'3| firstName,\n\n')),
360+
skip: true);
349361
});
350362

351363
test('throws on invalid source characters', () {

0 commit comments

Comments
 (0)