diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-22 15:17:34 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-22 15:33:15 +0000 |
| commit | 0e8bc8c3e806796bf3b03e7da6c59ff24e58559f (patch) | |
| tree | effadf2f7c8bc1cd771235e7a4cf55f5c43f3831 /lib/Parser | |
| parent | 17993103e1ba1d142205eb2e41291edebc0e3a89 (diff) | |
fix(parser): parse casts to type names from other source files
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser')
| -rw-r--r-- | lib/Parser/ParserExpression.cc | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Parser/ParserExpression.cc b/lib/Parser/ParserExpression.cc index b75f704..f41694f 100644 --- a/lib/Parser/ParserExpression.cc +++ b/lib/Parser/ParserExpression.cc @@ -196,6 +196,21 @@ std::unique_ptr<ExprAST> Parser::ParseParenExpr() { getNextToken(); bool IsType = isBuiltinTypeToken(CurTok) || (CurTok == tok_identifier && TypeNames.count(Lex.IdentifierStr)); + // A type declared in another source file is unknown here, so `( IDENT )` + // directly followed on the same line by the start of a primary is also a + // cast. `+` and `-` stay binary: `(n) - 5` is arithmetic. + if (!IsType && CurTok == tok_identifier && Lex.peekToken(0) == ')' && + Lex.peekLine(1) == Lex.peekLine(0)) { + switch (Lex.peekToken(1)) { + case tok_identifier: case tok_number_int: case tok_number_real: + case tok_string_literal: case tok_c_string_literal: case tok_char_literal: + case tok_true: case tok_false: case '(': case tok_not: + IsType = true; + break; + default: + break; + } + } if (IsType) { std::string TypeName = ParseTypeName(); if (TypeName.empty()) return nullptr; |
