Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ Defines AST nodes for the parser. Key types:
Parses ABL source code into an AST. Key capabilities:

- **Expression parsing** with proper operator precedence (ternary → or → and → comparison → additive → multiplicative → unary → postfix → primary)
- **Statement parsing**: DEFINE VARIABLE/VAR/PARAMETER/TEMP-TABLE/BUFFER/PROPERTY/STREAM/FRAME/EVENT, DO blocks (with counting loops), IF/THEN/ELSE, REPEAT, FOR EACH, FIND, CASE, PROCEDURE, FUNCTION, RUN, DISPLAY (with STREAM clause), MESSAGE, ASSIGN, CREATE, DELETE, RELEASE, VALIDATE, BUFFER-COPY, BUFFER-COMPARE, INPUT/OUTPUT/INPUT-OUTPUT stream I/O (FROM/TO/THROUGH/CLOSE), CATCH/FINALLY/THROW, PUBLISH/SUBSCRIBE/UNSUBSCRIBE, LEAVE, NEXT, RETURN
- **Statement parsing**: DEFINE VARIABLE/VAR/PARAMETER/TEMP-TABLE/BUFFER/PROPERTY/STREAM/FRAME/EVENT, DO blocks (with counting loops), IF/THEN/ELSE, REPEAT, FOR EACH, FIND, CASE, PROCEDURE, FUNCTION, RUN, DISPLAY (with STREAM clause), MESSAGE, ASSIGN, CREATE, DELETE, RELEASE, VALIDATE, BUFFER-COPY, BUFFER-COMPARE, INPUT/OUTPUT/INPUT-OUTPUT stream I/O (FROM/TO/THROUGH/CLOSE), CATCH/FINALLY/THROW, PUBLISH/SUBSCRIBE/UNSUBSCRIBE, ON (UI/developer event triggers with IN FRAME/IN BROWSE, database event triggers, key remapping), TRIGGER PROCEDURE, LEAVE, NEXT, RETURN
- **OO-ABL**: CLASS (with ABSTRACT/FINAL, INHERITS, IMPLEMENTS), INTERFACE, METHOD (with access modifiers, STATIC/ABSTRACT/OVERRIDE), DEFINE PROPERTY (auto and computed GET/SET), CONSTRUCTOR, DESTRUCTOR, USING
- **Postfix operations**: Method calls (object:method()), member access (object.member), array access (arr[i]), field access (table.field)
- **Function calls** with argument lists
- **Preprocessor**: &IF/&ELSEIF/&ELSE/&ENDIF at statement, expression, and data type levels via generic `PreprocIf<T>`, &SCOPED-DEFINE/&GLOBAL-DEFINE with `PreprocEnd` lexer token, &UNDEFINE, &MESSAGE, `{&variable}` references
- **Error recovery** via `parse_program()` with synchronization on period boundaries

Not yet implemented: ON triggers.
Not yet implemented: DO/FOR/REPEAT block-header ON phrases (ON ERROR UNDO, ON ENDKEY UNDO).

### Code Generation (`oxabl_codegen`)

Expand Down Expand Up @@ -170,4 +170,4 @@ cargo bench -p oxabl_common --bench source_map_bench
- `oxabl_lexer`: MVP complete with 43 tests
- `oxabl_common/source_map`: Implemented with 10 tests
- `oxabl_ast`: Implemented with expressions, statements, and data types
- `oxabl_parser`: Actively developed with 330 tests; parses expressions, control flow, variable declarations, functions, procedures, temp-tables, error handling, OO-ABL (CLASS, METHOD, PROPERTY, INTERFACE), preprocessor directives, stream I/O, and frame definitions
- `oxabl_parser`: Actively developed with 406 tests; parses expressions, control flow, variable declarations, functions, procedures, temp-tables, error handling, OO-ABL (CLASS, METHOD, PROPERTY, INTERFACE), preprocessor directives, stream I/O, frame definitions, ON triggers (UI events, database events, key remapping), and TRIGGER PROCEDURE
154 changes: 154 additions & 0 deletions crates/oxabl_ast/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,36 @@ pub enum Statement {
operation: StreamOperation,
},

