We're a place where coders share, stay up-to-date and grow their careers.
Use parser, for example pegjs.org/online
Expression = "(" _ head:(Expression / Pair) _ ")" { return head; } / "(" _ head:(Expression / Pair) _ operator:("AND" / "OR") _ tail: (Expression / Pair) _ ")" { return { [operator]: [head, tail]}; } Pair = head:String _ ":" _ tail:String { return [head, tail]; } String "string" = "\"" [^\"]+ "\"" { return text(); } _ "whitespace" = [ \t\n\r]*
Use parser, for example pegjs.org/online