ohmjs / ohm

A library and language for building parsers, interpreters, compilers, etc.
MIT License
5.01k stars 217 forks source link

How to identify a single space character? #493

Closed Elderkly closed 1 month ago

Elderkly commented 1 month ago

I expect that when I input CREATE TYPE NAME, it matches the CreateNode statement and recognizes TYPE as NodeType and NAME as NodeName. However, when I test in the interactive editor, I find that when I input CREATE nodeType, it prompts Expected " ", which seems to indicate that the space I entered is not being recognized. How can I resolve this issue? Here is my grammar definition.

Commands {
  Command = CreateNode

  CreateNode = "CREATE" " " NodeType " " NodeName

  NodeType =  (~specialChar ~space any)+

  NodeName = SemicolonString |   QuotedString

  SemicolonString = ";"

  specialChar = ";" | "," | "." | "(" | ")" | "[" | "]"

  FilePath = QuotedString

  QuotedString = SingleQuoted | DoubleQuoted

  SingleQuoted
    ="'" (~"'" any)* "'"

  DoubleQuoted
    ="\"" (~"\"" any)* "\""
}