Skip to content

Commit

Permalink
chore(tooling): Fixup ABNF grammar with proper quoted value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jan 29, 2024
1 parent 160501c commit 3cfbf5f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions inputters/sil_spec.lua
Expand Up @@ -44,6 +44,12 @@ describe("#SIL #inputter", function ()
assert.is.equal("bar", t[1][1])
end)

it("commands with space around args and values", function()
local t = inputter:parse([[\foo[ baz = qiz qiz ]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
assert.is.equal("qiz qiz", t.options.baz)
end)

it("commands with multiple quoted args", function()
local t = inputter:parse([[\foo[baz="qiz, qiz",qiz="baz, baz"]{bar}]])[1][1][1]
assert.is.equal("foo", t.command)
Expand Down
29 changes: 21 additions & 8 deletions sil.abnf
Expand Up @@ -39,7 +39,7 @@ env-passthrough-text = utf8-text
comment = "%" utf8-text CRLF

; Input strings that are not special
text = *( text-char / escaped-specials )
text = *text-char

; Input content wrapped in braces can be attatched to a command or used to
; manually isolate chunks of content (e.g. to hinder ligatures).
Expand All @@ -55,15 +55,28 @@ braced-passthrough-text = utf8-text

; Building blocks
options = "[" parameter *( "," parameter ) "]"
parameter = *WSP sil-identifier *WSP "=" *WSP ( value / quoted-value ) *WSP
value = utf8-text
quoted-value = DQUOTE utf8-text DQUOTE
parameter = *WSP sil-identifier *WSP "=" *WSP ( quoted-value / value ) *WSP
quoted-value = DQUOTE *quoted-value-char DQUOTE
value = *value-char

specials = "\" / "%" / "{" / "}"
escaped-specials = "\" specials
value-char =/ %x00-21 ; omit "
value-char =/ %x23-2B ; omit ,
value-char =/ %x2D-3A ; omit ;
value-char =/ %x3C-5C ; omit ]
value-char =/ %x3E-7F ; end of utf8-1
value-char =/ utf8-2
value-char =/ utf8-3
value-char =/ utf8-4

; non-ascii-char = %x80-D7FF / %xE000-10FFFF
text-char = %x0-24 ; omit %
quoted-value-char = "\" %x22
quoted-value-char =/ %x00-21 ; omit "
quoted-value-char =/ %x23-7F ; end of utf8-1
quoted-value-char =/ utf8-2
quoted-value-char =/ utf8-3
quoted-value-char =/ utf8-4

text-char = "\" ( %x5C / %x25 / %x7B / %x7D )
text-char =/ %x00-24 ; omit %
text-char =/ %x26-5B ; omit \
text-char =/ %x5D-7A ; omit {
text-char =/ %x7C ; omit }
Expand Down

0 comments on commit 3cfbf5f

Please sign in to comment.