- From: fuchsia via GitHub <sysbot+gh@w3.org>
- Date: Mon, 31 Jul 2017 20:24:16 +0000
- To: public-svg-issues@w3.org
Step 1: the SVG 1.1 grammer in EBNF
--------------------------------------
```
svg-path ::= wsp* command*
command ::= moveto-command wsp* (drawto-command wsp*)*
moveto-command ::= moveto
drawto-command ::= closepath
| lineto
| horizontal-lineto
| vertical-lineto
| curveto
| smooth-curveto
| quadratic-bezier-curveto
| smooth-quadratic-bezier-curveto
| elliptical-arc
closepath ::= [Zz]
moveto ::= [Mm] wsp* moveto-argument (comma-wsp? lineto-argument)*
moveto-argument ::= coordinate-pair
lineto ::= [Ll] wsp* lineto-argument (comma-wsp? lineto-argument)*
lineto-argument ::= coordinate-pair
horizontal-lineto ::= [Hh] wsp* horizontal-lineto-argument
(comma-wsp? horizontal-lineto-argument)*
horizontal-lineto-argument ::=
coordinate
vertical-lineto ::= [Vv] wsp* vertical-lineto-argument
(comma-wsp? vertical-lineto-argument)*
vertical-lineto-argument ::=
coordinate
curveto ::= [Cc] wsp* curveto-argument (comma-wsp? curveto-argument)*
curveto-argument ::= coordinate-pair comma-wsp? coordinate-pair comma-wsp? coordinate-pair
smooth-curveto ::= [Ss] wsp* smooth-curveto-argument
(comma-wsp? smooth-curveto-argument)*
smooth-curveto-argument ::=
coordinate-pair comma-wsp? coordinate-pair
quadratic-bezier-curveto ::=
[Qq] wsp* quadratic-bezier-curveto-argument
(comma-wsp? quadratic-bezier-curveto-argument)*
quadratic-bezier-curveto-argument ::=
coordinate-pair comma-wsp? coordinate-pair
smooth-quadratic-bezier-curveto ::=
[Tt] wsp* smooth-quadratic-bezier-curveto-argument
(comma-wsp? smooth-quadratic-bezier-curveto-argument)*
smooth-quadratic-bezier-curveto-argument ::=
coordinate-pair
elliptical-arc ::= [Aa] wsp* elliptical-arc-argument
(comma-wsp? elliptical-arc-argument)*
elliptical-arc-argument ::=
nonnegative-number comma-wsp? nonnegative-number comma-wsp?
number comma-wsp flag comma-wsp? flag comma-wsp? coordinate-pair
coordinate-pair ::= coordinate comma-wsp? coordinate
flag ::= [01]
comma-wsp ::= (wsp+ (comma wsp*)) | (comma? wsp*)
comma ::= ","
coordinate ::= number
number ::= sign? nonnegative-number
nonnegative-number ::= fraction exponent?
fraction ::= ( digits ( dot digits? )? ) | ( dot digits )
exponent ::= [Ee] sign? digits
sign ::= "+" | "-"
digits ::= [0-9]+
dot ::= "."
wsp ::= [#x9#xA#xD#x20]
```
I've tried my hardest to be consistent. (And, trust me, that comes very unnaturally to me; if there are two ways of doing something, I'll manage it in three.)
Changes I've made:
- Every command now has an xxx-argument which contains the argument for that single command. That wasn't the case.
- Recursion has been eliminated. I remain conflicted about this because recursion is an easy idiom _once you're used to it._ But unless people are chucking this into Bison, I can't see its needed. And it's made the grammar simpler for non-experts, I think.
- I've made use of ranges (`[Mm]`) for the commands, rather than a quoted pair, except for sign - because the [EBNF spec](https://www.w3.org/TR/REC-xml/#sec-notation) doesn't make clear whether `[+-]` is legal. This is a stylistic choice that makes the commands shorter, but I'm not wed to it.
- I've kept the three separate number types: `number`, `nonnegative-number` and `flag`. But the existence of flag causes all sorts of havoc in the grammar. All those `*` and `?` quantifiers after `wsp` and `comma-wsp` are the result of `flag`. And, as I follow it, this is a legal description of an elliptical arc `M1 1A1 1 1 111 1`. (Space is required before the first flag, but the second flag and the next coordinate don't need any so `111` is three parameters each with a value 1.) I haven't tested any browsers and parsers to see if they get it right.
I've turned this EBNF into a recursive descent parser on [jsfiddle](https://jsfiddle.net/8pt7xfj6/5/). It's green for valid paths and red for invalid ones.
PS why is it wrong to define a comma as one of the space characters and allow them anywhere? (Something deep inside me objects. But I don't know why.)
--
GitHub Notification of comment by fuchsia
Please view or discuss this issue at https://github.com/w3c/svgwg/issues/335#issuecomment-319185643 using your GitHub account
Received on Monday, 31 July 2017 20:24:17 UTC