2026-03-20 13:31:31 +00:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
namespace Rokojori;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TokenPredicateData
|
|
|
|
|
{
|
2026-04-27 08:15:59 +00:00
|
|
|
|
2026-03-20 13:31:31 +00:00
|
|
|
public string type;
|
|
|
|
|
public string match;
|
|
|
|
|
|
2026-04-27 08:15:59 +00:00
|
|
|
|
2026-03-20 13:31:31 +00:00
|
|
|
public bool Matches( ASTNode node )
|
|
|
|
|
{
|
|
|
|
|
return node.IsToken( type, match );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public System.Predicate<Token> predicate
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
System.Predicate<Token> pred = ( tk ) => tk.Is( type, match );
|
|
|
|
|
return pred;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TokenPredicateData Create( string type, string match = null )
|
|
|
|
|
{
|
|
|
|
|
var pd = new TokenPredicateData();
|
|
|
|
|
pd.type = type;
|
|
|
|
|
pd.match = match;
|
|
|
|
|
return pd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TokenPredicateData Lexed( Lexer lexer, string value )
|
|
|
|
|
{
|
|
|
|
|
var lexedSequence = Token.CreateLexedSequenceData( lexer, value );
|
|
|
|
|
return lexedSequence[ 0 ];
|
|
|
|
|
}
|
2026-04-27 08:15:59 +00:00
|
|
|
|
|
|
|
|
public static readonly List<TokenPredicateData> Semicolon = [
|
|
|
|
|
TokenPredicateData.Create(
|
|
|
|
|
LexerMatcherLibrary.OperatorMatcher.type, ";"
|
|
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public static readonly List<TokenPredicateData> BlockPredicates = [
|
|
|
|
|
|
|
|
|
|
TokenPredicateData.Create(
|
|
|
|
|
LexerMatcherLibrary.BracketMatcher.type, "("
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
TokenPredicateData.Create(
|
|
|
|
|
LexerMatcherLibrary.BracketMatcher.type, ")"
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TokenPredicateData.Create(
|
|
|
|
|
LexerMatcherLibrary.BracketMatcher.type, "{"
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
TokenPredicateData.Create(
|
|
|
|
|
LexerMatcherLibrary.BracketMatcher.type, "{"
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TokenPredicateData.Create(
|
|
|
|
|
LexerMatcherLibrary.BracketMatcher.type, "["
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
TokenPredicateData.Create(
|
|
|
|
|
LexerMatcherLibrary.BracketMatcher.type, "]"
|
|
|
|
|
)
|
|
|
|
|
];
|
2026-03-20 13:31:31 +00:00
|
|
|
}
|