public override void VisitBooleanLiteralSyntax(BooleanLiteralSyntax syntax) => AssignType(syntax, () => LanguageConstants.Bool);
protected virtual void VisitBooleanLiteralSyntax(BooleanLiteralSyntax pNode) { }
protected virtual SyntaxNode VisitBooleanLiteralSyntax(BooleanLiteralSyntax pNode) { return(pNode); }
public virtual void VisitBooleanLiteral(BooleanLiteralSyntax node) { }
private bool TryParseFactor([NotNullWhen(true)] out ExpressionSyntax?expressionSyntax) { // Factor := Identifier | Number | Boolean literal | ( Expression ) | -Factor | !Factor | ~Factor expressionSyntax = null; switch (_lexer.PeekTokenType()) { case TokenType.Minus: return(ParseUnary(UnaryOperation.Minus, out expressionSyntax)); case TokenType.Exclamation: return(ParseUnary(UnaryOperation.Negation, out expressionSyntax)); case TokenType.Tilde: return(ParseUnary(UnaryOperation.Complement, out expressionSyntax)); case TokenType.OpenParen: // Eat the '(' _lexer.GetToken(); // Parse the expression. // The inner expression is returned as is, with no enclosing 'parens' node. // The modified precedence/associativity is already reflected in the syntax tree. if (!TryParseExpression(out expressionSyntax)) { return(false); } // Eat the ')' if (!ExpectToken(TokenType.CloseParen, DiagnosticCode.ExpectedClosingParen)) { return(false); } return(true); case TokenType.False: // Eat the token _lexer.GetToken(); expressionSyntax = new BooleanLiteralSyntax(false, _lexer.LastPosition); return(true); case TokenType.True: // Eat the token _lexer.GetToken(); expressionSyntax = new BooleanLiteralSyntax(true, _lexer.LastPosition); return(true); case TokenType.StringLiteral: return(TryParseStringLiteral(out expressionSyntax)); case TokenType.Identifier: if (!TryReadAndValidateIdentifier(out var identifier, allowReservedTypeNames: false)) { return(false); } // This may be either a function call or a variable reference if (_lexer.PeekTokenType() == TokenType.OpenParen) { // Function call if (!TryParseFunctionCall(identifier, out var callSyntax)) { return(false); } else { Debug.Assert(callSyntax != null); expressionSyntax = callSyntax; return(true); } } else { // Variable reference expressionSyntax = identifier; return(true); } default: return(TryParseNumber(out expressionSyntax)); } // Local helper method for sharing code between the various unary paths bool ParseUnary(UnaryOperation op, out ExpressionSyntax?syntax) { // Eat the operator var opPosition = _lexer.Position; _lexer.GetToken(); // Recurse into the inner expression, which is a factor too if (TryParseFactor(out var innerFactor)) { Debug.Assert(innerFactor != null); syntax = new UnaryExpressionSyntax(op, innerFactor, opPosition); return(true); } else { syntax = null; return(false); } } }