/// ON trigger statement -- event handlers for UI, database, and key events.
///
/// ```abl
/// ON CHOOSE OF btnOk IN FRAME f1 DO: /* ... */ END.
/// ON WRITE OF Customer NEW BUFFER bNew OLD BUFFER bOld DO: /* ... */ END.
/// ON F1 HELP.
/// ```
On { kind: OnKind },

/// TRIGGER PROCEDURE FOR event OF table [NEW/OLD clauses].
///
/// Declares a schema trigger -- always the first statement in a trigger procedure file.
///
/// ```abl
/// TRIGGER PROCEDURE FOR WRITE OF Customer
/// NEW BUFFER bNew OLD BUFFER bOld.
/// ```
TriggerProcedure {
/// The trigger event (CREATE, DELETE, FIND, WRITE, ASSIGN, or REPLICATION-*).
event: DbTriggerEvent,
/// The target table (or table.field for ASSIGN OF form).
target: Identifier,
/// NEW/OLD BUFFER referencing (WRITE triggers).
referencing: TriggerReferencing,
/// NEW VALUE variable definition (ASSIGN triggers, mutually exclusive with OF form).
new_value: Option<TriggerAssignParam>,
/// OLD VALUE variable definition (ASSIGN NEW VALUE form).
old_value_param: Option<TriggerAssignParam>,
},

/// Leave statement - exit innermost loop
Leave,

Expand Down Expand Up @@ -865,3 +895,127 @@ pub enum SubscribeTarget {
/// Subscribe to events from any publisher.
Anywhere,
}

// =============================================================================
// ON trigger types
// =============================================================================

/// Discriminant for the different forms of the ON statement.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OnKind {
/// UI/developer event trigger (includes "WEB-NOTIFY" ANYWHERE form):
/// ON event-list OF widget-list [OR event-list OF widget-list]... [ANYWHERE]
/// { trigger-block | REVERT | PERSISTENT RUN proc [(args)] }
UiEvent {
/// Event/widget clauses -- at least one, chained via OR.
/// Empty when ANYWHERE is used standalone (e.g., ON "WEB-NOTIFY" ANYWHERE).
clauses: Vec<OnEventClause>,
/// Whether ANYWHERE was specified.
anywhere: bool,
/// The trigger action.
action: OnAction,
},
/// Database event trigger:
/// ON CREATE|DELETE|FIND|WRITE|ASSIGN OF table [referencing] [OVERRIDE]
/// { trigger-block | REVERT }
DbEvent {
/// The database event.
event: DbTriggerEvent,
/// The table (or table.field for ASSIGN) the trigger is on.
target: Identifier,
/// NEW/OLD BUFFER/VALUE referencing phrases.
referencing: TriggerReferencing,
/// Whether OVERRIDE was specified.
is_override: bool,
/// The trigger action (block or REVERT).
action: OnAction,
},
/// Key remapping: ON key-label key-function.
KeyRemap {
/// The key label (e.g., F1, CTRL-X) -- any identifier.
key_label: Identifier,
/// The key function (e.g., HELP, ENDKEY, GO) -- any identifier.
key_function: Identifier,
},
}

/// A single event/widget-list clause in a UI ON trigger.
///
/// `ON CHOOSE, ENTRY OF btnOk IN FRAME f1, btnCancel`
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OnEventClause {
/// Comma-separated event names (identifiers, including keywords like LEAVE/ENTRY).
pub events: Vec<Identifier>,
/// Comma-separated widget references with optional frame/browse qualifiers.
pub widgets: Vec<WidgetRef>,
}

/// The action taken by an ON trigger.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OnAction {
/// A trigger block -- either a single statement or DO...END block.
Block(Box<Statement>),
/// REVERT -- removes the trigger.
Revert,
/// PERSISTENT RUN procedure [(args)].
PersistentRun {
procedure: Identifier,
arguments: Vec<Expression>,
},
}

