Skip to content

Commit

Permalink
fixed another bug in bigint handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jan 6, 2014
1 parent b3b16ee commit 89d966b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
21 changes: 10 additions & 11 deletions newlisp-parser-test.lsp
Expand Up @@ -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})))

Expand All @@ -51,6 +52,4 @@

(println "\n" {all tests completed})

(println (Nlex:parse-newlisp "(+ 2 2)"))

(exit)
7 changes: 4 additions & 3 deletions newlisp-parser.lsp
Expand Up @@ -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)))
Expand All @@ -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))))
Expand Down

0 comments on commit 89d966b

Please sign in to comment.