Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variadic grol side #99

Merged
merged 10 commits into from
Aug 4, 2024
Merged

Variadic grol side #99

merged 10 commits into from
Aug 4, 2024

Conversation

ldemailly
Copy link
Member

@ldemailly ldemailly commented Aug 4, 2024

So .. is a magic argument that both indicate that a function is variadic and also receives the array of optional arguments within the function

Probably need to document that last argument if an array of objects is expended for both grol and extension variadic functions, this makes:

printf=func(format, ..){print(sprintf(format, ..))}

work but printf(["%d\n", 42]) also works, ie any array not just ..

Also fixes #97

@ldemailly ldemailly requested a review from ccoVeille August 4, 2024 01:47
@ldemailly ldemailly changed the base branch from main to extensions_1 August 4, 2024 01:57
@ldemailly ldemailly force-pushed the variadic_grol_side branch from 11570e0 to a9ecb2e Compare August 4, 2024 02:22
@ldemailly ldemailly changed the base branch from extensions_1 to main August 4, 2024 02:22
@ldemailly ldemailly force-pushed the variadic_grol_side branch from a6d5018 to 3ad95bf Compare August 4, 2024 05:04
… otherwise log10(1000) is 2.9999... instead of 3
@@ -42,6 +42,7 @@ j--
/*/*/
/* This is a
multiline comment */
..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add something about

1..2
1 .. 3
1 .. 4
1.. 5

To make sure how the lexer reacts with things that could be interpreted as number

And maybe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are no range yet (1. is there already in many places)

1..2 is actually

1.
.2

but it's always been that

1 .. 2

complains about .. being undefined (unless used inside a varargs or set before)

short version is we need #56 and more documentation about the language

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fuzz testing would be nice too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#101 for fancier fuzz test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are no range yet

Not yet,y point was to add these to tests and see what happens.

So yes,the fuzzy testing might help

@@ -42,6 +42,7 @@ j--
/*/*/
/* This is a
multiline comment */
..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the following to test

...
. ..
.. .
....

… (a Unicode ellipsis)

My idea is to make sure nothing strange could pop out from a future refactoring

return token.ConstantTokenChar2(ch, nextChar)
}
// number can start with . eg .5
return token.Intern(l.readNumber(ch))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No check on isDigit before ?

See #99 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could have been "passthrough" but I already know it started with . so I don't want to redo the letter check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short version is unlike some of the other scripting language that force you to type 0.5, grol is fine with .5 (had to handle that in readNumber, including that it doesn't allow 2 dots etc... see that code and its tests)

Comment on lines +75 to 83
case '.':
if nextChar == '.' { // DOTDOT
l.pos++
return token.ConstantTokenChar2(ch, nextChar)
}
// number can start with . eg .5
return token.Intern(l.readNumber(ch))
default:
switch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected something like that

Suggested change
case '.':
if nextChar == '.' { // DOTDOT
l.pos++
return token.ConstantTokenChar2(ch, nextChar)
}
// number can start with . eg .5
return token.Intern(l.readNumber(ch))
default:
switch {
case '.':
if nextChar == '.' { // DOTDOT
l.pos++
return token.ConstantTokenChar2(ch, nextChar)
}
fallthrough
default:
switch {

or

Suggested change
case '.':
if nextChar == '.' { // DOTDOT
l.pos++
return token.ConstantTokenChar2(ch, nextChar)
}
// number can start with . eg .5
return token.Intern(l.readNumber(ch))
default:
switch {
default:
if ch == '.' && nextChar == '.' { // DOTDOT
l.pos++
return token.ConstantTokenChar2(ch, nextChar)
}
switch {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests according to this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are tests already for .3 etc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first proposal is worse as it does a check for letter when we already know there is a .

and same for 2nd one, also all the other 2 token check are in the main switch, not in default/fallback
the start with digit or number is I think actually clearer than with the before || ch = '.'

and I don't want to have ch == '.' checked twice, I prefer to repeat token.Intern(l.readNumber(ch))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong in the way I reported it

But my point was that code let me think there could be a problem with

1.a
.a
1.-
4. (4 dot space)

The current code seem to me to be:

  • we found a dot
  • let's read the number that follows

But what comes next might not be a number

Maybe it's something that readNumber handles well. But with previous code the one in the default case, the type was checked

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we found a dot let's read the number that follows

that's what the old code did too, if we agree that new code and old code are exactly the same except when .. is found we can then separate the issue of what happens with invalid numbers from the structure of the code

old (grol 0.31.0) code:

$ .a
11:49:35.063 [CRI] parser has 1 error(s)
11:49:35.063 [ERR] parser error: could not parse "." as float

same with new code and it'll be the same for all your examples as they don't involve 2 ..
(and again there are lots of test about these, like 4. space is 4.0 float and spaces are ignored, etc)

@ldemailly
Copy link
Member Author

been trying to apply batch of 6 or 7 suggestions for the 3rd time already, getting "can't have more than 1 suggestion per line" bogus GitHub error

ldemailly and others added 5 commits August 3, 2024 22:49
@ccoVeille
Copy link
Contributor

What about adding to number tests things that could come later

1.3e6
1+6i

Adding them to test would raise errors, but then you will think about fixing later

@ldemailly
Copy link
Member Author

you filled a follow up for _ and 1e6 and I filled for fuzz testing, can we merge this?

it's quite a big addition, and so is #102 and I'd like to get both in (as long as there is no terrible tech debt or bug)

@ccoVeille
Copy link
Contributor

Yes, they can be merged

@ldemailly ldemailly merged commit e6fb1f8 into main Aug 4, 2024
1 check passed
@ldemailly ldemailly deleted the variadic_grol_side branch August 4, 2024 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add some grol stdlib in grol
2 participants