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

Puppet syntax broken in a number of contexts #979

Closed
alex-harvey-z3q opened this issue Sep 3, 2018 · 7 comments
Closed

Puppet syntax broken in a number of contexts #979

alex-harvey-z3q opened this issue Sep 3, 2018 · 7 comments

Comments

@alex-harvey-z3q
Copy link
Contributor

alex-harvey-z3q commented Sep 3, 2018

I am using the Rouge gem in my Jekyll on Github blog and have found a number of issues with the Puppet syntax highlighter.

(I can see from the revision history that it hasn't really been changed since 2013, so at least some of the problems would be that it lacks Puppet >= 4 syntax support.)

Issue 1 (note the red equals sign), example 1:

screen shot 2018-09-03 at 9 48 07 pm

Issue 1, example 2:

screen shot 2018-09-03 at 9 52 41 pm

Issue 2:

screen shot 2018-09-03 at 9 50 27 pm

These are from two posts online here and here.

@alex-harvey-z3q
Copy link
Contributor Author

Geoff Williams wrote in the Puppet Community Slack:

@alex Just had a quick look at that library. Seems that the lexer for puppet goes to rule /[$]#{qualname}/, Name::Variable, I tried to find the definition of Name::Variable and closest I got was https://github.com/sinatra/mustermann/blob/master/mustermann/lib/mustermann/ast/compiler.rb I'd guess Name::Variable doesn't match Puppet's idea of a regex, although the library does seem to support hashes. What if you try assigning a hash with only one level, or an array, or just a simple variable? Could be that the regex used just doesn't support n-level nesting?

@alex-harvey-z3q
Copy link
Contributor Author

@jneen if you could give me a clue what might be wrong I'd be happy to try to work on a fix. I did have a look but I can't get my head around the code. E.g. where does Name::Variable get defined?

@dblessing
Copy link
Collaborator

dblessing commented Sep 3, 2018 via email

@jneen
Copy link
Member

jneen commented Sep 3, 2018

If you're curious where it's defined, it's in lib/rouge/token.rb. But as @dblessing already mentioned, it's nothing more than a fancy symbol - the type of tokens that are variables.

You can try running

rougify -L debug=1 -f null my_file.pp

to get a debug trace of the lex. (-L debug=1 sets debugging on, and -f null uses the "null" formatter, which suppresses normal output.)

alex-harvey-z3q added a commit to alex-harvey-z3q/rouge that referenced this issue Sep 4, 2018
The = sign had been missed apparently as a valid Puppet operator.
Fixes rouge-ruby#979.
@alex-harvey-z3q
Copy link
Contributor Author

Weirdly enough the lexer simply wasn't recognising the = sign as an Operator. Fixed:

Example 1
screen shot 2018-09-04 at 7 59 44 pm

Example 2
screen shot 2018-09-04 at 8 00 22 pm

Example 3
screen shot 2018-09-04 at 8 00 53 pm

@alex-harvey-z3q
Copy link
Contributor Author

@jneen I raised a PR to fix it above. How long will it take for the fix to propagate to Jekyll on Github?

@dblessing
Copy link
Collaborator

dblessing commented Sep 4, 2018 via email

alex-harvey-z3q added a commit to alex-harvey-z3q/rouge that referenced this issue Sep 4, 2018
The = sign had been missed apparently as a valid Puppet operator. Also
adds tests. Fixes rouge-ruby#979.
alex-harvey-z3q added a commit to alex-harvey-z3q/rouge that referenced this issue Sep 4, 2018
The = sign had been missed apparently as a valid Puppet operator. Also
adds tests. Fixes rouge-ruby#979.
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

No branches or pull requests

3 participants