Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions ToyIncrementalParser/Interpreter/Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ToyIncrementalParser.Syntax;

namespace ToyIncrementalParser.Interpreter;
Expand All @@ -20,7 +19,7 @@ public ToyValue Execute(ProgramSyntax program, TextWriter? output = null)
{
ArgumentNullException.ThrowIfNull(program);

var text = ReconstructText(program);
var text = program.FullText;
return ExecuteInternal(program, text, output ?? TextWriter.Null);
}

Expand Down Expand Up @@ -248,32 +247,6 @@ private void DefineFunction(FunctionDefinitionSyntax definition, Environment env
environment.Define(definition.Identifier.Text, ToyValue.FromFunction(function));
}

private static string ReconstructText(SyntaxNode node)
{
var builder = new StringBuilder();
AppendNodeText(node, builder);
return builder.ToString();
}

private static void AppendNodeText(SyntaxNode node, StringBuilder builder)
{
if (node is SyntaxToken token)
{
foreach (var trivia in token.LeadingTrivia)
builder.Append(trivia.Text);

builder.Append(token.Text);

foreach (var trivia in token.TrailingTrivia)
builder.Append(trivia.Text);

return;
}

foreach (var child in node.GetChildren())
AppendNodeText(child, builder);
}

private static double ExpectNumber(ToyValue value, SyntaxToken token, EvaluationContext context)
{
if (value.Kind != ToyValueKind.Number)
Expand Down
10 changes: 2 additions & 8 deletions ToyIncrementalParser/Parser/Blender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ToyIncrementalParser.Parser;

internal sealed class Blender : ISymbolStream, ICharacterSource
internal sealed class Blender : ISymbolStream
{
private readonly IText _newText;
private readonly Stack<SymbolEntry> _symbolStack = new();
Expand Down Expand Up @@ -183,12 +183,6 @@ internal char ConsumeCharacterCore()

internal int CurrentPositionCore => _currentPosition;

// ICharacterSource implementation delegates to the wrapper
char ICharacterSource.PeekCharacter() => _characterSource.PeekCharacter();
char ICharacterSource.ConsumeCharacter() => _characterSource.ConsumeCharacter();
void ICharacterSource.PushBack(char ch) => _characterSource.PushBack(ch);
int ICharacterSource.CurrentPosition => _characterSource.CurrentPosition;

private void BuildInitialStack(GreenProgramNode oldRoot, IText newText, TextChange change)
{
// We build the initial work stack by processing the old program from left to right using a work stack.
Expand Down Expand Up @@ -693,7 +687,7 @@ private void CrumbleTopSymbol()
private SymbolToken LexNextToken()
{
// Reuse the lexer if we have one, otherwise create a new one
_lexer ??= new Lexer(this);
_lexer ??= new Lexer(_characterSource);
// The lexer will advance _currentPosition as it consumes characters
// After lexing, _currentPosition will be at lexed.FullEnd
var lexed = _lexer.NextToken();
Expand Down