commit:e2812563e23bbe26d95e8eb4d4bec1b9dc95965e
author:Chip Black
committer:Chip Black
date:Sun Oct 21 02:06:25 2018 -0500
parents:e1b1a59f907da1102c7b26ab8b7176eb8a7e348d
Fully parse if clauses in menu
diff --git a/src/script/menu.ts b/src/script/menu.ts
line changes: +18/-0
index 9e6f993..f58fa38
--- a/src/script/menu.ts
+++ b/src/script/menu.ts
@@ -7,9 +7,19 @@ enum MenuOptionType {
     Exit,
 }
 
+enum MenuConditionType {
+    Flag,
+    Object,
+}
+
 interface MenuOptionCommon {
     kind: MenuOptionType
     label: string
+    condition?: {
+        negate: boolean,
+        type: MenuConditionType,
+        name: string,
+    }
 }
 
 interface MenuItem extends MenuOptionCommon {
@@ -34,12 +44,18 @@ export class MenuInstruction implements ScriptInstruction {
 
     constructor(options: any[]) {
         this.options = options.map(o => {
+            const condition = o[0] && {
+                negate: o[0][2] != null,
+                type: o[0][3][0].value == '$' ? MenuConditionType.Flag : MenuConditionType.Object,
+                name: o[0][3][1].value,
+            };
             switch(o[1].value) {
                 case 'item':
                     return <MenuItem>{
                         kind: MenuOptionType.Item,
                         label: o[3],
                         instructions: o[5],
+                        condition,
                     };
                 case 'buy':
                     return <MenuBuy>{
@@ -47,11 +63,13 @@ export class MenuInstruction implements ScriptInstruction {
                         label: o[3][1].value, // TODO: fetch object name from object database
                         object: o[3][1].value,
                         value: o[5].value,
+                        condition,
                     };
                 case 'exit':
                     return <MenuExit>{
                         kind: MenuOptionType.Exit,
                         label: o[3],
+                        condition,
                     };
                 default:
                     throw new Error('Unknown menu item type: ' + o[1].value);

diff --git a/src/script/parser.ne b/src/script/parser.ne
line changes: +1/-1
index 6dc2280..b133d13
--- a/src/script/parser.ne
+++ b/src/script/parser.ne
@@ -44,7 +44,7 @@ menuitem -> if:? "buy" __ obj_identifier __ %number __
 menuitem -> if:? "exit" __ string __
 
 if -> "if" __ %bang:? flag_identifier __
-if -> "if" __ %bang:? obj_identifier %word __
+if -> "if" __ %bang:? obj_identifier __
 
 flag_identifier -> %flag_mark %word
 obj_identifier -> %obj_mark %word