-
Notifications
You must be signed in to change notification settings - Fork 354
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
Add toml parser #4678
base: main
Are you sure you want to change the base?
Add toml parser #4678
Conversation
Dropping this here as well, since Steven and I are collaborating in parallel on the effort trying different things here and there. This PR will serve as the final source to be contributed for TOML support. |
Related to #4400. A future PR will take the work done here and integrate it with the rewrite-gradle module. |
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.
Nice to see work on the TOML parser! I added a few small comments.
rewrite-toml/src/main/java/org/openrewrite/toml/internal/TomlParserVisitor.java
Outdated
Show resolved
Hide resolved
* <p>The default implementation returns the result of calling | ||
* {@link #visitChildren} on {@code ctx}.</p> | ||
*/ | ||
@Override public T visitArray_values(TomlParser.Array_valuesContext ctx) { return visitChildren(ctx); } |
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.
Our ANTLR grammars typically use camel case as that then also yields nicer Java identifiers out-of-the-box.
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.
That's definitely fair. This was just pulled directly from https://github.com/antlr/grammars-v4/tree/master/toml.
Do you recall if future syncs with the upstream just usually remake those particular kinds of adjustments for other language bindings? This was the thought running through my head as to why I hadn't mentioned the same thing to Steve.
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.
In my experience these grammars are hardly ever updated and quite often also contain small bugs, so I wouldn't worry too much. If we ever need to fix a bug we can still look at the history of the upstream grammar.
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.
@knutwannheden Do you just want the methods in TomlParserBaseVisitor to be camel case? Or do you also want all the types/methods in TomlParser (also generated by ANTLR)
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.
@steplica, Knut is meaning to update the ANTLR grammar to remove the underscores there which then translates throughout the rest of the code as well.
68cfe5f
to
d525683
Compare
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.
Some suggestions could not be made:
- rewrite-toml/src/main/java/org/openrewrite/toml/tree/TomlContainer.java
- lines 123-124
- rewrite-toml/src/main/java/org/openrewrite/toml/tree/TomlLeftPadded.java
- lines 38-39
- rewrite-toml/src/main/java/org/openrewrite/toml/tree/TomlRightPadded.java
- lines 100-101
Space after = visitSpace(right.getAfter(), p); | ||
return (after == right.getAfter() && t == right.getElement()) ? right : new TomlRightPadded<>(t, after, right.getMarkers()); | ||
} | ||
} |
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.
} | |
} |
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); | ||
} | ||
} | ||
} |
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.
} | |
} |
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); | ||
} | ||
} | ||
} |
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.
} | |
} |
* <p>The default implementation does nothing.</p> | ||
*/ | ||
@Override public void visitErrorNode(ErrorNode node) { } | ||
} |
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.
} | |
} |
* {@link #visitChildren} on {@code ctx}.</p> | ||
*/ | ||
@Override public T visitArrayTable(TomlParser.Array_tableContext ctx) { return visitChildren(ctx); } | ||
} |
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.
} | |
} |
|
||
@Test | ||
void Table_With_SuperTable_Declared_After_Dotted_Table() { | ||
rewriteRun(toml(""" |
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.
rewriteRun(toml(""" | |
rewriteRun(toml( | |
""" |
|
||
@Test | ||
void Table_With_SubTable_Added_Later() { | ||
rewriteRun(toml(""" |
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.
rewriteRun(toml(""" | |
rewriteRun(toml( | |
""" |
|
||
@Test | ||
void InlineTable() { | ||
rewriteRun(toml(""" |
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.
rewriteRun(toml(""" | |
rewriteRun(toml( | |
""" |
|
||
@Test | ||
void ArrayOfTables() { | ||
rewriteRun(toml(""" |
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.
rewriteRun(toml(""" | |
rewriteRun(toml( | |
""" |
rewriteRun(toml(""" | ||
[[fruits]] |
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.
rewriteRun(toml(""" | |
[[fruits]] | |
rewriteRun(toml( | |
""" |
What's changed?
What's your motivation?
Anything in particular you'd like reviewers to focus on?
Anyone you would like to review specifically?
Have you considered any alternatives or workarounds?
Any additional context
Checklist