54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
|
using KumiScript.Interpreter;
|
||
|
|
||
|
namespace KumiScript.Reader
|
||
|
{
|
||
|
public class ParserTopLevelVisitor : ITokenVisitor
|
||
|
{
|
||
|
Parser _parser;
|
||
|
public ParserTopLevelVisitor(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 ParserEndOfFileException();
|
||
|
}
|
||
|
|
||
|
public Expression VisitParen(ParenthesisToken paren)
|
||
|
{
|
||
|
if (!paren._leftParen)
|
||
|
throw new ParserUnexpectedTokenException("Unexpected Token ')'! Wanted ATOM, '(', or EOF.");
|
||
|
|
||
|
List<Expression> list = new List<Expression>();
|
||
|
ParserListVisitor listVisitor = new ParserListVisitor(_parser);
|
||
|
Expression item = _parser.NextExpressionCC(listVisitor);
|
||
|
|
||
|
while (item is not null)
|
||
|
{
|
||
|
list.Add(item);
|
||
|
item = _parser.NextExpressionCC(listVisitor);
|
||
|
}
|
||
|
|
||
|
return ListFactory.MakeList(list);
|
||
|
}
|
||
|
|
||
|
public Expression VisitSpecial(SpecialToken spec)
|
||
|
{
|
||
|
if (spec._value == '\'')
|
||
|
return _parser.NextExpressionCC(new ParserQuoteVisitor(_parser));
|
||
|
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
}
|
||
|
}
|