teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.12k stars 107 forks source link

Using reserved keyword in record field #746

Closed devmaars closed 4 months ago

devmaars commented 4 months ago

Hi, i was asking myself, if my record i want to use a keyword that teal grammar already use, how can i escape ? in lua for example we can use string encapsulation

local t = {}
t.end = 200 --- Error
t["end"] = 200 --- work

So here come record data type

local record MemoryRegion
    state: integer
    start: integer
    end: integer --- error
    type: integer --- no error even tho type is a defined function in lua/teal
    name: string
    internalName: string
end

So my question is how can i use a reserved keyword in a record ? is there a way to escape string ?

hishamhm commented 4 months ago

You can do it just like Lua table declarations.

local record MemoryRegion
    state: integer
    start: integer
    ["end"]: integer
    type: integer
    name: string
    internalName: string
end

Like in Lua tables, only Lua keywords need this kind of "escaping". Keywords added by Teal (e.g. record, global, etc.) are "soft keywords", so they do not require escaping.

devmaars commented 4 months ago

Thanks, seem working but it make the vscode go crazy image

hishamhm commented 4 months ago

Thanks for the feedback!

@devmaars does it report an error message?

@pdesaulniers any idea on the vscode-teal issue above?

devmaars commented 4 months ago

No there is no error, just the color that become all green. I have also tried disabling all my extensions to ensure that it is vs code teal, causing the color issue

pdesaulniers commented 1 month ago

@devmaars The syntax highlighting issue should be fixed in vscode-teal v0.10.0. Bracket notation was not supported inside record declarations.

2024-08-25-10:44:38