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

Add loose parse. #533

Closed
wants to merge 1 commit into from
Closed

Add loose parse. #533

wants to merge 1 commit into from

Conversation

jdalton
Copy link
Contributor

@jdalton jdalton commented Mar 30, 2017

Addresses #532. This PR is a start. It could use a test too.


parse() {
let node = this.options.program || this.startNode()
this.next()
Copy link
Contributor Author

@jdalton jdalton Mar 30, 2017

Choose a reason for hiding this comment

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

I noticed in the default parser the call is this.nextToken() but I saw that parse_dammit uses this.next().
I'm not sure which is best.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I believe they're different in parser/loose parser, but not completely sure as almost didn't touch the loose one. @marijnh should know better.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the loose parse class has a next method, which wraps the regular tokenizer with some error-correcting magic.

I think you should just move the body from parse_dammit into this method (which I guess you did) and have parse_dammit call it, to avoid duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed some other differences between loose and strict. The default Parser constructor accepts options, input but the LooseParser accepts input, options.

@@ -41,9 +41,7 @@ defaultOptions.tabSize = 4

// eslint-disable-next-line camelcase
export function parse_dammit(input, options) {
let p = new LooseParser(input, options)
p.next()
return p.parseTopLevel()
Copy link
Contributor Author

@jdalton jdalton Apr 4, 2017

Choose a reason for hiding this comment

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

Interesting that before it didn't pass a node to parseTopLevel but to align with the strict parse I went ahead and did that too. I also used const instead of let (though the Parser equiv should use const too).

Copy link
Member

Choose a reason for hiding this comment

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

parseTopLevel doesn't take an argument. To clarify, these are completely different classes. A loose parser has a regular parser, but doesn't inherit from it.

Copy link
Contributor Author

@jdalton jdalton Apr 4, 2017

Choose a reason for hiding this comment

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

Updated to remove the node use. I think it'd be beneficial if their APIs aligned a bit more. It seems kind of odd for them to be different in little ways here and there.

Copy link
Member

Choose a reason for hiding this comment

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

They often do different things, and have different constraints. I don't think aligning methods is much of priority.

Copy link
Contributor Author

@jdalton jdalton Apr 4, 2017

Choose a reason for hiding this comment

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

You do see how having two methods named parseTopLevel that do two different things, with different argument signatures, is kind of confusing though, right?

@jdalton
Copy link
Contributor Author

jdalton commented Apr 13, 2017

Updated.

@marijnh
Copy link
Member

marijnh commented Apr 14, 2017

Great, merged as 9dbcf60

@marijnh marijnh closed this Apr 14, 2017
@jdalton jdalton deleted the loose-parse branch April 14, 2017 05:40
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.

3 participants