pozorfluo / build-your-own-lisp

following http://www.buildyourownlisp.com/
Other
5 stars 0 forks source link

Number notation without decimal separator is broken #1

Closed pozorfluo closed 4 years ago

pozorfluo commented 4 years ago
Lispy version 0.0.0.0.1 to Exit press CTRL + C
lispy> + 5 5
<stdin>:1:4: error: expected one of '0123456789', one of '.' or one or more of one of '0123456789' at space
lispy> + 5.0 5.35
> 
  regex 
  expr|symbol|char:1:1 '+'
  expr|number|regex:1:3 '5.0'
  expr|number|regex:1:7 '5.35'
  regex 
(+ 5.000000 5.350000 )
10.350000

regex currently used by parser for numbers :

[-]?[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?

does having a [0-9]+ ( ie one or more ) after a [.]? ( ie zero or one ) make the [.]? zero or one mandatory ?

how about :

[-]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?

this removes the possibility to start at the decimal separator ( eg : .56 ) shrug

pozorfluo commented 4 years ago
[-]?[0-9]+[.]?[0-9]*([eE][-+]?[0-9]+)?

will do for now