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

Syntax errors in EvalString sometimes not displayed correctly #5242

Closed
zickgraf opened this issue Dec 5, 2022 · 4 comments · Fixed by #5246
Closed

Syntax errors in EvalString sometimes not displayed correctly #5242

zickgraf opened this issue Dec 5, 2022 · 4 comments · Fixed by #5246

Comments

@zickgraf
Copy link
Contributor

zickgraf commented Dec 5, 2022

Observed behaviour

gap> EvalString( "(1;" );
Syntax error: ) expected in stream:1
�
Error, Could not evaluate string.

Expected behaviour

gap> EvalString( "(1;" );
Syntax error: ) expected in stream:1
_EVALSTRINGTMP:=(1;
                  ^
Error, Could not evaluate string.

Sometimes the error is displayed as expected:

gap> EvalString( ";;" );
Syntax error: expression expected in stream:1
_EVALSTRINGTMP:=;;;
                ^^
Error, Could not evaluate string.

but I could not find a pattern.

Copy and paste GAP banner (to tell us about your setup)

 ┌───────┐   GAP 4.12.1 of 2022-10-20
 │  GAP  │   https://www.gap-system.org
 └───────┘   Architecture: x86_64-pc-linux-gnu-default64-kv8
 Configuration:  gmp 6.2.1, GASMAN, readline
 Loading the library and packages ...
 Packages:   GAPDoc 1.6.6.dev, IO 4.7.0dev, PrimGrp 3.4.2, SmallGrp 1.5, TransGrp 3.6.3
 Try '??help' for help. See also '?copyright', '?cite' and '?authors'
@fingolfin
Copy link
Member

The funny character is ASCII 255 and this comes from reading till EOF. We've had similar buglets in the past. Not sure if it's worth the effort to fix it properly, though? What's the usecase?

@zickgraf
Copy link
Contributor Author

zickgraf commented Dec 5, 2022

What's the usecase?

I'm using EvalString for metaprogramming and it's much easier to find errors if the error message points right at the point where something is missing/unexpected. The above is only a minimal example, this also happens in more complex cases.

@fingolfin
Copy link
Member

Note that you can avoid the issue (at least in the cases I am aware of) by ensuring your string always ends with a newline:

gap> EvalString( "(1;\n" );
Syntax error: ) expected in stream:1
_EVALSTRINGTMP:=(1;
                  ^
Error, Could not evaluate string.

@zickgraf
Copy link
Contributor Author

zickgraf commented Dec 6, 2022

A newline in the input string is not always sufficient:

gap> EvalString( "(1\n" );
Syntax error: ) expected in stream:2
�
Error, Could not evaluate string.

But indeed a newline helps when adding it after the semicolon added by EvalString. This also explains why it usually does not happen on the REPL (commands are naturally completed by a newline) or when reading from files (which usually end with a newline character). As expected, the same problem occurs when ommiting the newline on the REPL:

$ echo -n "(1;" | gap
 ┌───────┐   GAP 4.12.1 of 2022-10-20
 │  GAP  │   https://www.gap-system.org
 └───────┘   Architecture: x86_64-pc-linux-gnu-default64-kv8
 Configuration:  gmp 6.2.1, GASMAN
 Loading the library and packages ...
 Packages:   GAPDoc 1.6.6.dev, IO 4.7.0dev, PrimGrp 3.4.2, SmallGrp 1.5, 
             TransGrp 3.6.3
 Try '??help' for help. See also '?copyright', '?cite' and '?authors'
gap> > Syntax error: ) expected
�

I will create a PR.

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 a pull request may close this issue.

2 participants