Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed another bug in bigint handling

  • Loading branch information...
commit 89d966b2b80fedeafdfc3643ce0f6cc2c8ba4a26 1 parent b3b16ee
@cormullion authored
Showing with 14 additions and 14 deletions.
  1. +10 −11 newlisp-parser-test.lsp
  2. +4 −3 newlisp-parser.lsp
View
21 newlisp-parser-test.lsp
@@ -24,25 +24,26 @@
(test {integers } {(map + 1 2 3 123 -1212312312 -13 -14 0 3 6 01 02 03 04 05 06 07 08 09 11 16)})
(test {floats } {(map add 1.2 -1.42 56. )})
(test {scientific } {123 0xE8 123e2 -1.3e-12 1.23 123e-3 45 1.23e4 42 1.123e-54} 'display)
+(test {bigint } {1234623827134691238746213947 12341293847621398476L} 'display)
; bracketed
-(test {[text] brackets } {[text](+ 1 1)[/text]})
-(test {[cmd] brackets } {[cmd](+ 1 1)[/cmd]})
+(test {[text] brackets } {[text](+ 1 1)[/text]})
+(test {[cmd] brackets } {[cmd](+ 1 1)[/cmd]})
(test {[CMD] brackets should fail } {[CMD](+ 1 1)[/CMD]})
-(test {both brackets } {[text][cmd](+ 1 1)[/cmd][/text]})
-(test {weird bracketed symbols } [text]myvar A-name [blah] X34-zz [* 7 5 ()};] *111*[/text] 'display)
+(test {both brackets } {[text][cmd](+ 1 1)[/cmd][/text]})
+(test {weird bracketed symbols } [text]myvar A-name [blah] X34-zz [* 7 5 ()};] *111*[/text] 'display)
; strings
-(test {strings braced} [text]{this is a braced string}[/text])
-(test {strings brackets} {[text]this is a bracketed string[/text]})
-(test {nested braces} [text]{this is {nested} braced string}[/text])
+(test {strings braced} [text]{this is a braced string}[/text])
+(test {strings brackets} {[text]this is a bracketed string[/text]})
+(test {nested braces} [text]{this is {nested} braced string}[/text])
; unicode
-(test {unicode } {{\unnnn} (utf8len "我能吞下玻璃而不伤身体。")} 'display)
+(test {unicode } {{\unnnn} (utf8len "我能吞下玻璃而不伤身体。")} 'display)
; try parsing some smallish files
-(test {this parser script } (read-file (string (env {HOME}) {/projects/programming/newlisp-projects/newlisp-parser.lsp})))
+(test {this parser script } (read-file (string (env {HOME}) {/projects/programming/newlisp-projects/newlisp-parser.lsp})))
;(test {markdown } (read-file (string (env {HOME}) {/projects/programming/newlisp-projects/markdown.lsp})))
;(test {life } (read-file (string (env {HOME}) {/projects/programming/newlisp-projects/life.lsp})))
@@ -51,6 +52,4 @@
(println "\n" {all tests completed})
-(println (Nlex:parse-newlisp "(+ 2 2)"))
-
(exit)
View
7 newlisp-parser.lsp
@@ -102,12 +102,10 @@
(let ((res '() number-as-string ""))
(set 'number-as-string (join (read-number-scanner (list c))))
(cond
+ ; the order is important, apparently
; literal bignum, ending with "L"
((ends-with number-as-string "L")
(set 'res (list 'BigintLit (bigint number-as-string))))
- ; implicit bignum, interpreted by newLISP as a bigint
- ((> (abs (bigint number-as-string) 9223372036854775807))
- (set 'res (list 'Bigint (bigint number-as-string))))
; try hex
((starts-with (lower-case number-as-string) "0x")
(set 'res (list 'Hex number-as-string)))
@@ -123,6 +121,9 @@
(> (length number-as-string) 1)
(empty? (difference (explode number-as-string) (explode "01234567"))))
(set 'res (list 'Octal number-as-string)))
+ ; implicit bignum, interpreted by newLISP as a bigint
+ ((> (abs (bigint number-as-string) 9223372036854775807))
+ (set 'res (list 'Bigint (bigint number-as-string))))
; perhaps an integer? 019 is read as 19 ...
((integer? (int number-as-string 0 10))
(set 'res (list 'Integer (int number-as-string 0 10))))
Please sign in to comment.
Something went wrong with that request. Please try again.