rokojori_action_library/Runtime/Text/Parsing/Parser/LexerPhase.cs

43 lines
928 B
C#
Raw Normal View History

2026-03-20 13:31:31 +00:00
using System.Collections.Generic;
namespace Rokojori;
public class LexerPhase:ParserPhase
{
public LexerPhase( Lexer lexer )
{
this.lexer = lexer;
}
public Lexer lexer;
public bool outputDebugInfo = false;
public override void Process( Parser parser )
{
parser.lexerEvents = lexer.LexToList( parser.source );
if ( lexer.hasError )
{
hasStopError = true;
return;
}
parser.lexerEvents.Pop();
lexer.GrabMatches( parser.lexerEvents, parser.source );
var root = parser.root;
parser.root.children.AddRange( parser.lexerEvents.Map( le => Token.Create( le, root ) ) );
if ( outputDebugInfo )
{
var index = 0;
RJLog.Log( "Lexer Info:", "\n" +
parser.lexerEvents.Map( le => "["+ ( index++ ) + "] '" + ( le.type == "Break" ? "\\n" : le.match ) + "' : " + le.type + " ("+ le.offset +")" ).Join( "\n" )
);
}
}
}