aboutsummaryrefslogtreecommitdiff
path: root/scanners.go
diff options
context:
space:
mode:
Diffstat (limited to 'scanners.go')
-rw-r--r--scanners.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/scanners.go b/scanners.go
new file mode 100644
index 0000000..b5811af
--- /dev/null
+++ b/scanners.go
@@ -0,0 +1,25 @@
+package unilex
+
+// ScanNumber simplest scanner that accepts decimal int and float.
+func ScanNumber(l *Lexer) bool {
+ l.AcceptWhile("0123456789")
+ if l.AtStart() {
+ // not found any digit
+ return false
+ }
+ l.Accept(".")
+ l.AcceptWhile("0123456789")
+ return !l.AtStart()
+}
+
+// ScanAlphaNum returns true if next input token contains alphanum sequence that not starts from digit and not contains.
+// spaces or special characters.
+func ScanAlphaNum(l *Lexer) bool {
+ digits := "0123456789"
+ alpha := "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
+ if !l.Accept(alpha) {
+ return false
+ }
+ l.AcceptWhile(alpha + digits)
+ return true
+}