Skip to content

Parse Comments line by line #168

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

Merged
merged 2 commits into from
Aug 23, 2018
Merged

Conversation

stasm
Copy link
Contributor

@stasm stasm commented Aug 22, 2018

Spin-off from #160; the Comment part.

Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

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

This one I like.

There's a bit of a naming/AST-ishness thing, though. The relationship between the CommentLine, the used-to-be abstract baseclass BaseComment and the "no BaseComment in the AST".

I'd love to see a comment somewhere. Maybe this is something to add to spec/valid.md? Like, an AST with a BaseComment would be illegal? But also, we make 'em illegal and then fix 'em up.

Some human readable "comment lines of the same comment type are aggregated", and "Comments preceding a Message or Term without blank line are removed from the resource, and added to that Message or Term". I really don't know where to best put it, in grammar.mjs->fluent.ebnf, in abstract.mjs, or in spec/valid.md.

Slightly derailing, I wonder if there's a better way to pass non-public Nodes from the CST to AST generation? I toyed with the indention part, and had a similar urge for an Indent node in ast.mjs, and felt dirty about that. Would using PatternElement have been fine?

@Pike Pike mentioned this pull request Aug 22, 2018
@stasm
Copy link
Contributor Author

stasm commented Aug 23, 2018

I'd love to see a comment somewhere. Maybe this is something to add to spec/valid.md? Like, an AST with a BaseComment would be illegal? But also, we make 'em illegal and then fix 'em up.]

I don't want to create too many assumptions about the AST. Some languages will need to slightly diverge from it to be able to implement Fluent. Right now, ast.mjs is not normative; it's more of a guideline.

I think we could standardize the JSON-serialized version of the AST. This would be useful for transporting data between implementations. Abstract classes like BaseComment and PatternElement would not be part of it, however.

Some human readable "comment lines of the same comment type are aggregated", and "Comments preceding a Message or Term without blank line are removed from the resource, and added to that Message or Term". I really don't know where to best put it, in grammar.mjs->fluent.ebnf, in abstract.mjs, or in spec/valid.md.

I'll add /* */ comments in grammar.mjs. They will be exported to the EBNF, too.

Slightly derailing, I wonder if there's a better way to pass non-public Nodes from the CST to AST generation? I toyed with the indention part, and had a similar urge for an Indent node in ast.mjs, and felt dirty about that. Would using PatternElement have been fine?

Yeah, perhaps! I used BaseComment as a means to "tag" the output of the CommentLine parser. You could use PatternElement to do the same. Or, just pass the raw indent (not wrapped in any {type, value} object) into the code in abstract.mjs. The fact that it's not an AST node can also be used to discriminate it.

@stasm
Copy link
Contributor Author

stasm commented Aug 23, 2018

Yeah, perhaps! I used BaseComment as a means to "tag" the output of the CommentLine parser. You could use PatternElement to do the same. Or, just pass the raw indent (not wrapped in any {type, value} object) into the code in abstract.mjs. The fact that it's not an AST node can also be used to discriminate it.

One more thing. The way I used BaseComment in the first comment, I didn't create an instance of it at any time. It's literally just for the purpose of matching the right case of a switch. I could have used any other value which is valid in a case comparison, like a string.

I'm not familiar with your exact use-case, but if you feel the need to temporarily store the indent as a node in the AST and then do something with it during a construction of another node, then we should look at the code and figure out if PatternElement is the right tool for it :)

In the second commit of this PR I dropped BaseComment in favor of a regular Comment.

@stasm stasm requested a review from Pike August 23, 2018 08:59
Copy link
Contributor

@Pike Pike left a comment

Choose a reason for hiding this comment

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

Thanks. r=me.

@stasm stasm merged commit 4f861fd into projectfluent:master Aug 23, 2018
@stasm stasm deleted the comment-by-line branch August 23, 2018 09:46
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