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
else|break|next|repeat|in as Name.Function instead of Name #2087
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this changes the output, you have to regenerate the tests for these languages with, e.g., pytest --update-goldens tests/examplefiles/splus
.
@@ -89,7 +89,7 @@ class SLexer(RegexLexer): | |||
(r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation), | |||
], | |||
'keywords': [ | |||
(r'(if|else|for|while|repeat|in|next|break|return|switch|function)' | |||
(r'(if|for|while|return|switch|function)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused. This rule is apparently broken, since include('valid_name')
comes before include('keywords')
in the 'statements'
state. Do you really want to highlight these as functions and not as keywords? How about simply moving include('valid_name')
after include('keywords')
? Could you explain the reason why else
, repeat
etc. are different from if
, for
, etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been looking at the R specification and it does claim that things like "break" are indeed functions in https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Flow-control-elements, but, in other sections they're considered keywords:
- https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Looping
- https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Reserved-words
I'm inclined to not change them to Function
because they seem quite different from actual functions like mean
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to not change them to Function because they seem quite different from actual functions like mean etc.
library(highr) ## in the R console
highr:::cmd_latex
cmd1 cmd2
COMMENT \hlcom{ }
FUNCTION \hlkwa{ }
IF \hlkwa{ }
ELSE \hlkwa{ }
WHILE \hlkwa{ }
FOR \hlkwa{ }
IN \hlkwa{ }
BREAK \hlkwa{ }
REPEAT \hlkwa{ }
NEXT \hlkwa{ }
NULL_CONST \hlkwa{ }
LEFT_ASSIGN \hlkwb{ }
The same highlighting LaTeX command
\hlkwa{ ... }
is used for FUNCTION as for ELSE, BREAK, NEXT, IN, REPEAT
But in SLexer ("r.py") actually highlight only function names (if followed by '(' evidently), not the keyword 'break', 'else' etc.
(except when they are followed by '(' - which is correct, but not usual; we write "for i in 1:5", not "for i in() 1:5")
--vladbazon
> why else, repeat etc. are different from if, for, etc.
In R 'else' is a function, but it is not called with "else()" but simply
"else" (without final '(', as recognized by Keyword.Reserved)
for(i in 1:10) {
if(i < 3) next # or, next() - which will be then a Keyword.Reserved
print(i)
if(i >= 5) break # or, break()
}
For another example, instead of
repeat({ ### here, 'repeat' will be Keyword.Reserved
# commands
})
is normally written:
repeat{ ### here, 'repeat' will be a 'Name' token (and with my
modification, a 'Name.Function' -- which is desired)
# commands
}
In SLexer ("r.py") we modified:
'root': [
# calls:
*(r'\b(else|next|break|repeat|in)\b', Name.Function),*
(r'(%s)\s*(?=\()' % valid_name, Name.Function),
include('statements'),### ...
],
reducing Keyword.Reserved (without 'else', 'repeat' etc.)
'keywords': [
(r'(if|for|while|return|switch|function)'
r'(?![\w.])',
Keyword.Reserved),
],
vladbazon
…On Sun, Mar 13, 2022 at 2:49 PM Jean Abou-Samra ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pygments/lexers/r.py
<#2087 (comment)>:
> @@ -89,7 +89,7 @@ class SLexer(RegexLexer):
(r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation),
],
'keywords': [
- (r'(if|else|for|while|repeat|in|next|break|return|switch|function)'
+ (r'(if|for|while|return|switch|function)'
I am confused. This rule is apparently broken, since include('valid_name')
comes before include('keywords') in the 'statements' state. Do you really
want to highlight these as functions and not as keywords? How about simply
moving include('valid_name') after include('keywords')? Could you explain
the reason why else, repeat etc. are different from if, for, etc.?
—
Reply to this email directly, view it on GitHub
<#2087 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACKDSLWI5LNDYQHYWAIYETU7XP63ANCNFSM5QTETOUA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
@Leonel020681 That's our CI workflow definition. Not sure what you mean by copying it in your comment? |
@jean-abou-samra Probably a bot/spam |
No description provided.