instaparse icon indicating copy to clipboard operation
instaparse copied to clipboard

Says ':' is invalid input for cypher.ebnf

Open sihingkk opened this issue 3 years ago • 3 comments

(insta/defparser parse-cypher
  "https://s3.amazonaws.com/artifacts.opencypher.org/M18/cypher.ebnf")
Error parsing grammar specification: Parse error at line 284, column 50:
   MapLiteral = '{', [SP], [PropertyKeyName, [SP], ':', [SP], Expression, [SP],
   { ',', [SP], PropertyKeyName, [SP], ':', [SP], Expression, [SP] }], '}' ; ^
   Expected one of: ? (* * + / ! & ε eps EPSILON epsilon Epsilon < ( { [
   #"#\"[^\"\\]*(?:\\.[^\"\\]*)*\"(?x) #Double-quoted regexp"
   #"#'[^'\\]*(?:\\.[^'\\]*)*'(?x) #Single-quoted regexp"
   #"\"[^\"\\]*(?:\\.[^\"\\]*)*\"(?x) #Double-quoted string"
   #"'[^'\\]*(?:\\.[^'\\]*)*'(?x) #Single-quoted string" } | #"[^,
   \r\t\n<>(){}\[\]+*?:=|'"#&!;./]+(?x) #Non-terminal"

I can't figure out why ':' is a bad expression.

sihingkk avatar Aug 19 '22 21:08 sihingkk

In that line, it looks like [PropertyKeyName has a left bracket but no right bracket.

Engelberg avatar Aug 19 '22 21:08 Engelberg

@Engelberg Thanks for reply.

it does have right bracket on the end of the line:

, [SP] }], '}' ;

it have the same error even if MapLiteral is reduced to:

 MapLiteral = ':';

sihingkk avatar Aug 24 '22 16:08 sihingkk

I believe the culprit is in your EscapedChar rule. Your rule begins '\'. That backslash is escaping that single-quote character, which is throwing off everything that follows. You probably mean '\\'.

I see some other issues you'll need to resolve. You use a - character frequently, which has no meaning in EBNF, and bounded repetition like 4 * HexDigit is an ABNF concept, not EBNF. But I don't think these are causing this specific error; it is treating - and 4 as the names of non-terminals it is expecting you to define later.

The best way to troubleshoot this kind of thing is to try to shrink the grammar and see what happens. The instaparse.combinators/ebnf function is very useful to work with smaller grammar fragments and see how they are parsed.

Engelberg avatar Aug 25 '22 07:08 Engelberg