kdl-org / kdl

the kdl document language specifications
https://kdl.dev
Other
1.1k stars 61 forks source link

Define `digit` in formal grammar #236

Closed CAD97 closed 2 years ago

CAD97 commented 2 years ago

digit is used as a subtraction in bare-identifier, but never defined.


An alternate change:

decimal := integer ('.' digit digit_*)? exponent?
exponent := ('e' | 'E') integer
integer := sign? digit digit_*
digit := [0-9]
digit_ := [0-9_]
sign := '+' | '-'

(NOTE: this has now flip-flopped to opposite what it was when @tabatkins made their comment.)

I think I slightly prefer the PR'd version, but it changes the implied grammar tree structure more significantly. This change "just" gives names to the [0-9] and [0-9_] productions.

tabatkins commented 2 years ago

Afaict both the PR and the alternate change are correct and produce no normative change beyond solving the original issue 👍

I actually slightly prefer the alternate change; I know that I initially missed that an exponent could have a sign when I was implementing, and so I like being more explicit with where exactly a sign is allowed in a number. It also avoids defining a digit_, which I slightly prefer.

CAD97 commented 2 years ago

Swapped in the preferred change instead of the less desirable minimal one