diff --git a/src/PoE.Core/Lexer.fsl b/src/PoE.Core/Lexer.fsl index b87d4ec..ee11b6f 100644 --- a/src/PoE.Core/Lexer.fsl +++ b/src/PoE.Core/Lexer.fsl @@ -269,6 +269,12 @@ and realtoken ctxt = #endif Parser.ELSE (currPos ctxt) } + | "elif" { +#if LEXERDEBUG + dbglog "ELIF" +#endif + Parser.ELIF (currPos ctxt) + } | "true" { #if LEXERDEBUG dbglog "TRUE" diff --git a/src/PoE.Core/Parser.fsy b/src/PoE.Core/Parser.fsy index 8a59a47..bd7cbd0 100644 --- a/src/PoE.Core/Parser.fsy +++ b/src/PoE.Core/Parser.fsy @@ -40,7 +40,7 @@ open PoE.BitVectorUtils %token RPIPE ASSIGN COLON %token PLUS MINUS MUL DIV MOD %token SHL SHR AND OR XOR NOT -%token IF THEN ELSE +%token IF ELIF THEN ELSE %token LPAREN RPAREN LBRACK RBRACK COMMA %token EQ NEQ GT GE LT LE %token BV INT8 INT16 INT32 INT64 UINT8 UINT16 UINT32 UINT64 @@ -219,13 +219,32 @@ whilestmt: WhileStmt ($2, $3, $1) } ifblockstmt: - IF expr THEN block DEDENT ELSE block { CondStmt ($2, $4, $7, $1) } - | IF expr THEN stmt NEWLINE ELSE block { CondStmt ($2, [ $4 ], $7, $1) } + IF expr THEN block DEDENT ifblockstmtaux + { CondStmt ($2, $4, $6, $1) } + | IF expr THEN stmt NEWLINE ifblockstmtaux + { CondStmt ($2, [ $4 ], $6, $1) } + +ifblockstmtaux: + ELSE block + { $2 } + | ELIF expr THEN block DEDENT ifblockstmtaux + { [ CondStmt ($2, $4, $6, $1) ] } + | ELIF expr THEN stmt NEWLINE ifblockstmtaux + { [ CondStmt ($2, [ $4 ], $6, $1) ] } ifsinglestmt: - IF expr THEN stmt NEWLINE ELSE stmt { CondStmt ($2, [ $4 ], [ $7 ], $1) } - | IF expr THEN stmt ELSE stmt { CondStmt ($2, [ $4 ], [ $6 ], $1) } - | IF expr THEN block DEDENT ELSE stmt { CondStmt ($2, $4, [ $7 ], $1) } + IF expr THEN block DEDENT ifsinglestmtaux + { CondStmt ($2, $4, $6, $1) } + | IF expr THEN stmt NEWLINE ifsinglestmtaux + { CondStmt ($2, [ $4 ], $6, $1) } + +ifsinglestmtaux: + ELSE stmt + { [ $2 ] } + | ELIF expr THEN block DEDENT ifsinglestmtaux + { [ CondStmt ($2, $4, $6, $1) ] } + | ELIF expr THEN stmt NEWLINE ifsinglestmtaux + { [ CondStmt ($2, [ $4 ], $6, $1) ] } breakstmt: BREAK { BreakStmt ($1) }