53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
|
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)
|
||
|
return null; //TODO: some other way of throwing it back
|
||
|
|
||
|
List<Expression> list = new List<Expression>();
|
||
|
Expression item = _parser.NextExpressionCC(this);
|
||
|
|
||
|
while (item is not null)
|
||
|
{
|
||
|
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();
|
||
|
}
|
||
|
}
|
||
|
}
|