aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2016-09-23 19:28:15 -0400
committerEduardo Julian2016-09-23 19:28:15 -0400
commitae73bbae76e9b26b3dc419e0591133ab4b5ccfb9 (patch)
tree2e908b6a7e3c604e4655d1921b7b809b5ea8b03d
parent757fecf16811f10ad83752b592987202f9dbc5d2 (diff)
- Lexer now allows , and _ as separators for numbers.
-rw-r--r--src/lux/compiler/host.clj3
-rw-r--r--src/lux/lexer.clj13
2 files changed, 13 insertions, 3 deletions
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index e143ff92b..cdd17a1ee 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -826,6 +826,9 @@
(.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/String" "substring" "(I)Ljava/lang/String;")
(.visitTryCatchBlock $from $to $handler "java/lang/Exception")
(.visitLabel $from)
+ (.visitLdcInsn ",|_")
+ (.visitLdcInsn "")
+ (.visitMethodInsn Opcodes/INVOKEVIRTUAL "java/lang/String" "replaceAll" "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;")
(.visitMethodInsn Opcodes/INVOKESTATIC "java/lang/Long" "parseUnsignedLong" "(Ljava/lang/String;)J")
(.visitLabel $to)
;; (.visitJumpInsn Opcodes/GOTO $then)
diff --git a/src/lux/lexer.clj b/src/lux/lexer.clj
index 690a25106..f52823bfc 100644
--- a/src/lux/lexer.clj
+++ b/src/lux/lexer.clj
@@ -158,9 +158,16 @@
(return (&/T [meta (<tag> token)]))))
lex-bool $Bool #"^(true|false)"
- lex-nat $Nat #"^\+(0|[1-9][0-9]*)"
- lex-int $Int #"^-?(0|[1-9][0-9]*)"
- lex-real $Real #"^-?(0\.[0-9]+|[1-9][0-9]*\.[0-9]+)(e-?[1-9][0-9]*)?"
+ )
+
+(do-template [<name> <tag> <regex>]
+ (def <name>
+ (|do [[meta _ token] (&reader/read-regex <regex>)]
+ (return (&/T [meta (<tag> (string/replace token #",|_" ""))]))))
+
+ lex-nat $Nat #"^\+(0|[1-9][0-9,_]*)"
+ lex-int $Int #"^-?(0|[1-9][0-9,_]*)"
+ lex-real $Real #"^-?(0\.[0-9,_]+|[1-9][0-9,_]*\.[0-9,_]+)(e-?[1-9][0-9,_]*)?"
)
(def lex-char