2024-01-26 05:37:51 +00:00
|
|
|
using KumiScript.Interpreter;
|
|
|
|
|
|
|
|
namespace KumiScript.Reader
|
|
|
|
{
|
|
|
|
public class ParserListVisitor : ITokenVisitor
|
|
|
|
{
|
|
|
|
Parser _parser;
|
|
|
|
public ParserListVisitor(Parser parser)
|
|
|
|
{
|
|
|
|
_parser = parser;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Expression VisitAtom(AtomToken atom)
|
|
|
|
{
|
|
|
|
return atom.ToExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Expression VisitString(StringToken str)
|
|
|
|
{
|
|
|
|
return str.ToExpression();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Expression VisitEoF(EndOfFileToken eof)
|
|
|
|
{
|
|
|
|
throw new ParserUnexpectedEndOfFileException("Expected ')' before end of file.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Expression VisitParen(ParenthesisToken paren)
|
|
|
|
{
|
|
|
|
if (!paren._leftParen)
|
2024-07-12 00:17:00 +00:00
|
|
|
return FakeExpression.GetInstance(); //TODO: some other way of throwing it back
|
2024-01-26 05:37:51 +00:00
|
|
|
|
|
|
|
List<Expression> list = new List<Expression>();
|
|
|
|
Expression item = _parser.NextExpressionCC(this);
|
2024-07-12 00:17:00 +00:00
|
|
|
while (!ReferenceEquals(item, FakeExpression.GetInstance()))
|
2024-01-26 05:37:51 +00:00
|
|
|
{
|
|
|
|
list.Add(item);
|
|
|
|
item = _parser.NextExpressionCC(this);
|
|
|
|
}
|
|
|
|
return ListFactory.MakeList(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Expression VisitSpecial(SpecialToken spec)
|
|
|
|
{
|
|
|
|
if (spec._value == '\'')
|
|
|
|
return _parser.NextExpressionCC(new ParserQuoteVisitor(_parser));
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|