ianh / owl

A parser generator for visibly pushdown languages.
MIT License
746 stars 21 forks source link

Hexadecimal input is parsed as number instead of integer #28

Closed falkoschindler closed 2 years ago

falkoschindler commented 2 years ago

I was thinking about adding support for hexadecimal arguments in my grammar, when I noticed that OWL already parses things like "0xff". But why is every hex input parsed as a number and not an integer? In my application it messes with the type checking system, because some function might expect an integer and would refuse to accept "0xff".

For example, the grammar

input = argument{','}
argument =
  integer : int
  number : num

with the input

1, 1.2, 0xff, 0xff.f

yields:

1           , 1.2         , 0xff        , 0xff.f      
argument:int  argument:num  argument:num  argument:num

Would it be possible to distinguish hex integers and hex floating point numbers without writing a new tokenize function?

ianh commented 2 years ago

Ah, this is because strtod is used to parse numbers. It accepts hexadecimal numbers, while owl's hand-written integer parser doesn't. This is definitely an oversight.

ianh commented 2 years ago

This should be fixed in 92c1b65.

falkoschindler commented 2 years ago

Awesome, that was quick! It seems to be working nicely. Thanks a lot!