PEG: tweak commas and symbols

This commit is contained in:
Emery Hemingway 2023-12-20 12:20:18 +02:00
parent dbe9f3566f
commit 558a1a862a
1 changed files with 12 additions and 13 deletions

View File

@ -9,7 +9,8 @@ when defined(nimHasUsed): {.used.}
grammar "Preserves":
ws <- *(' ' | '\t' | '\r' | '\n' | ',')
ws <- *(' ' | '\t' | '\r' | '\n' )
commas <- *(ws * ',') * ws
Document <- Value * ws * !1
@ -22,13 +23,13 @@ grammar "Preserves":
Atom <- Boolean | Float | Double | FloatRaw | DoubleRaw | SignedInteger | String | ByteString | Symbol
Record <- '<' * Value * *Value * ws * '>'
Record <- '<' * +Value * ws * '>'
Sequence <- '[' * *Value * ws * ']'
Sequence <- '[' * *(commas * Value) * commas * ']'
Dictionary <- '{' * *(Value * ':' * Value) * ws * '}'
Dictionary <- '{' * *(commas * Value * ws * ':' * Value) * commas * '}'
Set <- "#{" * *Value * ws * '}'
Set <- "#{" * *(commas * Value) * commas * '}'
Boolean <- "#f" | "#t"
@ -55,14 +56,12 @@ grammar "Preserves":
binchar <- binunescaped | (escape * (escaped | '"' | ('x' * Xdigit[2])))
binunescaped <- {' '..'!', '#'..'[', ']'..'~'}
symstart <- Alpha | sympunct | symustart
symcont <- Alpha | sympunct | symustart | symucont | Digit | '-'
sympunct <- {'~', '!', '$', '%', '^', '&', '*', '?', '_', '=', '+', '/', '.'}
symchar <- unescaped | '"' | (escape * (escaped | '|' | ('u' * Xdigit)))
symustart <- utf8.any - {0..127}
symucont <- utf8.any - {0..127}
# TODO: exclude some unicode ranges
Symbol <- >(symstart * *symcont) | ('|' * >(*symchar) * '|')
symchar <- (utf8.any - { 0..127, '\\', '|' }) | (escape * (escaped | ('u' * Xdigit[4]))) | "\\|"
QuotedSymbol <- '|' * >(*symchar) * '|'
sympunct <- {'~', '!', '$', '%', '^', '&', '*', '?', '_', '=', '+', '-', '/', '.'}
symuchar <- utf8.any - { 0..127 }
SymbolOrNumber <- >(+(Alpha | Digit | sympunct | symuchar))
Symbol <- QuotedSymbol | SymbolOrNumber
Embedded <- "#!" * Value