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

Updated the translator to use gsub("%S", "") instead of `gsub("%S",… #303

Merged
merged 1 commit into from
Aug 7, 2020

Conversation

itssamuelrowe
Copy link
Contributor

… " ")`

Fixes issue #277. If we remove the non-whitespace characters instead of simply replacing them with
spaces it produces a more pleasant-looking output. For example,

function f(x: integer)

becomes

function (x)

instead of

function f(x         )

Column numbers are not be preserved but line numbers are. This is okay because Lua error messages
do not show column numbers, they only show line numbers.

@itssamuelrowe itssamuelrowe self-assigned this Aug 6, 2020
@itssamuelrowe itssamuelrowe added the enhancement New feature or request label Aug 6, 2020
Copy link
Member

@hugomg hugomg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the examples, the only weird thing is that there is a lack of space before the =.
We could also treat specially. If the first character after the region is a = and the last character in the region is a space, then preserve that space.

pallene/translator.lua Outdated Show resolved Hide resolved
pallene/translator.lua Outdated Show resolved Hide resolved
pallene/translator.lua Outdated Show resolved Hide resolved
-- Remove the type annotation but exclude the next token.
self:add_whitespace(decl.type.loc.pos, decl.end_loc.pos - 1)
-- self:add_whitespace(decl.type.loc.pos, decl.end_loc.pos - 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 comments are now outdated. We could just remove them.

… " ")`

Fixes issue #277. If we remove the non-whitespace characters instead of simply replacing them with
spaces it produces a more pleasant-looking output. For example,

```
function f(x: integer)
```

becomes

```
function (x)
```

instead of

```
function f(x         )
```

Column numbers are not be preserved but line numbers are. This is okay because Lua error messages
do not show column numbers, they only show line numbers.
Copy link
Member

@hugomg hugomg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants