public override T VisitList([NotNull] ListContext context) { string firstEl = context .forms() ?.form(0) ?.literal() ?.symbol() ?.GetText(); int scopeCount = firstEl switch { "def" => DefDeclaration(context, SymbolTable), "fn" => FnDeclaration(context, SymbolTable), "defn" => DefnDeclaration(context, SymbolTable), "let" => LetDeclaration(context, SymbolTable), "loop" => LoopDeclaration(context, SymbolTable), _ when context.forms()?.form(0)?.vector() is { }
public override SymbolBase VisitList([NotNull] ListContext context) { if (context.forms().ChildCount == 0) { return(new ListSymbol(context.GetText())); } List <SymbolBase> symbols = new(); for (int i = 0; i < context.forms().ChildCount; i++) { symbols.Add(Visit(context.forms().form(i))); } if (symbols[0] is not SymbolSymbol) { return(new AnySymbol(context.GetText())); } _ = (symbols[0] as SymbolSymbol) ?? throw new TypeCastException( $"{Regex.Replace(symbols[0].GetType().Name, "Symbol$", "")} cannot be cast to " + $"{Regex.Replace(typeof(FunctionSymbol).Name, "Symbol$", "")}."); if (symbolTable.Root.SymbolMap.ContainsKey(symbols[0].Name)) { return((SymbolBase)Activator.CreateInstance( ((FunctionSymbol)symbolTable.Root.SymbolMap[symbols[0].Name]) .Accept(symbols.Skip(1).Select(s => s.GetType()).ToList()), context.GetText())); } else { throw new SyntaxException( $"Unable to resolve symbol: {symbols[0].Name} in this context."); } }