File tree Expand file tree Collapse file tree 8 files changed +21
-10
lines changed
src/Domain/HydraScript.Domain.FrontEnd
tests/HydraScript.UnitTests/Domain/FrontEnd Expand file tree Collapse file tree 8 files changed +21
-10
lines changed Original file line number Diff line number Diff line change 1414 <PackageVersion Include =" System.IO.Abstractions" Version =" 22.0.16" />
1515 <PackageVersion Include =" Visitor.NET" Version =" 4.2.0" />
1616 <PackageVersion Include =" Visitor.NET.AutoVisitableGen" Version =" 1.5.2" />
17+ <PackageVersion Include =" ZLinq" Version =" 1.5.2" />
1718 <PackageVersion Include =" ZLogger" Version =" 2.5.10" />
1819 <PackageVersion Include =" ZString" Version =" 2.6.0" />
1920 </ItemGroup >
Original file line number Diff line number Diff line change 33 <ItemGroup >
44 <PackageReference Include =" Visitor.NET" />
55 <PackageReference Include =" Visitor.NET.AutoVisitableGen" PrivateAssets =" all" />
6+ <PackageReference Include =" ZLinq" />
67 <PackageReference Include =" ZString" />
78 </ItemGroup >
89
Original file line number Diff line number Diff line change 33
44namespace HydraScript . Domain . FrontEnd . Lexer ;
55
6- public interface IStructure : IEnumerable < TokenType >
6+ public interface IStructure : IReadOnlyList < TokenType >
77{
88 public Regex Regex { get ; }
99
Original file line number Diff line number Diff line change 1+ using System . Collections . Frozen ;
12using HydraScript . Domain . FrontEnd . Lexer . TokenTypes ;
23
34namespace HydraScript . Domain . FrontEnd . Lexer ;
45
56public interface ITokenTypesProvider
67{
7- IEnumerable < TokenType > GetTokenTypes ( ) ;
8+ FrozenDictionary < string , TokenType > GetTokenTypes ( ) ;
89}
Original file line number Diff line number Diff line change @@ -24,8 +24,9 @@ public IEnumerator<Token> GetEnumerator()
2424 {
2525 foreach ( Match match in Structure . Regex . Matches ( _text ) )
2626 {
27- foreach ( var type in Structure )
27+ for ( var i = 0 ; i < Structure . Count ; i ++ )
2828 {
29+ var type = Structure [ i ] ;
2930 var group = match . Groups [ type . Tag ] ;
3031
3132 if ( ! group . Success || type . CanIgnore ( ) ) continue ;
Original file line number Diff line number Diff line change @@ -10,9 +10,7 @@ namespace HydraScript.Domain.FrontEnd.Lexer.Impl;
1010public class Structure < TContainer > ( ITokenTypesProvider provider ) : IStructure
1111 where TContainer : IGeneratedRegexContainer
1212{
13- private FrozenDictionary < string , TokenType > Types { get ; } = provider . GetTokenTypes ( )
14- . Concat ( [ new EndOfProgramType ( ) , new ErrorType ( ) ] )
15- . ToFrozenDictionary ( x => x . Tag ) ;
13+ private FrozenDictionary < string , TokenType > Types { get ; } = provider . GetTokenTypes ( ) ;
1614
1715 public Regex Regex { get ; } = TContainer . Regex ;
1816
@@ -27,4 +25,8 @@ public IEnumerator<TokenType> GetEnumerator() =>
2725
2826 [ ExcludeFromCodeCoverage ]
2927 IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
28+
29+ public int Count => Types . Values . Length ;
30+
31+ public TokenType this [ int index ] => Types . Values [ index ] ;
3032}
Original file line number Diff line number Diff line change 1+ using System . Collections . Frozen ;
12using HydraScript . Domain . FrontEnd . Lexer . TokenTypes ;
3+ using ZLinq ;
24
35namespace HydraScript . Domain . FrontEnd . Lexer . Impl ;
46
57public class TokenTypesProvider : ITokenTypesProvider
68{
7- public IEnumerable < TokenType > GetTokenTypes ( ) =>
8- Constants . TokenTypes . Stream
9+ public FrozenDictionary < string , TokenType > GetTokenTypes ( ) =>
10+ Constants . TokenTypes . Stream . AsValueEnumerable ( )
911 . OrderBy ( x => x . Priority )
1012 . Select ( x => x . CanIgnore
1113 ? new IgnorableType ( x . Tag )
12- : new TokenType ( x . Tag ) ) ;
14+ : new TokenType ( x . Tag ) )
15+ . Concat ( [ new EndOfProgramType ( ) , new ErrorType ( ) ] )
16+ . ToFrozenDictionary ( x => x . Tag ) ;
1317}
Original file line number Diff line number Diff line change 1+ using System . Collections . Frozen ;
12using HydraScript . Domain . FrontEnd . Lexer ;
23using HydraScript . Domain . FrontEnd . Lexer . Impl ;
34using HydraScript . Domain . FrontEnd . Lexer . TokenTypes ;
@@ -14,7 +15,7 @@ public void ToStringCorrectTest()
1415 {
1516 new ( "MyToken" ) ,
1617 new ( "OneToSeven" )
17- } ;
18+ } . ToFrozenDictionary ( x => x . Tag ) ;
1819 var provider = Substitute . For < ITokenTypesProvider > ( ) ;
1920 provider . GetTokenTypes ( ) . Returns ( tokenTypes ) ;
2021 var structure = new Structure < GeneratedRegexContainer > ( provider ) ;
You can’t perform that action at this time.
0 commit comments