Skip to content

Commit

Permalink
Initial support for decimal datatype in the lexer.r
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Mar 1, 2014
1 parent 386b373 commit 2e6a86c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lexer.r
Expand Up @@ -211,7 +211,33 @@ lexer: context [
] :pos
fail?
]


decimal-number-rule: [
(type: decimal!)
opt [#"-" | #"+"] [
;for numbers like: 1.0 -1.e2 1.0e-2
[
any digit #"." some digit
| some digit #"." any digit
]
opt [[#"e" | #"E"] opt [#"-" | #"+"] some digit]
|
;for numbers like: 1e2
some digit
[#"e" | #"E"] opt [#"-" | #"+"] some digit
]
e:
]

decimal-rule: [
decimal-number-rule
pos: [ ;-- protection rule from typo with sticky words
[integer-end | ws-no-count | end] (fail?: none)
| skip (fail?: [end skip])
] :pos
fail?
]

block-rule: [#"[" (stack/push block!) any-value #"]" (value: stack/pop block!)]

paren-rule: [#"(" (stack/push paren!) any-value #")" (value: stack/pop paren!)]
Expand Down Expand Up @@ -326,6 +352,7 @@ lexer: context [
| multiline-comment-rule
| escaped-rule (stack/push value)
| integer-rule (stack/push load-integer copy/part s e)
| decimal-rule (stack/push load-decimal copy/part s e)
| hexa-rule (stack/push decode-hexa copy/part s e)
| word-rule (stack/push to type value)
| lit-word-rule (stack/push to type value)
Expand Down Expand Up @@ -485,6 +512,11 @@ lexer: context [
s
]
load-decimal: func [s [string!]][
unless attempt [s: to decimal! s][throw-error]
s
]
load-string: func [s [string!] e [string!] /local new filter][
new: make string! offset? s e ;-- allocated size close to final size
filter: get pick [UTF8-char UTF8-filtered-char] s/-1 = #"{"
Expand Down

0 comments on commit 2e6a86c

Please sign in to comment.