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

error while compiling when a source file starts with a number #259

Open
sdx6 opened this issue May 26, 2024 · 1 comment
Open

error while compiling when a source file starts with a number #259

sdx6 opened this issue May 26, 2024 · 1 comment
Labels

Comments

@sdx6
Copy link

sdx6 commented May 26, 2024

Bug description

i was trying out using Nelua with an 8ball program, and by the end of it named it accordingly, 8ball.nelua, and it threw this compiler error

 [/home/leah/coding/nelua] (18:13:23)
 > nelua 8ball.nelua
/home/leah/.cache/nelua/8ball.c:598:22: error: invalid suffix "ball_responses" on integer constant
  598 | static nlstring_arr9 8ball_responses = {.v = {{(uint8_t*)"Yes.", 4}, {(uint8_t*)"No.", 3}, {(uint8_t*)"Maybe", 5}, {(uint8_t*)"Definitely.", 11}, {(uint8_t*)"Never.", 6}, {(uint8_t*)"Why do you ask...", 17}, {(uint8_t*)"Ew, I'm not responding to that.", 31}, {(uint8_t*)"OMG YES GIRLIE SLAAAAAYYYY", 26}, {(uint8_t*)"um no wHAT ???? DIE STUPID", 26}}};
      |                      ^~~~~~~~~~~~~~~
/home/leah/.cache/nelua/8ball.c:598:22: error: expected identifier or ‘(’ before numeric constant
/home/leah/.cache/nelua/8ball.c: In function ‘nelua_GC_registerroots’:
/home/leah/.cache/nelua/8ball.c:1752:43: error: invalid suffix "ball_responses" on integer constant
 1752 |   nelua_GC_register((&nelua_gc), (void*)(&8ball_responses), 144U, 131072U, (function_24MUm2mhxgB96C1FJ)NULL, (void*)NULL);
      |                                           ^~~~~~~~~~~~~~~
/home/leah/.cache/nelua/8ball.c: In function ‘nelua_main’:
/home/leah/.cache/nelua/8ball.c:2254:1: error: invalid suffix "ball_restart" on integer constant
 2254 | 8ball_restart:;
      | ^~~~~~~~~~~~~
/home/leah/.cache/nelua/8ball.c:2254:14: error: expected ‘;’ before ‘:’ token
 2254 | 8ball_restart:;
      |              ^
      |              ;
/home/leah/.cache/nelua/8ball.c:2259:12: error: invalid suffix "ball_quit" on integer constant
 2259 |       goto 8ball_quit;
      |            ^~~~~~~~~~
/home/leah/.cache/nelua/8ball.c:2259:12: error: expected identifier or ‘*’ before numeric constant
/home/leah/.cache/nelua/8ball.c:2261:19: error: invalid suffix "ball_responses.v" on integer constant
 2261 |     nelua_print_1(8ball_responses.v[nelua_assert_bounds_nlint64(nelua_math_random_1(0, 8), 9)]);
      |                   ^~~~~~~~~~~~~~~~~
/home/leah/.cache/nelua/8ball.c:2262:10: error: invalid suffix "ball_restart" on integer constant
 2262 |     goto 8ball_restart;
      |          ^~~~~~~~~~~~~
/home/leah/.cache/nelua/8ball.c:2262:10: error: expected identifier or ‘*’ before numeric constant
/home/leah/.cache/nelua/8ball.c:2264:1: error: invalid suffix "ball_quit" on integer constant
 2264 | 8ball_quit:;
      | ^~~~~~~~~~
/home/leah/.cache/nelua/8ball.c:2264:11: error: expected ‘;’ before ‘:’ token
 2264 | 8ball_quit:;
      |           ^
      |           ;
error: C compilation for '/home/leah/.cache/nelua/8ball' failed

Code example

no code for example, compiler issue

Expected behavior

the compilation finishes successfully and runs the code

Workaround

if you were to rename the file to eightball.nelua, or something else without a number the compilation will finish successfully

Environment

Nelua 0.2.0-dev
Build number: 1615
Git date: 2024-04-20 09:45:08 -0300
Git hash: 9f75e00
Semantic version: 0.2.0-dev.1615+9f75e009
Copyright (C) 2019-2024 Eduardo Bart (https://nelua.io/)

Linux

x86_64

gcc (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@sdx6 sdx6 added the bug label May 26, 2024
@jrfondren
Copy link

jrfondren commented May 26, 2024

The filename is used as a prefix for generated identifiers, so it has to be an identifier itself. "Has to be", but invalid characters are replaced with X. A simple fix ix probably to have that replacement include leading numerals.

There is a workaround:

## pragmas.unitname = 'eightball'
local function f()
  print 'from 8ball.nelia'
end
f()

This works as it generates eightball_f instead of 8ball_f

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