Re: [svgwg] Floating point number format discordance (SVG vs CSS vs browsers)

I admit, I hadn't thought about unit suffixes. I had thought about `M0.0` being split at the decimal point. And, in arcs, `000` can be three numbers while anything beginning 2-9 can be an illegal token, depending on how many numbers you've seen already; I'm reconciled to having to reparse numbers in arcs when that could be an issue.

But, forgetting about arcs, and working from [Draft 25](https://drafts.csswg.org/css-syntax/#consume-ident-like-token).

- Equip the tokeniser with a `tokenising-pathdata` flag.

- In "consume a numeric token" (`4.3.3`): have the tokeniser return the \<number-token\> immediately after consuming it, when `tokenising-pathdata` is set. The token has to be returned as a string because of the aforementioned arc issues. (Or we add a state var that tracks how deep into an arc argument you are.)

- In "consume an ident-like token" (`4.3.4`): if the string consumed is `"path"` and it's followed by a LEFT PARENTHESIS then set the `tokenising-pathdata` flag and return an appropriate token.

- In "consume a token" (`4.3.1`):
  - Amend the `U+0029 RIGHT PARENTHESIS ())` rule so that it clears the `tokenising-pathdata` flag.
  - And amend the `name-start code point` rule so it becomes:
    - If `tokenising-pathdata` is set, return a \<pathdata-command\> token whose value is the code-point.
    - Otherwise reconsume the current input code point, consume an ident-like token, and return it.

I've probably screwed up the details or misunderstood something, but isn't that outline enough?
Only returning numbers as strings strikes me as egregious. If the CSS parser grows an entry point that sets the `tokenising-pathdata` flag, then the whole SVG pathdata grammar can be condensed to:

```
<pathdata> = [<pathdata-command> [<number>#]*]*
```

Plus some rules for handling legacy elliptical arc arguments.

The arity and legality of commands can be handled at a higher level, just as you would in any programming language; it's not the role of grammar to name functions and specify their argument count.

---

Another suggestion I made was to give the SVGPathElement a property that returns the pathdata in a normal form: e.g. fully whitespace separated tokens. It doesn't have to be animated and it should stop at the first invalid number; i.e. it reflects what's actually drawn. Web programmers would love it because they could reliably parse pathdata by doing `pathdata.split(' ')`. And it would create a subset of pathdata that bridges to the CSS norm. This may turn out to be a more practical solution that the above.

-- 
GitHub Notification of comment by fuchsia
Please view or discuss this issue at https://github.com/w3c/svgwg/issues/331#issuecomment-341723085 using your GitHub account

Received on Friday, 3 November 2017 14:42:44 UTC