diff --git a/src/cst/Trigger.ts b/src/cst/Trigger.ts index 3c5c9aac..e854ccfa 100644 --- a/src/cst/Trigger.ts +++ b/src/cst/Trigger.ts @@ -6,6 +6,7 @@ import { BlockStmt } from "./ProceduralLanguage"; export type AllTriggerNodes = | AllTriggerStatements | TriggerEvent + | TriggerTarget | ForEachClause | WhenClause | FromReferencedTableClause @@ -26,6 +27,7 @@ export interface CreateTriggerStmt extends BaseNode { ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">]; name: EntityName; event: TriggerEvent; + target: TriggerTarget; clauses: TriggerClause[]; body: BlockStmt | ExecuteClause; } @@ -36,6 +38,10 @@ export interface TriggerEvent extends BaseNode { eventKw: Keyword<"INSERT" | "DELETE" | "UPDATE" | "TRUNCATE">; ofKw?: Keyword<"OF">; columns?: ListExpr; +} + +export interface TriggerTarget extends BaseNode { + type: "trigger_target"; onKw: Keyword<"ON">; table: EntityName; } diff --git a/src/parser.pegjs b/src/parser.pegjs index c2bb1fb2..03c39b6f 100644 --- a/src/parser.pegjs +++ b/src/parser.pegjs @@ -3283,6 +3283,7 @@ create_trigger_stmt ifKw:(if_not_exists __)? name:(entity_name __) event:(trigger_event __) + target:(trigger_target __) clauses:(trigger_clause __)* body:trigger_body { @@ -3295,6 +3296,7 @@ create_trigger_stmt ifNotExistsKw: read(ifKw), name: read(name), event: read(event), + target: read(target), clauses: clauses.map(read), body, }); @@ -3309,29 +3311,34 @@ trigger_kind } trigger_event - = timeKw:(trigger_time_kw __)? eventKw:(UPDATE __) ofKw:(OF __) cols:(list$column __) onKw:(ON __) table:entity_name { + = timeKw:(trigger_time_kw __)? eventKw:(UPDATE __) ofKw:(OF __) cols:list$column { return loc({ type: "trigger_event", timeKw: read(timeKw), eventKw: read(eventKw), ofKw: read(ofKw), columns: read(cols), - onKw: read(onKw), - table, }); } - / timeKw:(trigger_time_kw __)? eventKw:(DELETE / INSERT / UPDATE / TRUNCATE) onKw:(__ ON __) table:entity_name { + / timeKw:(trigger_time_kw __)? eventKw:(DELETE / INSERT / UPDATE / TRUNCATE) { return loc({ type: "trigger_event", timeKw: read(timeKw), eventKw: read(eventKw), - onKw: read(onKw), - table, }); } trigger_time_kw = kw:(BEFORE / AFTER / INSTEAD __ OF) { return read(kw); } +trigger_target + = onKw:(__ ON __) table:entity_name { + return loc({ + type: "trigger_target", + onKw: read(onKw), + table, + }); + } + trigger_clause = for_each_clause / when_clause diff --git a/src/showNode/trigger.ts b/src/showNode/trigger.ts index a10cec4f..0c613ed4 100644 --- a/src/showNode/trigger.ts +++ b/src/showNode/trigger.ts @@ -12,18 +12,13 @@ export const triggerMap: FullTransformMap = { node.ifNotExistsKw, node.name, node.event, + node.target, node.clauses, node.body, ]), trigger_event: (node) => - show([ - node.timeKw, - node.eventKw, - node.ofKw, - node.columns, - node.onKw, - node.table, - ]), + show([node.timeKw, node.eventKw, node.ofKw, node.columns]), + trigger_target: (node) => show([node.onKw, node.table]), for_each_clause: (node) => show([node.forEachKw, node.itemKw]), when_clause: (node) => show([node.whenKw, node.expr]), from_referenced_table_clause: (node) => show([node.fromKw, node.table]),