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

Cleanup the ParseTree hierarchy and open its functions #194

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

lppedd
Copy link
Contributor

@lppedd lppedd commented Aug 24, 2024

For the historical reason that RuleContext.parent wasn't marked with @JvmField, the two original Java getParent() and setParent() functions had to be renamed to readParent() and assignParent() to avoid a collission with the JVM-generated getter and setter for the parent property.

This change encapsulates the parent field into the RuleContext hierarchy - marking it with @JvmField and hiding it from the outer world - and renames the get/set functions to their original names.

ParserRuleContext's functions have also been opened.

Copy link
Member

@ftomassetti ftomassetti left a comment

Choose a reason for hiding this comment

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

Minor comments added

val start = this.start
val stop = this.stop

if (start != null && stop != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we could write this as `if (start != null && stop?.endPoint() != null) {

Copy link
Contributor Author

@lppedd lppedd Aug 30, 2024

Choose a reason for hiding this comment

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

Nope, because you'd have to assign the result of stop?.endPoint() to a variable x anyway, to assert x != null to be able to pass it to Position(start.startPoint(), x). So stop?.endPoint() != null is a redundant call to endPoint().

Another argument for calling startPoint() and endPoint() only once is they're functions, and the result may vary between invocations.

/**
* If we are debugging or building a parse tree for a visitor,
* we need to track all the tokens and rule invocations associated
* with this rule's context. This is empty for parsing w/o tree constr.
* operation because we don't have the need to track the details about
* how we parse this rule.
*/
@JvmField
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to make this a JvmField? Do we want the outside world to be able to set the field directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, the outside world was able to set that property anyway, even without @JvmField. The difference is without the annotation a getter, a setter, and a backing private field would be generated. With the annotation we only have the public backing field.

Applying @JvmField aligns the code with the Java runtime.

// The original condition was 'currentNode != null',
// but since nodeStack.removeFirst() throws if there
// is no element, the condition is always true
} while (true)
Copy link
Member

Choose a reason for hiding this comment

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

Good comment!

@ftomassetti ftomassetti merged commit b56322f into Strumenta:master Sep 2, 2024
6 checks passed
@ftomassetti
Copy link
Member

This one has been merged. Should we release 1.0.0 ?

@lppedd
Copy link
Contributor Author

lppedd commented Sep 2, 2024

@ftomassetti I'd like to make the identity map and weak map internal, as consumers should not use them. 1 hour and I'll open the PR.

@lppedd lppedd deleted the refactor/parsetree branch September 2, 2024 12:50
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