@@ -5,10 +5,11 @@ This Source Code Form is subject to the terms of the
55at http://mozilla.org/MPL/2.0/.
66----------------------------------------------------------*/
77
8+ using OneScript . Language . LexicalAnalysis ;
89using System ;
910using System . Collections . Generic ;
1011using System . Runtime . CompilerServices ;
11- using OneScript . Language . LexicalAnalysis ;
12+ using static OneScript . Language . LanguageDef ;
1213
1314namespace OneScript . Language
1415{
@@ -21,14 +22,20 @@ public static class LanguageDef
2122
2223 private static readonly IdentifiersTrie < Token > _stringToToken = new IdentifiersTrie < Token > ( ) ;
2324
24- private static readonly IdentifiersTrie < bool > _undefined = new IdentifiersTrie < bool > ( ) ;
25- private static readonly IdentifiersTrie < bool > _booleans = new IdentifiersTrie < bool > ( ) ;
26- private static readonly IdentifiersTrie < bool > _logicalOp = new IdentifiersTrie < bool > ( ) ;
27-
28- private static readonly IdentifiersTrie < bool > _preprocImport = new IdentifiersTrie < bool > ( ) ;
29-
3025 const int BUILTINS_INDEX = ( int ) Token . ByValParam ;
3126
27+ public enum WordType
28+ {
29+ Undefined ,
30+ Boolean ,
31+ Logical ,
32+ Null ,
33+ Preproc ,
34+ None
35+ } ;
36+
37+ private static readonly IdentifiersTrie < WordType > _specwords = new IdentifiersTrie < WordType > ( ) ;
38+
3239 static LanguageDef ( )
3340 {
3441 _priority . Add ( Token . Plus , 5 ) ;
@@ -52,21 +59,26 @@ static LanguageDef()
5259
5360 #region constants
5461
55- _undefined . Add ( "Undefined" , true ) ;
56- _undefined . Add ( "Неопределено" , true ) ;
62+ _specwords . Add ( "Undefined" , WordType . Undefined ) ;
63+ _specwords . Add ( "Неопределено" , WordType . Undefined ) ;
5764
58- _booleans . Add ( "True" , true ) ;
59- _booleans . Add ( "False" , true ) ;
60- _booleans . Add ( "Истина" , true ) ;
61- _booleans . Add ( "Ложь" , true ) ;
65+ _specwords . Add ( "True" , WordType . Boolean ) ;
66+ _specwords . Add ( "False" , WordType . Boolean ) ;
67+ _specwords . Add ( "Истина" , WordType . Boolean ) ;
68+ _specwords . Add ( "Ложь" , WordType . Boolean ) ;
6269
63- _logicalOp . Add ( "And" , true ) ;
64- _logicalOp . Add ( "Or" , true ) ;
65- _logicalOp . Add ( "Not" , true ) ;
70+ _specwords . Add ( "And" , WordType . Logical ) ;
71+ _specwords . Add ( "Or" , WordType . Logical ) ;
72+ _specwords . Add ( "Not" , WordType . Logical ) ;
6673
67- _logicalOp . Add ( "И" , true ) ;
68- _logicalOp . Add ( "ИЛИ" , true ) ;
69- _logicalOp . Add ( "НЕ" , true ) ;
74+ _specwords . Add ( "И" , WordType . Logical ) ;
75+ _specwords . Add ( "ИЛИ" , WordType . Logical ) ;
76+ _specwords . Add ( "НЕ" , WordType . Logical ) ;
77+
78+ _specwords . Add ( "NULL" , WordType . Null ) ;
79+
80+ _specwords . Add ( "Использовать" , WordType . Preproc ) ;
81+ _specwords . Add ( "Use" , WordType . Preproc ) ;
7082
7183 #endregion
7284
@@ -216,8 +228,6 @@ static LanguageDef()
216228
217229 #endregion
218230
219- _preprocImport . Add ( "Использовать" , true ) ;
220- _preprocImport . Add ( "Use" , true ) ;
221231 }
222232
223233 private static void AddToken ( Token token , string name )
@@ -433,18 +443,24 @@ public static bool IsEndOfBlockToken(Token token)
433443 default :
434444 return false ;
435445 }
446+ }
447+
448+
449+ public static WordType GetWordType ( string value )
450+ {
451+ return _specwords . TryGetValue ( value , out var wordType ) ? wordType : WordType . None ;
436452 }
437453
438454 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
439455 public static bool IsBooleanLiteralString ( string value )
440456 {
441- return _booleans . TryGetValue ( value , out var nodeIsFilled ) && nodeIsFilled ;
457+ return _specwords . TryGetValue ( value , out var wordType ) && wordType == WordType . Boolean ;
442458 }
443459
444460 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
445461 public static bool IsUndefinedString ( string value )
446462 {
447- return _undefined . TryGetValue ( value , out var nodeIsFilled ) && nodeIsFilled ;
463+ return _specwords . TryGetValue ( value , out var wordType ) && wordType == WordType . Undefined ;
448464 }
449465
450466 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -456,13 +472,13 @@ public static bool IsNullString(string value)
456472 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
457473 public static bool IsLogicalOperatorString ( string content )
458474 {
459- return _logicalOp . TryGetValue ( content , out var nodeIsFilled ) && nodeIsFilled ;
475+ return _specwords . TryGetValue ( content , out var wordType ) && wordType == WordType . Logical ;
460476 }
461477
462478 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
463479 public static bool IsImportDirective ( string value )
464480 {
465- return _preprocImport . TryGetValue ( value , out var nodeIsFilled ) && nodeIsFilled ;
481+ return _specwords . TryGetValue ( value , out var wordType ) && wordType == WordType . Preproc ;
466482 }
467483 }
468484}
0 commit comments