File tree Expand file tree Collapse file tree 3 files changed +35
-17
lines changed
src/Domain/HydraScript.Domain.FrontEnd/Lexer Expand file tree Collapse file tree 3 files changed +35
-17
lines changed Original file line number Diff line number Diff line change @@ -31,12 +31,12 @@ public static class TokenTypesJson
3131 },
3232 {
3333 "tag": "NullLiteral",
34- "pattern": "null",
34+ "pattern": "(?<![a-zA-Z0-9])( null)(?![a-zA-Z0-9]) ",
3535 "priority": 4
3636 },
3737 {
3838 "tag": "BooleanLiteral",
39- "pattern": "true|false",
39+ "pattern": "(?<![a-zA-Z0-9])( true|false)(?![a-zA-Z0-9]) ",
4040 "priority": 5
4141 },
4242 {
@@ -46,7 +46,7 @@ public static class TokenTypesJson
4646 },
4747 {
4848 "tag": "Keyword",
49- "pattern": "let|const|function|if|else|while|break|continue|return|as|type",
49+ "pattern": "(?<![a-zA-Z0-9])( let|const|function|if|else|while|break|continue|return|as|type)(?![a-zA-Z0-9]) ",
5050 "priority": 11
5151 },
5252 {
Original file line number Diff line number Diff line change 1- using System . Collections ;
1+ using Xunit ;
22
33namespace HydraScript . Tests . TestData ;
44
5- public class LexerSuccessData : IEnumerable < object [ ] >
5+ public class LexerSuccessData : TheoryData < string >
66{
7- public IEnumerator < object [ ] > GetEnumerator ( )
7+ public LexerSuccessData ( )
88 {
9- yield return new object [ ] { "a + b - c return while do" } ;
10- yield return new object [ ] { "=> abc null true false" } ;
11- yield return new object [ ] { "{ . } , ( ) [] =?:" } ;
9+ Add ( "a + b - c return while do" ) ;
10+ Add ( "=> abc null true false" ) ;
11+ Add ( "{ . } , ( ) [] =?:" ) ;
1212 }
13-
14- IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
1513}
1614
17- public class LexerFailData : IEnumerable < object [ ] >
15+ public class LexerFailData : TheoryData < string >
1816{
19- public IEnumerator < object [ ] > GetEnumerator ( )
17+ public LexerFailData ( )
2018 {
21- yield return new object [ ] { "a + v $$$" } ;
22- yield return new object [ ] { "kkk &" } ;
23- yield return new object [ ] { "|| |" } ;
19+ Add ( "a + v $$$" ) ;
20+ Add ( "kkk &" ) ;
21+ Add ( "|| |" ) ;
2422 }
23+ }
2524
26- IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
25+ public class LexerKeywordInsideIdentData : TheoryData < string >
26+ {
27+ public LexerKeywordInsideIdentData ( )
28+ {
29+ Add ( "constExpr" ) ;
30+ Add ( "letVarConst" ) ;
31+ Add ( "nullObj" ) ;
32+ Add ( "trueStmt" ) ;
33+ Add ( "falseStmt" ) ;
34+ Add ( "returnResult" ) ;
35+ }
2736}
Original file line number Diff line number Diff line change 11using HydraScript . Domain . FrontEnd . Lexer ;
22using HydraScript . Domain . FrontEnd . Lexer . Impl ;
3+ using HydraScript . Domain . FrontEnd . Lexer . TokenTypes ;
34using HydraScript . Infrastructure ;
45using HydraScript . Tests . TestData ;
56using Xunit ;
@@ -44,4 +45,12 @@ public void GetTokensSkipIgnorableTypesTest()
4445 var tokens = _regexLexer . GetTokens ( text ) ;
4546 Assert . DoesNotContain ( _regexLexer . Structure . FindByTag ( "Comment" ) , tokens . Select ( x => x . Type ) ) ;
4647 }
48+
49+ [ Theory , ClassData ( typeof ( LexerKeywordInsideIdentData ) ) ]
50+ public void GetTokens_KeywordInsideIdent_Ident ( string input )
51+ {
52+ var tokens = _regexLexer . GetTokens ( input ) ;
53+ var token = tokens . First ( ) ;
54+ token . Type . Should ( ) . Be ( new TokenType ( "Ident" ) ) ;
55+ }
4756}
You can’t perform that action at this time.
0 commit comments