/// Database trigger event types.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DbTriggerEvent {
Create,
Delete,
Find,
Write,
Assign,
ReplicationCreate,
ReplicationDelete,
ReplicationWrite,
}

/// Referencing phrase for database triggers (NEW/OLD BUFFER for WRITE, OLD VALUE for ASSIGN).
/// Shared between ON db-event triggers and TRIGGER PROCEDURE.
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct TriggerReferencing {
/// NEW [BUFFER] alias (WRITE triggers).
pub new_buffer: Option<Identifier>,
/// OLD [BUFFER] alias (WRITE triggers).
pub old_buffer: Option<Identifier>,
/// OLD [VALUE] alias (ASSIGN triggers in ON statement).
pub old_value: Option<Identifier>,
}

/// Widget reference in an ON trigger, with optional frame/browse qualifier.
///
/// `btnOk IN FRAME main-frame` or `col1 IN BROWSE brw1`
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct WidgetRef {
pub name: Identifier,
pub qualifier: Option<WidgetQualifier>,
}

/// Optional qualification for a widget reference.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum WidgetQualifier {
/// IN FRAME frame-name
InFrame(Identifier),
/// IN BROWSE browse-name
InBrowse(Identifier),
}

/// A variable-like parameter for TRIGGER PROCEDURE FOR ASSIGN NEW VALUE form.
///
/// ```abl
/// TRIGGER PROCEDURE FOR ASSIGN
/// NEW VALUE newVal AS CHARACTER
/// OLD VALUE oldVal AS CHARACTER.
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TriggerAssignParam {
pub name: Identifier,
pub data_type: DataType,
}
3 changes: 3 additions & 0 deletions crates/oxabl_lexer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn main() {
"blank",
"blob",
"break",
"browse",
"buffer",
"buffer-compare",
"buffer-copy",
Expand All @@ -111,6 +112,7 @@ fn main() {
"char",
"character",
"check",
"choose",
"chr",
"class",
"clear",
Expand Down Expand Up @@ -203,6 +205,7 @@ fn main() {
"enable",
"encode",
"end",
"endkey",
"entry",
"eq",
"error stat",
Expand Down
6 changes: 6 additions & 0 deletions crates/oxabl_lexer/src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ pub enum Kind {
Event,
Signature,
RunProcedure,
Choose,
Endkey,
Browse,

// Phrases
Editing,
Expand Down Expand Up @@ -832,11 +835,13 @@ pub fn match_keyword(s: &str) -> Option<Kind> {
"availa" => Some(Kind::Available),
"backgr" => Some(Kind::Background),
"begins" => Some(Kind::Begins),
"browse" => Some(Kind::Browse),
"buffer" => Some(Kind::Buffer),
"can do" => Some(Kind::CanDo),
"can-do" => Some(Kind::CanDo),
"center" => Some(Kind::Centered),
"charac" => Some(Kind::Character),
"choose" => Some(Kind::Choose),
"create" => Some(Kind::Create),
"cursor" => Some(Kind::Cursor),
"dbname" => Some(Kind::Dbname),
Expand All @@ -852,6 +857,7 @@ pub fn match_keyword(s: &str) -> Option<Kind> {
"displa" => Some(Kind::Display),
"enable" => Some(Kind::Enable),
"encode" => Some(Kind::Encode),
"endkey" => Some(Kind::Endkey),
"escape" => Some(Kind::Escape),
"except" => Some(Kind::Except),
"exists" => Some(Kind::Exists),
Expand Down
8 changes: 8 additions & 0 deletions crates/oxabl_parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ impl<'a> Parser<'a> {
| Kind::Event
| Kind::Signature
| Kind::RunProcedure
// ON trigger keywords (unreserved)
| Kind::Trigger
| Kind::Triggers
| Kind::Persistent
| Kind::Revert
| Kind::Choose
| Kind::Endkey
| Kind::Browse
)
}

Expand Down
Loading