aboutsummaryrefslogtreecommitdiff
path: root/example/math_expression/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'example/math_expression/main.go')
-rw-r--r--example/math_expression/main.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/example/math_expression/main.go b/example/math_expression/main.go
index bfece39..805028e 100644
--- a/example/math_expression/main.go
+++ b/example/math_expression/main.go
@@ -1,5 +1,3 @@
-// +build example
-
package main
import (
@@ -8,6 +6,13 @@ import (
"github.com/neonxp/unilex"
)
+const (
+ LP unilex.LexType = iota
+ RP
+ NUMBER
+ OPERATOR
+)
+
func main() {
l := unilex.New("10 * (20.0 + 30.0)")
@@ -29,13 +34,13 @@ func lexExpression(l *unilex.Lexer) unilex.StateFunc {
switch {
case l.Accept("("):
- l.Emit("LP")
+ l.Emit(LP)
case l.Accept(")"):
- l.Emit("RP")
+ l.Emit(RP)
case unilex.ScanNumber(l):
- l.Emit("NUMBER")
+ l.Emit(NUMBER)
case l.Accept("+-*/^!"):
- l.Emit("OPERATOR")
+ l.Emit(OPERATOR)
case l.Peek() == unilex.EOF:
return nil
default: