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

Support syntax of global variables #47

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions grammar/Matlab.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private element ::= ( el [ ';' | ',' ] ) | ';' | ','
private el ::= if_block
| switch_block
| try_block
| global_variable_declarations
| file_operation
| for_loop
| while_loop
Expand All @@ -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_variable_declarations ::= global br* IDENTIFIER (br* IDENTIFIER)* { pin=1 }

if_block ::= if br* condition ','? NEWLINE*
if_block_body NEWLINE*
elseif_block* NEWLINE*
Expand Down
1 change: 1 addition & 0 deletions grammar/MatlabLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ SINGLE_QUOTE_EXCAPE_SEQUENCE=\\[\\bfnrt]|''
otherwise { stopLookForCtrans(); return OTHERWISE; }
try { stopLookForCtrans(); return TRY; }
catch { stopLookForCtrans(); return CATCH; }
global { stopLookForCtrans(); return GLOBAL; }
load/" "+[^ (] { stopLookForCtrans(); yypushState(FILE_NAME_STATE); return LOAD; }
dir/" "+[^ (] { stopLookForCtrans(); yypushState(FILE_NAME_STATE); return DIR; }
ls/" "+[^ (] { stopLookForCtrans(); yypushState(FILE_NAME_STATE); return LS; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MatlabSyntaxHighlighter : SyntaxHighlighterBase() {
MatlabTypes.IDENTIFIER -> ID_KEYS

FUNCTION, END, IF, ELSE, ELSEIF, WHILE, SWITCH, CASE, OTHERWISE,
FOR, CLASSDEF, TRY, CATCH
FOR, CLASSDEF, TRY, CATCH, GLOBAL
-> KEYWORD_KEYS

INTEGER, FLOAT, FLOAT_EXPONENTIAL -> NUMBER_KEYS
Expand Down
5 changes: 5 additions & 0 deletions testData/parser/GlobalVariables.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global a b c;

global d ...
e ...
f g
28 changes: 28 additions & 0 deletions testData/parser/GlobalVariables.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Matlab File
MatlabGlobalVariableDeclarationsImpl(GLOBAL_VARIABLE_DECLARATIONS)
PsiElement(global)('global')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('b')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('c')
PsiElement(;)(';')
PsiElement(NEWLINE)('\n')
PsiElement(NEWLINE)('\n')
MatlabGlobalVariableDeclarationsImpl(GLOBAL_VARIABLE_DECLARATIONS)
PsiElement(global)('global')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('d')
PsiWhiteSpace(' ')
PsiElement(...)('...')
PsiElement(NEWLINE)('\n')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('e')
PsiWhiteSpace(' ')
PsiElement(...)('...')
PsiElement(NEWLINE)('\n')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('f')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('g')
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ open class MatlabParserTest : ParsingTestCase("", "m", MatlabParserDefinition())
fun testFileOperations() = doTest()
fun testWhileLoop() = doTest()
fun testForLoop() = doTest()
fun testGlobalVariables() = doTest()
fun testIf() = doTest()
fun testFunctionCall() = doTest()
fun testFunctionDeclaration() = doTest()
Expand Down