%name Parser %token_prefix TOKEN_ %left OR. %left AND. %right NOT. %include { // include something } %code { &&REPLACER{process.js}&& } %syntax_error { console.log("Syntax error"); } main ::= expr(A) . { _result.root_node = A } integer(A) ::= INTEGER_LITERAL(B) . { A = new Node({ type: "INTEGER_LITERAL", lexeme: B.lexeme, start: B.start, end: B.end }) } literal(A) ::= integer(B) . { A = new Node({ type: "literal", children: [B] }) } string(A) ::= STRING_LITERAL(B) . { A = new Node({ type: "STRING_LITERAL", lexeme: B.lexeme, start: B.start, end: B.end }) } id(A) ::= string(B) . { A = new Node({ type: "id", children: [B] }); } id(A) ::= ID(B) . { A = new Node({ type: "ID", lexeme: B.lexeme, start: B.start, end: B.end }) } eq(A) ::= id(B) EQ(C) literal(D) . { A = new Node({ type: "eq", children: [ B, new Node({ type: "EQ", lexeme: C.lexeme, start: C.start, end: C.end }), D ] }) } and(A) ::= expr(B) AND expr(D) . { A = new Node({ type: "and", children: [ B, D ] }) } expr(A) ::= eq(B) . { A = new Node({ type: "expr", children: [B] }) } expr(A) ::= and(B) . { A = B; } expr(A) ::= LCB expr(C) RCB . { A = C; } address_literal_content(A) ::= STRING_LITERAL(B) . { A = new Node({ children: [ new Node({ type: "STRING_LITERAL", lexeme: B.lexeme, start: B.start, end: B.end }) ] }); } address_literal_content(A) ::= address_literal_content(B) COMMA STRING_LITERAL(C) . { B.add(new Node({ type: "STRING_LITERAL", lexeme: C.lexeme, start: C.start, end: C.end })); A = B; } address_literal_content_or_empty(A) ::= address_literal_content(B) . { A = B; } address_literal_content_or_empty(A) ::= . { A = new Node({ type: "address_literal_content" }); } address_literal(A) ::= ADDRESS LSB address_literal_content_or_empty(C) RSB . { A = new Node({ type: "address_literal", children: C.children }); } literal(A) ::= address_literal(B) . { A = new Node({ type: "literal", children: [B] }); }