GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [lua] Support Luau, a gradually typed language based on Lua by matthargett · Pull Request #4066 · pmd/pmd

Conversation

@matthargett

@matthargett matthargett commented Jul 26, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Describe the PR

Support Luau, which is an overlay on top of Lua 5.x that shouldn't introduce any ambiguity with legacy codebases.
Tested against ~200KLOC of OSS Lua code (comments in file), and 450KLOC of private Lua code. I added a new test file and snapshot that captures the scenarios in the aforementioned corpus' that found bugs in my grammar modifications.

CPD now analyzes all of the StyLua and full-moon test suites without errors, except for intentional abuses cases that involve unterminated strings. 🎉

This also adds in the Java CPD feature to skip imports (require statements in Lua's case), the repetitive boilerplate for which can get in the way of lowering the duplication threshold for logic.

Additionally, the Lua tokenizer now supports the C# CPD feature to skip literals and literal sequences, so that non-behavioral data tables (arrays of constants for cryptography, translation string tables, etc) can be removed so the duplicate threshold can be further lowered for actual behavioral code.

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oltrep, ZoteTheMighty, and hmallen99 reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
matthargett added 4 commits July 25, 2022 21:43
@matthargett
Initial Lua type grammar
65fef39
@matthargett
Support all Luau type extension syntax available in all test corpus s…
8aaa130
…ources. Add a regression test for a few of the things that required tweaks.
@matthargett
Capture more syntax scenarios in the regression test, update the snap…
cfb8374
…shot.
@matthargett
rename new snapshot artifact to better express intent
3d6fab0
@ghost

ghost commented Jul 26, 2022

Copy link
Copy Markdown
1 Message
📖 No regression tested rules have been changed.

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala
oowekyala reviewed Jul 27, 2022
View reviewed changes

@oowekyala oowekyala left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Hi and thanks for the contribution!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pmd-lua/src/test/resources/net/sourceforge/pmd/lang/lua/cpd/testdata/luauTypes.txt Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-lua/src/test/resources/net/sourceforge/pmd/lang/lua/cpd/testdata/luauTypes.txt Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-lua/src/test/resources/net/sourceforge/pmd/lang/lua/cpd/testdata/luauTypes.txt Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pmd-lua/src/main/antlr4/net/sourceforge/pmd/lang/lua/antlr4/Lua.g4 Resolved

Uh oh!

There was an error while loading. Please reload this page.

@matthargett

matthargett commented Jul 27, 2022

Copy link
Copy Markdown
Contributor Author

Hi and thanks for the contribution!

You're welcome! I noticed I need to consistently format the grammar with the original coding style. I'll do that today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala oowekyala added the in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception label Jul 28, 2022
@matthargett

matthargett commented Jul 29, 2022

Copy link
Copy Markdown
Contributor Author

Just a heads up that I'm going to be on vacation for 2 weeks. I'll put this PR in draft until I'm back, then fold in the feedback. Thanks!!

adangel reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala
oowekyala marked this pull request as draft August 11, 2022 17:10
@matthargett
Merge branch 'master' of github.com:pmd/pmd into lua-types
ba77fa1
matthargett referenced this pull request in antlr/grammars-v4 Aug 14, 2022
@matthargett
Fortify Lua grammar to fix parse issue when certain quotation charact…
ff6ef1e
…ers are used in comments and multiline strings.
matthargett added 2 commits September 7, 2022 17:00
@matthargett
Merge branch 'master' of github.com:pmd/pmd into lua-types
c59ee1d
@matthargett
Move rules from lexer to parser. Fix some bugs found in manual testin…
0260159
…g. Add bugs found via manual testing to new lua test file.
@matthargett
matthargett marked this pull request as ready for review September 8, 2022 02:30
@matthargett

matthargett commented Sep 8, 2022

Copy link
Copy Markdown
Contributor Author

Just a few more cleanups, from my perspective, but let me know if there's additional feedback!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

matthargett added 4 commits September 7, 2022 19:37
@matthargett
add an if-expression twist
7cf9c65
@matthargett
Cleanups and minor tweaks for issues found in testing across 500KLOC …
7747b75
…of open source Lua code.
@matthargett
Support multi-line 'normal' strings. Support skipping literal sequenc…
b8b4e51
…es. More minor adjustments to make the testing corpus tokenize without errors.
@matthargett
Format to have more consistent style with itself. Most other files ap…
7d9a84f
…pear to have mixed formatting.
@matthargett
matthargett requested a review from oowekyala September 9, 2022 23:51
@matthargett
Merge branch 'master' of github.com:pmd/pmd into lua-types
6b16581
@matthargett

matthargett commented Sep 13, 2022

Copy link
Copy Markdown
Contributor Author

@adangel I'm not sure the build timeout that causes CI to fail is relate to my changes, but I can't re-run the job. Can you review and debug from your side? Thanks! :D

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

matthargett added 3 commits September 13, 2022 21:58
@matthargett
remove unused param
936cbaf
@matthargett
fix incorrect comments
f7a5f9c
@matthargett
Update documentation and changelog
05c30a1
@matthargett matthargett changed the title Support typed Lua [lua] Support Luau, a gradually typed language based on Lua Sep 14, 2022
@matthargett

matthargett commented Sep 14, 2022

Copy link
Copy Markdown
Contributor Author

@adangel I finally won the dice roll with the maven server being overloaded. Would it be possible for this PR to be included in 6.50 release?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel
adangel self-requested a review September 15, 2022 18:51
@adangel

adangel commented Sep 15, 2022

Copy link
Copy Markdown
Member

@matthargett Thanks for the update! I'll try to review it next week - having it in 6.50.0 shouldn't be a problem.

matthargett reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel
[lua] Fix parsing of short/long comments
dcd8ff0
@adangel adangel added this to the 6.50.0 milestone Sep 24, 2022
@adangel
[lua] Fixups from pmd#4066
746fcbf
adangel
adangel approved these changes Sep 24, 2022
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks!

I'm fixing the remaining parts when I merge your PR.

Note: I'm also fixing are parsing issue around comments, mentioned here (antlr/grammars-v4@ff6ef1e#r84475967). Keep this in mind when updating the grammar back in https://github.com/antlr/grammars-v4/tree/master/lua

One general comment: The grammar now supports both "original" Lua and Luau. This is OK for PMD, where we can be less strict when parsing. But if the upstream grammar is used to verify "original" Lua code and one expects to fail parsing invalid Lua code (but valid Luau), that expectation is now not true anymore. Maybe a separate grammar is better - but it always depends on the use case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

matthargett reacted with thumbs up emoji matthargett reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction
Comment thread pmd-lua/src/main/antlr4/net/sourceforge/pmd/lang/lua/antlr4/Lua.g4 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/pages/release_notes.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel
Add missing test files
4d63003
@adangel
adangel merged commit ea2f4fb into pmd:master Sep 24, 2022
@matthargett

matthargett commented Sep 26, 2022

Copy link
Copy Markdown
Contributor Author

Note: I'm also fixing are parsing issue around comments, mentioned here (antlr/grammars-v4@ff6ef1e#r84475967). Keep this in mind when updating the grammar back in https://github.com/antlr/grammars-v4/tree/master/lua

Thanks! I saw that person's comment and was meaning to circle back and debug. It's funny, issues with ' and " in comments was one of the issues I fixed in my first PR!

One general comment: The grammar now supports both "original" Lua and Luau. This is OK for PMD, where we can be less strict when parsing. But if the upstream grammar is used to verify "original" Lua code and one expects to fail parsing invalid Lua code (but valid Luau), that expectation is now not true anymore. Maybe a separate grammar is better - but it always depends on the use case.

Agreed. Here, I tried to see if a superset approach would work across all the OSS-available variants (Lua 5.x, Luau, WoW Lua, and LuaJIT) and strved to ensure they all had representation in the OSS testing corpus (linked in the comment header of the file). It looks like everything works when running CPD across those many repos and 400+KLOC (and my additional private 300+KLOC), but it's feasible that someone (a human, not a fuzzing tool) could write new code that would cause issues. If that happens, I'm happy to split the grammar into whatever discrete pieces are helpful for that new use case.

Until then, having a usable duplication checker is an enormous leap forward for teams that are scaling engineer operations around Lua (whatever variant or runtime) -- in either headcount or KLOC dimensions (or both!).

Thanks again for the assist!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@matthargett
matthargett deleted the lua-types branch September 26, 2022 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes
@oowekyala oowekyala Awaiting requested review from oowekyala

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

in:grammar About the grammar of a lexer or parser, eg, a parse/lex exception

Projects

None yet

Milestone

6.50.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@matthargett @adangel @oowekyala
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.