Replies: 3 comments 3 replies
-
Also I am not entirely sure how well the string approaches work with emojis etc., they seem to break off and I don't know if they can be put back together again after. |
Beta Was this translation helpful? Give feedback.
-
It does actually work in nearley though, even the document -> linespace:* (node (newline document):?):?
node -> identifier (node_space node_argument):* (node_space node_document):?
node_argument -> prop | value
node_document -> "{" linespace:* document linespace:* "}"
node_space -> ws:* escline ws:* | ws:+
identifier -> [a-zA-Z] [a-zA-Z0-9~!@#$%\^&*\-_+.:'|<>?//]:* | string
prop -> identifier "=" value
value -> string | raw_string | number | boolean | "null"
string -> "\"" ("\\" [\"\\] | [^"]):* "\""
raw_string -> "r" raw_string_hash
raw_string_hash -> "#" raw_string_hash "#" | raw_string_quotes
raw_string_quotes -> "\"" .:* "\""
number -> decimal | hex | octal | binary
decimal -> integer ("." [0-9]:+):? exponent:?
exponent -> ("e" | "E") integer
integer -> sign:? [1-9] [0-9_]:*
sign -> "+" | "-"
hex -> "0x" [0-9a-fA-F] [0-9a-fA-F_]:*
octal -> "0o" [0-7] [0-7_]:*
binary -> "0b" ("0" | "1") ("0" | "1" | "_"):*
boolean -> "true" | "false"
escline -> "\\" newline
linespace -> newline | ws | single_line_comment
newline -> ("\r" "\n") | "\n"
ws -> " " | "\t" | multi_line_comment
single_line_comment -> "//" [^\n]:+ newline
multi_line_comment -> "/*" ("*" [^\/] | [^*]):* "*/" |
Beta Was this translation helpful? Give feedback.
-
omg thanks so much for doing this! This is awesome. I'm amazed that my random grammar syntax "mostly" just worked with nearley! Would you like to PR this grammar, so we can start iterating further on it? |
Beta Was this translation helpful? Give feedback.
-
Some suggestions for the grammar. I applied the following changes and ran it on the examples.
1.
and.1
.node
whitespace rules are but something like below. This has the "command" followed by any number ofprop | value
s (separated by whitespace with one optional escaped newline), then optionally followed by whitespace with one optional escaped newline and a nested document. I also moved the trailing newline todocument
because otherwise all files would have to end with a newline (I guess that's preferred but maybe not mandatory?)*/
should be able to be escaped):identifier
is not complete when comparing to the example (missing the hat, single quote, pipe and angle brackets)document
? I don't like the double?
but I have not found anything else yet.As for the raw string, I wanted to remove the
*n
to keep the grammar of the grammar simple but that's not very easy without backtracking. I thought something like this but that does not work.Beta Was this translation helpful? Give feedback.
All reactions