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 JSP (Java Server Pages) lexer #915

Merged
merged 1 commit into from
Aug 10, 2018

Conversation

miparnisari
Copy link
Contributor

@miparnisari miparnisari commented May 20, 2018

Tested with close to 300 JSP files 😄
image

image

@miparnisari miparnisari changed the title Add JSP lexer (Java Server Pages) Add JSP lexer May 20, 2018
@miparnisari miparnisari changed the title Add JSP lexer Add JSP (Java Server Pages) lexer May 20, 2018
Copy link
Collaborator

@dblessing dblessing left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @miparnisari. I have some style comments but otherwise looks good.

@@ -0,0 +1,116 @@
# -*- coding: utf-8 -*- #

module Rouge
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please change all indenting to 2 spaces.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, I'm not sure why Rubocop didn't complain. I'll investigate that later.

rule(/<\/[a-zA-Z]*:[a-zA-Z]*/) { token Name::Tag; push :jsp_tag_end }

rule(/<%[!=]?/) { token Name::Tag; push :jsp_expression2 }
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer the non-block argument style in the cases above: rule(/.../), Name::Tag, :jsp_directive is equivalent to rule(/.../) { token Name::Tag; push :jsp_directive }.

Also, be consistent with use of parentheses throughout the file - rule /.../ or rule(/.../).

Copy link
Member

Choose a reason for hiding this comment

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

the parentheses are required in these cases?

Copy link
Member

Choose a reason for hiding this comment

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

but yes, the non-block style would be better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Derp, thanks.


state :jsp_expression do
rule(/<\/jsp:(#{actions.join('|')})>/) { token Name::Tag; pop! }
rule(/[^<\/]+/) { delegate @java }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although there's technically nothing wrong with this syntax, let's stick to do ... end style blocks. I don't see this style used anywhere else in the code so let's stay consistent.

Copy link
Member

Choose a reason for hiding this comment

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

??? i use this style all the time...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, yep. I see it now. Don't know why I wasn't finding these examples earlier.

@dblessing dblessing added the author-action The PR has been reviewed but action by the author is needed label Jun 13, 2018
@jneen
Copy link
Member

jneen commented Jun 13, 2018

For template languages like this, it is more appropriate to delegate to the parent language than to subclass it (see other template lexers like ERB for example), since the templating system acts as a preprocessor before the html syntax is interpreted.

@dblessing
Copy link
Collaborator

Thanks for pointing out the ERB example @jneen. That looks nice and clean. @miparnisari Can you take a look, please, and see how that might work?

@miparnisari
Copy link
Contributor Author

Thanks @jneen and @dblessing ! I'll have a look at the ERB example later.

@miparnisari
Copy link
Contributor Author

@jneen @dblessing i've updated the lexer to subclass it from TemplateLexer.

@dblessing
Copy link
Collaborator

Thanks @miparnisari I'll review shortly.

Copy link
Collaborator

@dblessing dblessing left a comment

Choose a reason for hiding this comment

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

This is really great @miparnisari Thank you. Also, thank you for updating the CHANGELOG, although now it falls in the wrong spot. Would you mind removing that, or if you'd like you can create a section for the next release. But I can also do that along with other changes. Hopefully I have this automated in the future.

Also, if you're able, please squash the commits into one logical commit. This is not a huge issue and if you have trouble with it, that's OK.

@miparnisari
Copy link
Contributor Author

Both done.

@dblessing dblessing merged commit c063aea into rouge-ruby:master Aug 10, 2018
@miparnisari
Copy link
Contributor Author

Any chance of releasing this soon in version 3.2.2? @dblessing

@miparnisari miparnisari mentioned this pull request Sep 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author-action The PR has been reviewed but action by the author is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants