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

Special string "#N" confuses the parser #117

Open
rodrimc opened this issue Mar 23, 2018 · 1 comment
Open

Special string "#N" confuses the parser #117

rodrimc opened this issue Mar 23, 2018 · 1 comment
Labels

Comments

@rodrimc
Copy link
Contributor

rodrimc commented Mar 23, 2018

The compilation of the following code fails:

 native/pre do                                                                   
 ##include <stdio.h>                                                             
 end                                                                             
                                                                                 
 native/pure                                                                     
   _printf,                                                                      
 ;                                                                               
                                                                                 
 _printf ("#0\n");
 escape 0; 

backtrace:

lua5.3: /usr/local/bin/ceu:2896: bad argument #1 to 'gsub' (string expected, got boolean)
stack traceback:
	[C]: in function 'string.gsub'
	/usr/local/bin/ceu:2896: in function </usr/local/bin/ceu:2894>
	[C]: in function 'lpeg.match'
	/usr/local/bin/ceu:2905: in main chunk
	[C]: in ?

Version: 2d28f15

As far as I could check, this bug actually happens when using the following pattern within the printf:

"#N\C"

where N is any number and C is any character.

@fsantanna fsantanna added the bug label Mar 23, 2018
@fsantanna fsantanna changed the title Special string within printf breaks the compilation Special string "#N" confuses the parser Mar 23, 2018
fsantanna added a commit that referenced this issue Mar 23, 2018
@fsantanna
Copy link
Collaborator

fsantanna commented Mar 23, 2018

The pattern #N is a preprocessor directive to change the current line.
The parser of Céu relies on these directives for error messages.
However, it does not implement a proper lexer to distinguish, for example, when they are inside strings.

The parser crash is fixed but the behavior is still wrong.
In the example below the assert will point to line 99 when it should be 6:

native/pre do
    void f (char* str) {}
end
native _f;
_f("#99\n");
{ceu_assert(0,"err");}
escape 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants