summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-13 19:16:11 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-08-14 12:07:22 -0600
commit567beedfc8f6418e27259fa774e6c7ba1a685c22 (patch)
tree17dfea6e8c4201baafac2f2923f3ec5c5b33ce51 /parse.go
parentb379bd7c2fba1e7d2c9429b3ffb93afdabd88cbd (diff)
parse: Fix a bug in the number parser
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/parse.go b/parse.go
index e09b85a..a1c5472 100644
--- a/parse.go
+++ b/parse.go
@@ -304,13 +304,27 @@ func (par *parser) stateInEscUC(c rune) (RuneType, error) {
// [-------------- integer ------------][--------- fraction --------][--------- exponent ---------]
// >─A─╮───────╭──╮─"0"─────────C─╭─────────╮──────────────────╭─────────╮──────────────────────────╭─>
// │ │ │ │ │ │ │ │
-// ╰─"-"─B─╯ ╰─digit 1-9─╭─D─╯─digit╮ ╰─"."─E─digit──╭─F─╯─digit╮ ╰─"e"─╭─G─╮─────╭─╭digit─H─╯
-// ╰────<─────╯ ╰────<─────╯ │ │ │ │ ╰────<───╯
+// ╰─"-"─B─╯ ╰─digit 1-9─╭─D─╯─digit╮ ╰─"."─E─digit──╭─F─╯─digit╮ ╰─"e"─╭─G─╮─────╭─╭digit─I─╯
+// ╰────<─────╯ ╰────<─────╯ │ │ │ H ╰────<───╯
// ╰─"E"─╯ ╰─"-"─╯
// │ │
// ╰─"+"─╯
//
// Which state we're at is the 'X' in 'stateNumberX'.
+//
+// It may be worth noting that these states, if we're going to try to
+// assign meaningful names, are perhaps best named by the type of the
+// preceding character:
+//
+// A = (nothing yet)
+// B = IntNeg
+// C = IntZero
+// D = IntDig
+// E = FracDot
+// F = FracDig
+// G = ExpE
+// H = ExpSign
+// I = ExpDig
// number: integer-part ////////////////////////////////////////////////////////
func (par *parser) stateNumberA(c rune) (RuneType, error) { // start
@@ -395,14 +409,26 @@ func (par *parser) stateNumberF(c rune) (RuneType, error) { // in the fraction p
// number: exponent-part ///////////////////////////////////////////////////////
func (par *parser) stateNumberG(c rune) (RuneType, error) { // got a leading "e"
switch c {
- case '-', '+', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
+ case '-', '+':
par.replaceState(par.stateNumberH, true)
return RuneTypeNumberExp, nil
+ case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
+ par.replaceState(par.stateNumberI, true)
+ return RuneTypeNumberExp, nil
+ default:
+ return RuneTypeError, fmt.Errorf("number: unexpected character: %c", c)
+ }
+}
+func (par *parser) stateNumberH(c rune) (RuneType, error) { // got a + or - sign
+ switch c {
+ case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
+ par.replaceState(par.stateNumberI, true)
+ return RuneTypeNumberExp, nil
default:
return RuneTypeError, fmt.Errorf("number: unexpected character: %c", c)
}
}
-func (par *parser) stateNumberH(c rune) (RuneType, error) { // in the exponent's number part
+func (par *parser) stateNumberI(c rune) (RuneType, error) { // in the exponent's number part
switch c {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
return RuneTypeNumberExp, nil