diff --git a/grammar/Matlab.bnf b/grammar/Matlab.bnf index ec3b349..f9fa077 100644 --- a/grammar/Matlab.bnf +++ b/grammar/Matlab.bnf @@ -98,6 +98,7 @@ private element ::= ( el [ ';' | ',' ] ) | ';' | ',' private el ::= if_block | switch_block | try_block + | global_variable_declarations | file_operation | for_loop | while_loop @@ -110,6 +111,8 @@ meta block ::= (<

> NEWLINE *)* private block_that_recovers_until_end ::= <> { recoverWhile=not_end_or_oef } private not_end_or_oef ::= !( NEWLINE* ( end | <> ) ) +global_variable_declarations ::= global br* IDENTIFIER (br* IDENTIFIER)* { pin=1 } + if_block ::= if br* condition ','? NEWLINE* if_block_body NEWLINE* elseif_block* NEWLINE* diff --git a/grammar/MatlabLexer.flex b/grammar/MatlabLexer.flex index ad124f7..27ad538 100644 --- a/grammar/MatlabLexer.flex +++ b/grammar/MatlabLexer.flex @@ -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; } diff --git a/src/com/github/korniloval/matlab/MatlabSyntaxHighlighter.kt b/src/com/github/korniloval/matlab/MatlabSyntaxHighlighter.kt index c08dc8a..5c81e40 100644 --- a/src/com/github/korniloval/matlab/MatlabSyntaxHighlighter.kt +++ b/src/com/github/korniloval/matlab/MatlabSyntaxHighlighter.kt @@ -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 diff --git a/testData/parser/GlobalVariables.m b/testData/parser/GlobalVariables.m new file mode 100644 index 0000000..686117f --- /dev/null +++ b/testData/parser/GlobalVariables.m @@ -0,0 +1,5 @@ +global a b c; + +global d ... + e ... + f g diff --git a/testData/parser/GlobalVariables.txt b/testData/parser/GlobalVariables.txt new file mode 100644 index 0000000..ddbe210 --- /dev/null +++ b/testData/parser/GlobalVariables.txt @@ -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') \ No newline at end of file diff --git a/tests/com/github/korniloval/matlab/parser/MatlabParserTest.kt b/tests/com/github/korniloval/matlab/parser/MatlabParserTest.kt index 55b8cda..77c4f7e 100644 --- a/tests/com/github/korniloval/matlab/parser/MatlabParserTest.kt +++ b/tests/com/github/korniloval/matlab/parser/MatlabParserTest.kt @@ -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()