ayecue / miniscript-vs

VSCode extension for MiniScript.
https://marketplace.visualstudio.com/items?itemName=ayecue.miniscript-vs
MIT License
3 stars 0 forks source link

Transpiler bug: conflict with comments #53

Closed Xisec closed 2 months ago

Xisec commented 2 months ago

Tried to build this code

_eol = char(13)
_hexDigitMap = {}
for i in range(0,15)
    if i < 10 then
        _hexDigitMap[str(i)] = i
    else
        _hexDigitMap[char(55+i)] = i    // (lowercase hex digit)
        _hexDigitMap[char(87+i)] = i    // (uppercase hex digit)
    end if
end for

_escapeFrom = ["\\", """", char(8), char(9), char(10), char(12), char(13)]
_escapeTo = ["\\", "\""", "\b","\t","\n","\f","\r"]
_escapeIndexes = _escapeFrom.indexes

With the following wrong results:

_eol = char(13)
_hexDigitMap = {}
for i in range(0, 15)
    if i < 10 then
        _hexDigitMap[str(i)] = i
    else
        _hexDigitMap[char(55 + i) // (lowercase hex digit)] = i <--- wrong brackets closure
        _hexDigitMap[char(87 + i) // (uppercase hex digit)] = i <--- wrong brackets closure
    end if
end for

_escapeFrom = [
    "\\",
    """",
    char(8),
    char(9),
    char(10),
    char(12),
    char(13), <--- wrong comma
]
_escapeTo = [
    "\\",
    "\""",
    "\b",
    "\t",
    "\n",
    "\f",
    "\r", <--- wrong comma
]
_escapeIndexes = _escapeFrom.indexes

The problem solver if I move the "// (uppercase hex digit)]" comments out of the conflict line (up or down)

ayecue commented 2 months ago

Hey @Xisec,

thanks for reporting. Sorry that it took a bit of time to address the issue. I had to essentially refactor parts of the transformer.

The issue related to the comment should be fixed now with version 0.7.0. The example:

_eol = char(13)
_hexDigitMap = {}
for i in range(0, 15)
    if i < 10 then
        _hexDigitMap[str(i)] = i
    else
        _hexDigitMap[char(55 + i) // (lowercase hex digit)] = i <--- wrong brackets closure
        _hexDigitMap[char(87 + i) // (uppercase hex digit)] = i <--- wrong brackets closure
    end if
end for

should now result into

_eol = char(13)
_hexDigitMap = {}
for i in range(0, 15)
    if i < 10 then
        _hexDigitMap[str(i)] = i
    else
        _hexDigitMap[char(55 + i)] = i // (lowercase hex digit)
        _hexDigitMap[char(87 + i)] = i // (uppercase hex digit)
    end if
end for

Regarding your second report:

_escapeFrom = [
    "\\",
    """",
    char(8),
    char(9),
    char(10),
    char(12),
    char(13), <--- wrong comma
]

Unfortunately that is by design since MiniScript does not allow multiline arrays without tailing commas unless you would write:

test = [
    "\\",
    """",
    char(8),
    char(9),
    char(10),
    char(12),
    char(13)]

which wouldn't look too nice IMO.

ayecue commented 2 months ago

Also a hint since you're building the code. I recommend for building to use either default or uglify since beautify is usually an option you would use in development phase. I for example only use the beautifying via the formatter which you can activate in your VSCode settings by for example activating format on save.

ayecue commented 2 months ago

Closing issue for now. In case you're still experiencing issues feel free to reopen this issue.