/// <summary> /// Initialization logic, called on the first instantiation of a Parser object. /// </summary> /// <param name="force">Force re-initialization</param> public static void Init(bool force = false) { if (hasRegistered && !force) { return; } Logger.Log(LogLevel.Info, Logger.REGISTRY, "Starting parselet registry."); PrefixParselets = new Dictionary <TokenType, IPrefixParselet>(); Logger.Log(LogLevel.Debug, Logger.REGISTRY, "Registering prefix parselets."); PrefixParselets.Add(TokenTypes.Identifier, new NameParselet()); PrefixParselets.Add(TokenTypes.Number, new NumberParselet()); PrefixParselets.Add(TokenTypes.String, new StringParselet()); PrefixParselets.Add(TokenTypes.Boolean, new BooleanParselet()); PrefixParselets.Add(TokenTypes.ParenthesisIn, new ParenthesisParselet()); PrefixParselets.Add(TokenTypes.BraceIn, new ListLiteralParselet()); foreach (TokenType tc in UnaryPrefixRegistry.GetTokens()) { RegisterPrefixOperator(tc); } if (PrefixLoading != null) { PrefixLoading(null, new PrefixLoadingEventArgs(PrefixParselets)); } InfixParselets = new Dictionary <TokenType, IInfixParselet>(); Logger.Log(LogLevel.Debug, Logger.REGISTRY, "Registering infix and postfix parselets."); InfixParselets.Add(TokenTypes.ParenthesisIn, new FunctionCallParselet()); InfixParselets.Add(TokenTypes.BracketIn, new ListOrdinalParselet()); InfixParselets.Add(TokenTypes.OperatorQuestion, new ConditionalParselet()); foreach (TokenType tc in BinaryInfixRegistry.GetTokens()) { BinaryInfixRegistry.RegItem reg = BinaryInfixRegistry.Get(tc); RegisterBinaryOperator(tc, reg.PrecedenceLevel, reg.IsRightAssociative); } foreach (TokenType tc in UnaryPostfixRegistry.GetTokens()) { RegisterPostfixOperator(tc); } if (InfixLoading != null) { InfixLoading(null, new InfixLoadingEventArgs(InfixParselets)); } hasRegistered = true; }
public NodeBase Parse(Parser parser, Token token) { NodeBase operand = parser.Parse(Precedence); return(UnaryPrefixRegistry.MakeNode(token.Type, operand)); }