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

Adds Parser APIs in Java and allows for parsing multiple statements #1634

Merged
merged 12 commits into from
Nov 1, 2024

Conversation

johnedquinn
Copy link
Member

@johnedquinn johnedquinn commented Oct 30, 2024

Relevant Issues

Description

  • Adds Parser APIs in Java
  • Allows for parsing multiple statements
  • Updates SourceLocations to be in Java. Utilizes the SourceLocation class from SPI.
  • PartiQLParser.Result no longer contains the input string -- this didn't make any sense.
  • PartiQLParser now contains the Builder as a nested class, Lombok style

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@johnedquinn johnedquinn marked this pull request as ready for review October 30, 2024 20:30
Replaces all internal parse() invocations with parseSingle()
Comment on lines 23 to 33
public class PartiQLParserBuilder {

public fun build(): PartiQLParser {
return PartiQLParserDefault()
/**
* TODO
* @return TODO
*/
@NotNull
public PartiQLParser build() {
return new PartiQLParserDefault();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Remove this class?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this is part of the follow-up that @alancai98 will be undertaking for removing the older parser.

Comment on lines 49 to 76
/**
* TODO
* @param source TODO
* @param ctx TODO
* @return TODO
* @throws PErrorListenerException TODO
* @see PartiQLParserV1#parse(String, Context)
*/
@NotNull
default Result parseSingle(@NotNull String source, @NotNull Context ctx) throws PErrorListenerException {
Result result = parse(source, ctx);
if (result.statements.size() != 1) {
SourceLocation location;
if (result.statements.size() > 1) {
location = result.locations.get(result.statements.get(1).tag);
} else {
location = null;
}
Map<String, Object> properties = new HashMap<String, Object>() {{
put("EXPECTED_TOKENS", new ArrayList<String>() {{
add("EOF");
}});
}};
PError pError = new PError(PError.UNEXPECTED_TOKEN, Severity.ERROR(), PErrorKind.SYNTAX(), location, properties);
ctx.getErrorListener().report(pError);
}
return result;
}
Copy link
Member

Choose a reason for hiding this comment

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

Parse single doesn't make sense actually with the result. That was a bad suggestion on my part (:

Let me know your thoughts, but removing this seems fine.

@johnedquinn johnedquinn merged commit 8b5cc65 into partiql:v1 Nov 1, 2024
7 checks passed
@johnedquinn johnedquinn deleted the v1-parser-java branch November 1, 2024 18:56
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