From ae73bbae76e9b26b3dc419e0591133ab4b5ccfb9 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 23 Sep 2016 19:28:15 -0400 Subject: - Lexer now allows , and _ as separators for numbers. --- src/lux/compiler/host.clj | 3 +++ src/lux/lexer.clj | 13 ++++++++++--- 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 ( 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 [ ] + (def + (|do [[meta _ token] (&reader/read-regex )] + (return (&/T [meta ( (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 -- cgit v1.2.3