Trident D'Gao
Trident D'Gao

Reputation: 19762

Expected any character but end of input found

my input is a recursive structure looks like this (notice the blank 2nd line):

xxx @{} yyy @{ zzz @{} wwww }
 

the grammar as i see that would read it should look like this:

start = item+
item = thing / space
thing = '@{' item* '}'
space = (!'@' .)+

but what i get is

Line 2, column 1: Expected "@{", "}", or any character but end of input found.

what am i doing wrong?

Upvotes: 0

Views: 3446

Answers (2)

Trident D'Gao
Trident D'Gao

Reputation: 19762

In order to make it run, I modified the code as:

start = item+
item = thing / space
thing = '@{' item* '}'
space =[^@}]+

Upvotes: 0

Gene
Gene

Reputation: 47010

I do not know peg at all, but a quick look at the docs seems to say the dot in the 4th rule is the problem. The online parser succeeds with:

start = item+
item = thing / space
thing = '@{' item* '}'
space = [ a-z]+

This produces:

[
   [
      "x",
      "x",
      "x",
      " "
   ],
   [
      "@{",
      [],
      "}"
   ],
   [
      " ",
      "y",
      "y",
      "y",
      " "
   ],
   [
      "@{",
      [
         [
            " ",
            "z",
            "z",
            "z",
            " "
         ],
         [
            "@{",
            [],
            "}"
         ],
         [
            " ",
            "w",
            "w",
            "w",
            "w",
            " "
         ]
      ],
      "}"
   ]
]

Upvotes: 1

Related Questions