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

Pascal detection rules are too keen #1866

Closed
jamespwilliams opened this issue Sep 1, 2022 · 3 comments · Fixed by #1898
Closed

Pascal detection rules are too keen #1866

jamespwilliams opened this issue Sep 1, 2022 · 3 comments · Fixed by #1898
Assignees
Labels
bugfix-request A request for a bugfix to be developed.

Comments

@jamespwilliams
Copy link

jamespwilliams commented Sep 1, 2022

Name of the lexer
Pascal

Code sample

class a {
    $test = 'var'
}

I can't provide a useful code sample link, because this is a filetype detection bug, not a highlighting bug.

Additional context

The problem is that the disambiguation rules for Pascal are too keen to decide in favour of Pascal when determining whether a file is Pascal or not. The code above is Puppet, which also uses the .pp filetype. Since #1845, Rouge decides that any file containing var is Pascal: https://github.com/tancnle/rouge/blob/master/lib/rouge/guessers/disambiguation.rb#L136. This causes a lot of conflicts, because var is a common FHS component, so pops up in Puppet code very frequently.

Looking for \bvar\s instead of \bvar\b would reduce a lot of false positives, while still being the same semantically - Pascal var keywords have to be followed by a space, from what I can tell. Another approach, which could be used in combination, would be to add a disambiguation rule that declares a file Puppet if it sees a :: - a very common feature of Puppet code, but a rare feature of Pascal (I think - I'm not a Pascal writer).

@jamespwilliams jamespwilliams added the bugfix-request A request for a bugfix to be developed. label Sep 1, 2022
@jamespwilliams
Copy link
Author

http://pirate.shu.edu/~wachsmut/Teaching/CSAS1111/Notes-Pascal/pascal1.html suggests Pascal programs begin with PROGRAM. If that is indeed a rule, that could be a useful disambiguation rule. Someone with more Pascal experience may be able to weigh in here.

@jamespwilliams jamespwilliams changed the title Pascal lexer detection rules are too keen Pascal detection rules are too keen Sep 1, 2022
@tancnle
Copy link
Collaborator

tancnle commented Sep 4, 2022

Thanks for reporting the issue @jamespwilliams 👍🏼 I think it is a fair assessment regarding var. PROGRAM might not be applicable to free pascal. I would propose to:

  • Drop the var keyword or enforce the following space
  • Add disambiguation rule for Puppet, rocket => and class definition foo::bar

What do you think @jamespwilliams @Alexey-T?

@jamespwilliams
Copy link
Author

Sounds good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix-request A request for a bugfix to be developed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants