%token Other %token LSquare %token RSquare %token Equals %token Comment %token White %token Newline %token Eof %start sentence %type < (string * (string * string) list) list > sentence %% sentence: preamble entries {$2} preamble: {()} | comment Newline preamble {()} | White Newline preamble {()} entries: Eof {[]} | entry entries {$1 :: $2} comment: Comment rhs {"#"^$2} entry: LSquare Other RSquare Newline lines {$2, $5} lines: {[]} | lhs Equals rhs Newline lines {($1, $3) :: $5} | lhs Equals rhs Eof {[($1, $3)]} | Newline lines {$2} | White Newline lines {$3} | comment Newline lines {$3} lhs: Other lhstail {$1^$2} | RSquare lhstail {"]"^$2} noncom: Other {$1} | LSquare {"["} | RSquare {"]"} lhstail: {""} | noneq lhstail {$1^$2} noneq: noncom {$1} | Comment {"#"} rhs: {""} | any rhs {$1 ^ $2} any: noneq {$1} | Equals {"="}