Skip to content

garbled parse in erroneous grammar #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
guitarvydas opened this issue Mar 25, 2025 · 0 comments
Open

garbled parse in erroneous grammar #501

guitarvydas opened this issue Mar 25, 2025 · 0 comments

Comments

@guitarvydas
Copy link

I load the following grammar and test into ohm-editor and set the start rule to "KVkeep_inputport". The parse fails. When I click on the "Explain parse" option, the parse tree shows garbled information (scroll to far right).

background: I am trying to figure out why the comma in ,..."contents":{...} is disappearing when I set the start rule to "object". [This probably has to do with a misunderstanding I have about space-skipping and shortest vs. longest match, but, it doesn't change the fact that the editor parse appears garbled].

grammar:

keep {
  main = item+
  item =
    | rootArray -- root
    | "{" spaces item+ "}" -- braces
    | "[" spaces item+ "]" -- square
    | ~"{" ~"}" ~"[" ~"]" any
  rootArray = "[" object+ "]"
  object = "{" kvPair+ "}"
  kvPair = 
    | applySyntactic<KVkeep> -- keep
    | string ":" other+ -- ignore
    | space -- separator

  KVkeep =
    | Key<"attributes"> "{" ID Key<"kind"> value<"inputgate"> (#other)* "}"-- inputgate
    | Key<"attributes"> "{" ID Key<"kind"> value<"inputport"> (#other)* "}" -- inputport
    | Key<"attributes"> "{" ID Key<"kind"> value<"outputgate"> (#other)* "}" -- outputgate
    | Key<"attributes"> "{" ID Key<"kind"> value<"outputport"> (#other)* "}" -- outputport
    | Key<"attributes"> "{" ID Key<"kind"> value<"part"> (#other)* "}" -- part
    | Key<"attributes"> "{" ID Key<"kind"> value<"wire"> (#other)* "}" -- wire


  other =
    | "{" ws other+ "}" ws -- braces
    | "[" ws other+ "]" ws -- square
    | ~"{" ~"}" ~"[" ~"]" any -- default

  ID = Key<"id"> string

  Key<s> = dq s dq ":"
  value<s> = dq s dq
  string = dq (~dq any)* dq
  dq = "\""
  space += ","
  ws = spaces
}

test:

"attributes": {
              "id": "3",
              "kind": "inputport",
              "label": "pin",
              "parent": "2"
            },
            "contents": {
              "boundingbox": [
                -16.75,
                27.5,
                36.75,
                25
              ]
            }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant