Skip to content

Commit f50ce46

Browse files
committed
UI: Factor out UI components into a library; require 'use UI' for activation
1 parent a968f01 commit f50ce46

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

examples/ui_test.prox

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use UI;
2+
13
App MyLibraryApp {
24
State count = 0;
35

include/parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef struct {
1919
int current;
2020
bool panicMode;
2121
bool hadError;
22+
bool uiEnabled;
2223
const char *source;
2324
} Parser;
2425

src/compiler/parser/parser.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void initParser(Parser *parser, Token *tokens, int count, const char *source) {
9595
parser->current = 0;
9696
parser->panicMode = false;
9797
parser->hadError = false;
98+
parser->uiEnabled = false;
9899
parser->source = source;
99100
}
100101

@@ -610,6 +611,7 @@ static Stmt *useDecl(Parser *p) {
610611
}
611612

612613
appendString(modules, path);
614+
if (strcmp(path, "UI") == 0) p->uiEnabled = true;
613615
} while (match(p, 1, TOKEN_COMMA));
614616

615617
consume(p, TOKEN_SEMICOLON, "Expect ';'.");
@@ -733,6 +735,11 @@ static Stmt *statement(Parser *p) {
733735
}
734736

735737
// UI Declarations
738+
if (check(p, TOKEN_UI_APP) || check(p, TOKEN_UI_WINDOW)) {
739+
if (!p->uiEnabled) {
740+
parserError(p, "UI components require 'use UI' to be imported.");
741+
}
742+
}
736743
if (match(p, 1, TOKEN_UI_APP)) return uiAppDecl(p);
737744
if (match(p, 1, TOKEN_UI_WINDOW)) return uiWindowDecl(p);
738745
if (match(p, 1, TOKEN_UI_STATE)) return uiStateDecl(p);

std/lib/ui.prox

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// --------------------------------------------------
2+
// Project: ProX Programming Language (ProXPL)
3+
// Author: ProgrammerKR
4+
// Created: 2026-02-26
5+
// Description: UI Library marker file.
6+
// --------------------------------------------------
7+
8+
// This file serves as a marker for the built-in UI library.
9+
// Importing this library enables UI keywords and components.

0 commit comments

Comments
 (0)