-
Notifications
You must be signed in to change notification settings - Fork 17
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
Support syntax of global variables #47
Conversation
That’s awesome! I’ll review it tomorrow :) |
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.
Looks good!
Only couple of small changes required
grammar/Matlab.bnf
Outdated
@@ -110,6 +111,8 @@ meta block ::= (<<p>> NEWLINE *)* | |||
private block_that_recovers_until_end ::= <<block element>> { recoverWhile=not_end_or_oef } | |||
private not_end_or_oef ::= !( NEWLINE* ( end | <<eof>> ) ) | |||
|
|||
global_block ::= global br* IDENTIFIER (br* IDENTIFIER)* [',' | sep] { pin=1 } |
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.
Let's rename the rule to global_variable_declaration
Also you do not need [',' | sep]
at the end because this suffix is in element
rule
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 think global_variable_declarations
would be better ('s' on the end)
testData/parser/GlobalVariables.txt
Outdated
PsiElement(IDENTIFIER)('f') | ||
PsiWhiteSpace(' ') | ||
PsiElement(IDENTIFIER)('g') | ||
PsiElement(NEWLINE)('\n') |
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.
Seems like tests should trim extra whitespaces in test data
When I run the test I see that there is no last line PsiElement(NEWLINE)('\n')
, so just remove it (and re-run test to check that it works)
"try if b == 2 c = 3 end end" is valid octave statement. Does it cause error in Matlab? |
Thanks for the feedback! I will try to make all those changes today / tomorrow.
In MATLAB (R2018b at least) I obtain this: Anyway, I guess it is good as it is now if Octave is fine with it. Once I am done, I will also have a look at #48 and see if I can implement it. |
Hi,
I attempted to implement issue #32, while adding test files for it and ensuring syntax highlighting works. I am completely new to lexers and IntelliJ plugins, so feel free to modify / reject this!
While doing this, I have seen that lines such as "global a if b == 2 c = 3 end" do not flag any errors, but I think they should. However, I saw that the same occurs with other keywords, such as "try if b == 2 c = 3 end end". Hence, if this is actually an issue, hopefully it is not directly concerning the global keywords.
Finally, MATLAB would also highlight the global variables in a different color, both when you declare them as global and later every time they are used. Should this behaviour be implemented here as well? I have not checked how this could be done, but I suspect it will have less to do with updating the lexer and more to do with the Kotlin classes.