ceu-lang / ceu

The Programming Language Céu

Home Page:http://www.ceu-lang.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Special string "#N" confuses the parser

rodrimc opened this issue · comments

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.

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;