aboutsummaryrefslogtreecommitdiff
path: root/lib/Parser
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 09:09:54 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 09:09:54 +0000
commit59a2bb6acb975d820ab29be63a6f909d6e6ef40f (patch)
treeac87916075e9e5a9f166b14fea0b39864d801166 /lib/Parser
parentdc645a36aaade7087ade574cefe69ce7bb29753e (diff)
feat(parser): parse INCLUDE and GLOBAL blocks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/Parser')
-rw-r--r--lib/Parser/Parser.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/Parser/Parser.cc b/lib/Parser/Parser.cc
index 826bc89..d4dd18e 100644
--- a/lib/Parser/Parser.cc
+++ b/lib/Parser/Parser.cc
@@ -46,6 +46,7 @@ std::vector<std::unique_ptr<StmtAST>> Parser::Parse() {
void Parser::syncToStatementStart() {
while (CurTok != tok_eof) {
switch (CurTok) {
+ case tok_include: case tok_global: case tok_endglobal:
case tok_delete: case tok_constant: case tok_declare: case tok_identifier: case tok_input: case tok_output:
case tok_case: case tok_endcase: case tok_otherwise:
case tok_if: case tok_while: case tok_repeat: case tok_for:
@@ -95,6 +96,37 @@ std::unique_ptr<StmtAST> Parser::ParseStatement() {
}
std::unique_ptr<StmtAST> Parser::ParseStatementImpl() {
+ if (CurTok == tok_include || CurTok == tok_global) {
+ bool Include = CurTok == tok_include;
+ int Line = Lex.getLine();
+ getNextToken();
+ if (BlockDepth != 1) {
+ sourceDiagnostic(Line, "error: %s is only allowed at top level at line %d\n",
+ Include ? "INCLUDE" : "GLOBAL", Line);
+ return nullptr;
+ }
+ if (Include) {
+ if (CurTok != tok_string_literal) {
+ sourceDiagnostic(Line, "error: INCLUDE requires a string literal at line %d\n", Line);
+ return nullptr;
+ }
+ auto Stmt = std::make_unique<IncludeStmtAST>(Lex.StringVal);
+ getNextToken();
+ return Stmt;
+ }
+ auto Body = ParseBlock({tok_endglobal});
+ if (CurTok != tok_endglobal) {
+ sourceDiagnostic(Line, "error: Expected ENDGLOBAL at line %d\n", Lex.getLine());
+ return nullptr;
+ }
+ getNextToken();
+ return std::make_unique<GlobalBlockAST>(std::move(Body));
+ }
+ if (CurTok == tok_endglobal) {
+ sourceDiagnostic(Lex.getLine(), "error: ENDGLOBAL without matching GLOBAL at line %d\n", Lex.getLine());
+ getNextToken();
+ return nullptr;
+ }
if (CurTok == tok_delete) {
int Line = Lex.getLine();
getNextToken();