protected virtual Node_Argument parseArgument(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'argument' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Argument( parseOpt<Node_Identifier>(parseIdentifier, sexp), parseOpt<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual Node_Breed parseBreed(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'breed' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Breed( parseOne<INode_Expression>(parseExpression, sexp), parseOpt<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual Node_Assign parseAssign(Sexp sexp) { if( sexp.list.Count != 3 ) throw new ParseError( String.Format( "'assign' node must have 3 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Assign( parseOne<Node_Identifier>(parseIdentifier, sexp), parseOne<Node_Boolean>(parseBoolean, sexp), parseOne<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual Node_Boolean parseBoolean(Sexp sexp) { try { return new Node_Boolean(sexp.atom, getSource(sexp)); } catch(FormatException e) { throw new ParseError( String.Format( "node of type Boolean cannot be of value '{0}'", sexp.atom), getSource(sexp), e); } catch(ArgumentException e) { throw new ParseError( String.Format( "node of type Boolean cannot be of value '{0}'", sexp.atom), getSource(sexp), e); } }
protected virtual INode_Expression parseNonwordExpression(Sexp sexp) { throw new ParseError( "expression must begin with a word", getSource(sexp)); }
protected virtual Node_Method parseMethod(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'method' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Method( parseOne<Node_Identifier>(parseIdentifier, sexp), parseOne<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual Node_Module parseModule(Sexp sexp) { if( sexp.list.Count != 4 ) throw new ParseError( String.Format( "'module' node must have 4 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Module( parseOne<Node_Integer>(parseInteger, sexp), parseOne<Node_Integer>(parseInteger, sexp), parseMult0<Node_Import>(parseImport, sexp), parseOne<Node_Sieve>(parseSieve, sexp), getSource(sexp) ); }
protected virtual Node_Enum parseEnum(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'enum' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Enum( parseOne<INode_Expression>(parseExpression, sexp), parseMult1<Node_EnumEntry>(parseEnumEntry, sexp), getSource(sexp) ); }
protected virtual Node_MemberImplementation parseMemberImplementation(Sexp sexp) { if( sexp.list.Count != 4 ) throw new ParseError( String.Format( "'member-implementation' node must have 4 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_MemberImplementation( parseOne<Node_MemberType>(parseMemberType, sexp), parseOpt<Node_Identifier>(parseIdentifier, sexp), parseOpt<INode_Expression>(parseExpression, sexp), parseOne<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual Node_Object parseObject(Sexp sexp) { if( sexp.list.Count != 1 ) throw new ParseError( String.Format( "'object' node must have 1 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Object( parseMult1<Node_Worker>(parseWorker, sexp), getSource(sexp) ); }
protected virtual INode_Expression parseExpression(Sexp sexp) { if( sexp.type != SexpType.LIST ) return parseTerminalExpression(sexp); if( sexp.list.Count == 0 ) throw new ParseError( "this list cannot be empty", getSource(sexp)); if( sexp.list.First.Value.type != SexpType.WORD ) return parseNonwordExpression(sexp); Sexp first = sexp.list.First.Value; string specType = first.atom; sexp.list.RemoveFirst(); switch(specType) { case "declare-empty": return parseDeclareEmpty(sexp); case "raise": return parseRaise(sexp); case "assign": return parseAssign(sexp); case "call": return parseCall(sexp); case "compound": return parseCompound(sexp); case "conditional": return parseConditional(sexp); case "curry": return parseCurry(sexp); case "declare-assign": return parseDeclareAssign(sexp); case "identifier": return parseIdentifier(sexp); case "select": return parseSelect(sexp); case "set-property": return parseSetProperty(sexp); case "try-catch": return parseTryCatch(sexp); case "type-select": return parseTypeSelect(sexp); case "and": return parseAnd(sexp); case "nand": return parseNand(sexp); case "or": return parseOr(sexp); case "nor": return parseNor(sexp); case "xor": return parseXor(sexp); case "xnor": return parseXnor(sexp); case "breed": return parseBreed(sexp); case "caller": return parseCaller(sexp); case "object": return parseObject(sexp); case "dictionary": return parseDictionary(sexp); case "enum": return parseEnum(sexp); case "extract-member": return parseExtractMember(sexp); case "function": return parseFunction(sexp); case "function-interface": return parseFunctionInterface(sexp); case "generator": return parseGenerator(sexp); case "generic-function": return parseGenericFunction(sexp); case "generic-interface": return parseGenericInterface(sexp); case "instantiate-generic": return parseInstantiateGeneric(sexp); case "integer": return parseInteger(sexp); case "interface": return parseInterface(sexp); case "rational": return parseRational(sexp); case "string": return parseString(sexp); default: sexp.list.AddFirst(first); return parseExpressionDefault(sexp); } }
protected virtual Node_InstantiateGeneric parseInstantiateGeneric(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'instantiate-generic' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_InstantiateGeneric( parseOne<INode_Expression>(parseExpression, sexp), parseMult1<Node_Argument>(parseArgument, sexp), getSource(sexp) ); }
protected virtual Node_ParameterInfo parseParameterInfo(Sexp sexp) { if( sexp.list.Count != 4 ) throw new ParseError( String.Format( "'parameter-info' node must have 4 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_ParameterInfo( parseOne<Node_Direction>(parseDirection, sexp), parseOne<INode_Expression>(parseExpression, sexp), parseOne<Node_Identifier>(parseIdentifier, sexp), parseOne<Node_Boolean>(parseBoolean, sexp), getSource(sexp) ); }
protected virtual Node_Hidable parseHidable(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'hidable' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Hidable( parseOne<Node_Boolean>(parseBoolean, sexp), parseOne<INode_StatementDeclaration>(parseStatementDeclaration, sexp), getSource(sexp) ); }
protected virtual Node_ImportAttempt parseImportAttempt(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'import-attempt' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_ImportAttempt( parseOne<Node_String>(parseString, sexp), parseOne<Node_String>(parseString, sexp), getSource(sexp) ); }
protected virtual Node_GenericInterface parseGenericInterface(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'generic-interface' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_GenericInterface( parseMult1<Node_ParameterInfo>(parseParameterInfo, sexp), parseOne<Node_Interface>(parseInterface, sexp), getSource(sexp) ); }
protected virtual Node_GenericFunction parseGenericFunction(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'generic-function' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_GenericFunction( parseMult1<Node_ParameterInfo>(parseParameterInfo, sexp), parseOne<Node_Function>(parseFunction, sexp), getSource(sexp) ); }
protected virtual Node_FunctionInterface parseFunctionInterface(Sexp sexp) { if( sexp.list.Count != 3 ) throw new ParseError( String.Format( "'function-interface' node must have 3 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_FunctionInterface( parseOpt<INode_Expression>(parseExpression, sexp), parseMult0<Node_ParameterInfo>(parseParameterInfo, sexp), parseOne<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual INode_InterfaceMember parseNonwordInterfaceMember(Sexp sexp) { throw new ParseError( "expression must begin with a word", getSource(sexp)); }
protected virtual Node_Select parseSelect(Sexp sexp) { if( sexp.list.Count != 3 ) throw new ParseError( String.Format( "'select' node must have 3 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Select( parseOne<INode_Expression>(parseExpression, sexp), parseMult0<Node_Case>(parseCase, sexp), parseOpt<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual INode_StatementDeclaration parseNonwordStatementDeclaration(Sexp sexp) { throw new ParseError( "expression must begin with a word", getSource(sexp)); }
protected virtual Node_Sieve parseSieve(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'sieve' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Sieve( parseMult0<INode_Expression>(parseExpression, sexp), parseMult0<Node_Hidable>(parseHidable, sexp), getSource(sexp) ); }
protected virtual Node_Interface parseInterface(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'interface' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Interface( parseMult0<INode_Expression>(parseExpression, sexp), parseMult0<Node_StatusedMember>(parseStatusedMember, sexp), getSource(sexp) ); }
protected virtual INode_Expression parseExpressionDefault(Sexp sexp) { throw new ParseError( String.Format( "unknown type of Expression '{0}'", sexp.list.First.Value.atom), getSource(sexp)); }
protected virtual Node_Raise parseRaise(Sexp sexp) { if( sexp.list.Count != 1 ) throw new ParseError( String.Format( "'raise' node must have 1 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_Raise( parseOne<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual INode_InterfaceMember parseInterfaceMember(Sexp sexp) { if( sexp.type != SexpType.LIST ) return parseTerminalInterfaceMember(sexp); if( sexp.list.Count == 0 ) throw new ParseError( "this list cannot be empty", getSource(sexp)); if( sexp.list.First.Value.type != SexpType.WORD ) return parseNonwordInterfaceMember(sexp); Sexp first = sexp.list.First.Value; string specType = first.atom; sexp.list.RemoveFirst(); switch(specType) { case "breeder": return parseBreeder(sexp); case "callee": return parseCallee(sexp); case "property": return parseProperty(sexp); case "method": return parseMethod(sexp); default: sexp.list.AddFirst(first); return parseInterfaceMemberDefault(sexp); } }
protected virtual Node_SetProperty parseSetProperty(Sexp sexp) { if( sexp.list.Count != 3 ) throw new ParseError( String.Format( "'set-property' node must have 3 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_SetProperty( parseOne<INode_Expression>(parseExpression, sexp), parseOne<Node_Identifier>(parseIdentifier, sexp), parseOne<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }
protected virtual INode_InterfaceMember parseInterfaceMemberDefault(Sexp sexp) { throw new ParseError( String.Format( "unknown type of InterfaceMember '{0}'", sexp.list.First.Value.atom), getSource(sexp)); }
protected virtual INode_StatementDeclaration parseStatementDeclaration(Sexp sexp) { if( sexp.type != SexpType.LIST ) return parseTerminalStatementDeclaration(sexp); if( sexp.list.Count == 0 ) throw new ParseError( "this list cannot be empty", getSource(sexp)); if( sexp.list.First.Value.type != SexpType.WORD ) return parseNonwordStatementDeclaration(sexp); Sexp first = sexp.list.First.Value; string specType = first.atom; sexp.list.RemoveFirst(); switch(specType) { case "declare-first": return parseDeclareFirst(sexp); case "sieve": return parseSieve(sexp); default: sexp.list.AddFirst(first); return parseStatementDeclarationDefault(sexp); } }
protected virtual Node_DictionaryEntry parseDictionaryEntry(Sexp sexp) { if( sexp.list.Count != 2 ) throw new ParseError( String.Format( "'dictionary-entry' node must have 2 children ({0} given)", sexp.list.Count), getSource(sexp)); return new Node_DictionaryEntry( parseOne<INode_Expression>(parseExpression, sexp), parseOne<INode_Expression>(parseExpression, sexp), getSource(sexp) ); }