I would like to parse the following PlantUML which likes flow-charts, by using python lark package. The syntax of each action is based on verilog-hdl.
PlantUML
@startuml :[7:0] a; :write(reg01, 8'h01, ); if (flag == 1'b1) then (Yes) :write(reg01, 8'h01, ); endif @enduml When parse uml with the following ebnf, the following error occored at 2nd function call.
EBNF
start: "@startuml" (statement | cond_if)* "@enduml" cond_if: "if" "(" condition ")" "then" "(" "Yes" ")" (statement)* "endif" statement: ":" expression ";" condition: expression expression: /[^;\n]+/ %import common.WS %ignore WS Error
Error: No terminal matches ':' in the current parser context, at line 6 col 3 :write(reg01, 8'h01, ); ^ Expected one of: * RPAR I copied the line of function call :write(reg01, 8'h01, ); to outside of if branch (like line 3). Then, 1st function call (outside of if branch) is OK but 2nd (inside of if branch) is NG.
I would like to extract write(reg01, 8'h01, ) as one token of expression because expression will be parsed by other parser.
How do I modify EBNF?
conditionregex;condition: /[^)]+/would work, but would preclude the use of parentheses in your conditions. Too bad Lark doesn't seem to support lookaheads in regex.