summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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