Ignore letters other than e/E if number is decimal, and ignore all letters after e/E

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Ignore letters other than e/E if number is decimal, and ignore all letters after e/E

Soni "They/Them" L.
Currently Lua ignores some letters after numbers, but not enough:

 > x=1print(x)
1
 > x=1eprint(x)
stdin:1: malformed number near '1e'
 > x=1fprint(x)
stdin:1: malformed number near '1f'
 > x=1aprint(x)
stdin:1: malformed number near '1a'

additionally if your number has an e:

 > x=1e0eprint(x)
stdin:1: malformed number near '1e0e'

it'd be nicer if the number parser was more strict so only actual parts
of numbers would be consumed by it. this would make almost all of the
above cases valid lua, except x=1eprint(x)

Reply | Threaded
Open this post in threaded view
|

Re: Ignore letters other than e/E if number is decimal, and ignore all letters after e/E

Roberto Ierusalimschy
> Currently Lua ignores some letters after numbers, but not enough:
>
> > x=1print(x)
> 1
> > x=1eprint(x)
> stdin:1: malformed number near '1e'
> > x=1fprint(x)
> stdin:1: malformed number near '1f'
> > x=1aprint(x)
> stdin:1: malformed number near '1a'
>
> additionally if your number has an e:
>
> > x=1e0eprint(x)
> stdin:1: malformed number near '1e0e'
>
> it'd be nicer if the number parser was more strict so only actual parts of
> numbers would be consumed by it. this would make almost all of the above
> cases valid lua, except x=1eprint(x)

Lua 5.4 takes the opposite approach. Any letter after a number is
consumed by it, so that idiosyncratic syntax like 'x=1print(x)' will
be invalid too.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Ignore letters other than e/E if number is decimal, and ignore all letters after e/E

Soni "They/Them" L.


On 2019-09-25 11:37 a.m., Roberto Ierusalimschy wrote:

> > Currently Lua ignores some letters after numbers, but not enough:
> >
> > > x=1print(x)
> > 1
> > > x=1eprint(x)
> > stdin:1: malformed number near '1e'
> > > x=1fprint(x)
> > stdin:1: malformed number near '1f'
> > > x=1aprint(x)
> > stdin:1: malformed number near '1a'
> >
> > additionally if your number has an e:
> >
> > > x=1e0eprint(x)
> > stdin:1: malformed number near '1e0e'
> >
> > it'd be nicer if the number parser was more strict so only actual parts of
> > numbers would be consumed by it. this would make almost all of the above
> > cases valid lua, except x=1eprint(x)
>
> Lua 5.4 takes the opposite approach. Any letter after a number is
> consumed by it, so that idiosyncratic syntax like 'x=1print(x)' will
> be invalid too.
>
> -- Roberto
>

Oh. Fair enough.

v
Reply | Threaded
Open this post in threaded view
|

Re: Ignore letters other than e/E if number is decimal, and ignore all letters after e/E

v
In reply to this post by Roberto Ierusalimschy
On Wed, 2019-09-25 at 11:37 -0300, Roberto Ierusalimschy wrote:

> > Currently Lua ignores some letters after numbers, but not enough:
> >
> > > x=1print(x)
> > 1
> > > x=1eprint(x)
> > stdin:1: malformed number near '1e'
> > > x=1fprint(x)
> > stdin:1: malformed number near '1f'
> > > x=1aprint(x)
> > stdin:1: malformed number near '1a'
> >
> > additionally if your number has an e:
> >
> > > x=1e0eprint(x)
> > stdin:1: malformed number near '1e0e'
> >
> > it'd be nicer if the number parser was more strict so only actual
> > parts of
> > numbers would be consumed by it. this would make almost all of the
> > above
> > cases valid lua, except x=1eprint(x)
>
> Lua 5.4 takes the opposite approach. Any letter after a number is
> consumed by it, so that idiosyncratic syntax like 'x=1print(x)' will
> be invalid too.
>
> -- Roberto
>

Oh well, RIP all my Lua codegolf :(

--
v <[hidden email]>