edubart / nelua-lang

Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
https://nelua.io
MIT License
2k stars 62 forks source link

Bug when closing parethesis is placed in new line for ## print() #115

Closed stefanos82 closed 3 years ago

stefanos82 commented 3 years ago

Bug description

When I place the closing parenthesis of ## print() in a new line, it breaks.

t.nelua:8:1: syntax error: unexpected syntax
)
^

shell returned 1

I'm trying to print the type(s) of nested records and caused a bug by mistake.

Code example

Provide minimal reproduction code to test the bug. Please, format the code properly and try to keep it as simple as possible, just focusing on the experienced bug.

require 'string'

local A = @record{}
global A.B = @record{ x: integer}

## print(string.format("A.type: '%s'\nA.value.metafields.B: '%s'", A.type, A.value.metafields.B))

The problematic code looks like this:

require 'string'

local A = @record{}
global A.B = @record{ x: integer}

## print(
    string.format("A.type: '%s'\nA.value.metafields.B: '%s'", A.type, A.value.metafields.B)
)

Expected behavior

It should print

A.type: 'type'
A.value.metafields.B: 'A.B: type = A.B'

Workaround

If you have already found a way to workaround the issue, then please share how you did it, this may help others with the same issue.

Environment

Provide relevant information about your environment:

codehz commented 3 years ago

I think it is expected. you need to use ##[[ ]] syntax for multiline preprocess

stefanos82 commented 3 years ago

Indeed; good catch @codehz

Andre-LA commented 3 years ago

Indeed, however it doesn't need the ## at the end, just ##[[ ]] works¹, it follows the same rules as comments actually, so ##[==[ ]==] can be used to avoid some [[ ]] conflict²:

¹ https://nelua.io/overview/#preprocessor ² https://nelua.io/overview/#preprocessor-code-blocks