8000 Preserve comments during lexing by upedd · Pull Request #1002 · teal-language/tl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Preserve comments during lexing #1002

8000 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

Merged
merged 4 commits into from
Jun 4, 2025
Merged

Conversation

upedd
Copy link
Contributor
@upedd upedd commented Jun 4, 2025

Part of tealdoc project. Stores comments inside of comments field of Token. Always attaches comments to the leading token.

Copy link
github-actions bot commented Jun 4, 2025

Teal Playground URL: https://1002--teal-playground-preview.netlify.app

@@ -6,6 +6,30 @@ local function string_trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end

--- removes leading whitespace from every line of a multiline string
local function dedent(s)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of copying them around, you can add those utility functions to spec/util.lua, then localize them at the top with local dedent = util.dedent for brevity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

spec/util.lua Outdated
end

for i, line in ipairs(lines) do
lines[i] = line:gsub("^" .. string.rep(" ", min), "")
Copy link
Member

Choose a reason for hiding this comment

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

to strip the first min characters (which you already determined are whitespace), you can just do:

Suggested change
lines[i] = line:gsub("^" .. string.rep(" ", min), "")
lines[i] = line:sub(min + 1)

Also, weird edge case but: if s was something like "\n", wouldn't min end up staying as math.huge? Perhaps an if min == math.huge them min = 0 end before the loop should be in order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Should've caught that, sorry.

Copy link
Member

Choose a reason for hiding this comment

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

It happens! "Who watches tests the Watchmen test code?" :)

end

if min == math.huge then
return s
Copy link
Member

Choose a reason for hiding this comment

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

Better solution! 👍

@hishamhm hishamhm merged commit 1be547d into teal-language:master Jun 4, 2025
3 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0