From 12a01b7cc0fbf2a1f7db61fc5acac779f5da1cbd Mon Sep 17 00:00:00 2001 From: zxj5470 Date: Thu, 31 Jan 2019 17:28:13 +0800 Subject: [PATCH] [ annotator ] enhance --- grammar/julia-grammar.bnf | 21 +-- .../julia/lang/julia-bundle.properties | 4 +- .../julia/lang/editing/julia-annotator.kt | 24 ++- .../julia/lang/editing/julia-completion.kt | 2 +- .../lang/module/julia-language-server.kt | 2 +- .../julia/lang/psi/impl/julia-psi-ext.kt | 13 ++ .../julia/lang/psi/julia-navigation.kt | 34 +++-- testData/parsing/ParseFor.jl | 10 ++ testData/parsing/ParseFor.txt | 140 ++++++++++++++++++ testData/parsing/ParseImport.txt | 5 +- testData/parsing/ParseIssue204.txt | 10 +- testData/parsing/ParseIssue213.txt | 5 +- testData/parsing/ParseIssue255.txt | 22 +-- testData/parsing/ParseIssue312.jl | 13 +- testData/parsing/ParseIssue312.txt | 113 +++++++++++++- testData/parsing/ParseRed.txt | 20 ++- 16 files changed, 379 insertions(+), 59 deletions(-) diff --git a/grammar/julia-grammar.bnf b/grammar/julia-grammar.bnf index f2b47ca7..bdaaaecf 100644 --- a/grammar/julia-grammar.bnf +++ b/grammar/julia-grammar.bnf @@ -225,13 +225,13 @@ expr ::= | assignLevel | arrowOp | ternaryOp + | quoteLevel | lambda | miscArrowsOp | orOp | andOp | comparisonLevelOp | pipeLevelOp - | quoteLevel | plusLevelOp | bitwiseLevel | multiplyLevel @@ -278,12 +278,14 @@ private assignLevel ::= assignOp | assignLevelOp -assignOp ::= expr commaSep? (EQ_SYM | ASSIGN_SYM) endOfLine expr { +assignOp ::= expr commaSep? (EQ_SYM | ASSIGN_SYM) endOfLine statementEvenStupid { rightAssociative=true implements=['com.intellij.psi.PsiNameIdentifierOwner'] mixin='org.ice1000.julia.lang.psi.impl.JuliaAssignOpMixin' } +private statementEvenStupid ::= moduleDeclaration | typeDeclaration | abstractTypeDeclaration | expr + multiAssignOp ::= strictExpressionList commaSep? (EQ_SYM | ASSIGN_SYM) endOfLine expressionList assignLevelOp ::= expr assignLevelOperator endOfLine expressionList { rightAssociative=true } assignLevelOperator ::= @@ -428,18 +430,19 @@ comparisonLevelOperator ::= pipeLevelOperator ::= PIPE_SYM | INVERSE_PIPE_SYM pipeLevelOp ::= expr pipeLevelOperator endOfLine expr +// before lambda private quoteLevel ::= spliceOp - | colonOp +// | colonOp | quoteOp | compoundQuoteOp -colonSymBegins::= COLON_SYM endOfLine LEFT_BRACKET -colonOp ::= expr colonSymBegins expr RIGHT_BRACKET +//colonSymBegins::= COLON_SYM endOfLine LEFT_BRACKET +//colonOp ::= expr colonSymBegins expr RIGHT_BRACKET spliceOp ::= expr SLICE_SYM compoundQuoteOp ::= QUOTE_KEYWORD endOfLine (expr endOfLine)* END_KEYWORD quoteOp ::= COLON_SYM quotable -private allowQuoteSymbols::= DOUBLE_COLON +private allowQuoteSymbols::= DOUBLE_COLON | DOT_SYM | privateOperaSymbols private quotable ::= unaryOpAsSymbol | interpolateAsOp // unbracketed is useless, and idk why @@ -699,8 +702,8 @@ primitiveTypeDeclaration ::= macro ::= MACRO_KEYWORD endOfLine symbol endOfLine - untypedVariables endOfLine - <> + untypedVariables? endOfLine + <>? END_KEYWORD { pin=1 extends=expr @@ -729,7 +732,7 @@ export ::= importAllExpr ::= IMPORTALL_KEYWORD access { pin=1 extends=expr } -private imported ::= access (COLON_SYM endOfLine symbolAndMacroSymbol)? (commaSep access)* +private imported ::= access (COLON_SYM endOfLine access)? (commaSep access)* importExpr ::= IMPORT_KEYWORD endOfLine imported { pin=1 extends=expr } using ::= USING_KEYWORD endOfLine imported { pin=1 extends=expr } diff --git a/res/org/ice1000/julia/lang/julia-bundle.properties b/res/org/ice1000/julia/lang/julia-bundle.properties index 25d79214..6de26c0c 100644 --- a/res/org/ice1000/julia/lang/julia-bundle.properties +++ b/res/org/ice1000/julia/lang/julia-bundle.properties @@ -102,7 +102,9 @@ julia.lint.function-param-hints.show=Show function params hints julia.lint.apply-function-param-hints.show=Show apply function params hints. (unimplemented) julia.lint.version-number.argument-error= ArgumentError: invalid version string: julia.lint.variable.assign-from-nothing.warning=The variable will become nothing. -julia.lint.variable.type-declarations.global-error=type declarations on global variables are not yet supported +julia.lint.variable.assign-to-module-error=ERROR: syntax: "module" expression not at top level. +julia.lint.variable.assign-from-nothing-replace=remove the assignment and just keep the right. +julia.lint.variable.type-declarations.global-error=ERROR: syntax: type declarations on global variables are not yet supported julia.lint.variable.type-declarations.global-error-replace=remove the type annotation julia.modules.type=Julia Module diff --git a/src/org/ice1000/julia/lang/editing/julia-annotator.kt b/src/org/ice1000/julia/lang/editing/julia-annotator.kt index e5b519c5..89ff61b5 100644 --- a/src/org/ice1000/julia/lang/editing/julia-annotator.kt +++ b/src/org/ice1000/julia/lang/editing/julia-annotator.kt @@ -171,9 +171,27 @@ $JULIA_DOC_SURROUNDING JuliaBundle.message("julia.lint.variable.type-declarations.global-error-replace") )) } - val rightElement = element.exprList.lastOrNull() ?: return - if (rightElement is JuliaUsing || rightElement is JuliaImportExpr) { - holder.createWarningAnnotation(element, JuliaBundle.message("julia.lint.variable.assign-from-nothing.warning")) + // element after `=` if stupid! + val leftElement = element.exprList.firstOrNull() + val rightElement = leftElement?.nextRealSibling?.nextRealSibling ?: return + when (rightElement) { + is JuliaUsing, + is JuliaImportExpr, + is IJuliaTypeDeclaration -> + holder + .createWarningAnnotation(element, JuliaBundle.message("julia.lint.variable.assign-from-nothing.warning")) + .registerFix(JuliaReplaceWithTextIntention(element, + rightElement.text, + JuliaBundle.message("julia.lint.variable.assign-from-nothing-replace") + )) + is JuliaModuleDeclaration -> { + holder + .createErrorAnnotation(element, JuliaBundle.message("julia.lint.variable.assign-to-module-error")) + .registerFix(JuliaReplaceWithTextIntention(element, + rightElement.text, + JuliaBundle.message("julia.lint.variable.assign-from-nothing-replace") + )) + } } } diff --git a/src/org/ice1000/julia/lang/editing/julia-completion.kt b/src/org/ice1000/julia/lang/editing/julia-completion.kt index 9100d974..ed120c99 100644 --- a/src/org/ice1000/julia/lang/editing/julia-completion.kt +++ b/src/org/ice1000/julia/lang/editing/julia-completion.kt @@ -237,7 +237,7 @@ class JuliaBasicCompletionContributor : CompletionContributor() { JuliaCompletionProvider(functionInside)) extend(CompletionType.BASIC, psiElement() - .inside(JuliaUsing::class.java), + .inside(JuliaStatements::class.java), JuliaModuleStubCompletionProvider()) } } diff --git a/src/org/ice1000/julia/lang/module/julia-language-server.kt b/src/org/ice1000/julia/lang/module/julia-language-server.kt index cb41c326..7c06412a 100644 --- a/src/org/ice1000/julia/lang/module/julia-language-server.kt +++ b/src/org/ice1000/julia/lang/module/julia-language-server.kt @@ -81,7 +81,7 @@ end // language=Julia val command = """ try - repr(Docs.doc($name)) + repr(@doc $name) catch e println("__INTELLIJ__"*repr(e)) end diff --git a/src/org/ice1000/julia/lang/psi/impl/julia-psi-ext.kt b/src/org/ice1000/julia/lang/psi/impl/julia-psi-ext.kt index 76c8de25..f23817a4 100644 --- a/src/org/ice1000/julia/lang/psi/impl/julia-psi-ext.kt +++ b/src/org/ice1000/julia/lang/psi/impl/julia-psi-ext.kt @@ -51,3 +51,16 @@ val PsiElement.prevRealSibling: PsiElement? } return pre } + +val PsiElement.nextRealSibling: PsiElement? + get() { + var next = this.nextSibling + while (next != null) { + if (next is PsiWhiteSpace) { + next = next.nextSibling + } else { + return next + } + } + return next + } diff --git a/src/org/ice1000/julia/lang/psi/julia-navigation.kt b/src/org/ice1000/julia/lang/psi/julia-navigation.kt index 4debc5da..60b2d7a4 100644 --- a/src/org/ice1000/julia/lang/psi/julia-navigation.kt +++ b/src/org/ice1000/julia/lang/psi/julia-navigation.kt @@ -141,29 +141,39 @@ class JuliaLineMarkerProvider : LineMarkerProvider { if (element is IJuliaSymbol) { when { element.parent is JuliaAbstractTypeDeclaration -> { - val builder = NavigationGutterIconBuilder + return NavigationGutterIconBuilder .create(overridenTypeIcon) .setTooltipText("Please Click name to navigate to Subtypes") .setTarget(element) - return builder.createLineMarkerInfo(element) + .createLineMarkerInfo(element) } + // function Base.+ element.parent is JuliaFunction - && element.prevSibling.elementType == JuliaTypes.DOT_SYM - && element.prevSibling.prevSibling.elementType == JuliaTypes.SYM -> { - val builder = NavigationGutterIconBuilder - .create(overridingIcon) - .setTooltipText("navigate to overrided function. (This feature is still working)") - // TODO stubIndex - .setTarget(element) - return builder.createLineMarkerInfo(element) + && element.prevSibling?.elementType == JuliaTypes.DOT_SYM + && element.prevSibling?.prevSibling?.elementType == JuliaTypes.SYM -> { + val moduleName = element.prevSibling.prevSibling.text + val overridingName = element.text + val modules = JuliaModuleDeclarationIndex.findElementsByName(project, moduleName) + val targets = modules.flatMap { module -> + module.statements?.let { stmt -> + stmt.children.filter { (it is IJuliaFunctionDeclaration) && it.nameIdentifier?.text == overridingName } + } ?: emptyList() + } + return if (targets.isNotEmpty()) { + NavigationGutterIconBuilder + .create(overridingIcon) + .setTooltipText("navigate to overrided function. (This feature is still working)") + .setTargets(targets) + .createLineMarkerInfo(element) + } else null } element.isSuperTypeExpr || element.parent is JuliaType && element.parent.isSuperTypeExpr -> { val target = JuliaTypeDeclarationIndex.findElementsByName(project, element.text) + JuliaAbstractTypeDeclarationIndex.findElementsByName(project, element.text) - val builder = NavigationGutterIconBuilder + return NavigationGutterIconBuilder .create(overridingIcon) .setTooltipText("navigate to overrided type.") .setTargets(target) - return builder.createLineMarkerInfo(element) + .createLineMarkerInfo(element) } } } diff --git a/testData/parsing/ParseFor.jl b/testData/parsing/ParseFor.jl index 234bfb9d..defdf877 100644 --- a/testData/parsing/ParseFor.jl +++ b/testData/parsing/ParseFor.jl @@ -6,3 +6,13 @@ for α ∈ [1, 2, 3, 4] println(β) end)") end + +for j = 1:(i < lc ? 64 : last_chunk_len) + if Imsk & u != 0 + lx < c && throw_setindex_mismatch(X, c) + @inbounds x = convert(Bool, X[c]) + C = ifelse(x, C | u, C & ~u) + c += 1 + end + u <<= 1 + end \ No newline at end of file diff --git a/testData/parsing/ParseFor.txt b/testData/parsing/ParseFor.txt index 9415b11d..9e5dd844 100644 --- a/testData/parsing/ParseFor.txt +++ b/testData/parsing/ParseFor.txt @@ -118,4 +118,144 @@ FILE PsiElement(QUOTE_END)('"') PsiElement(RIGHT_BRACKET)(')') PsiElement(EOL)('\n') + PsiElement(END_KEYWORD)('end') + PsiElement(EOL)('\n\n') + JuliaForExprImpl(FOR_EXPR) + PsiElement(FOR_KEYWORD)('for') + JuliaSingleIndexerImpl(SINGLE_INDEXER) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('j') + PsiElement(EQ_SYM)('=') + JuliaRangeOpImpl(RANGE_OP) + JuliaIntegerImpl(INTEGER) + PsiElement(INT_LITERAL)('1') + PsiElement(COLON_SYM)(':') + JuliaTupleImpl(TUPLE) + PsiElement(LEFT_BRACKET)('(') + JuliaTernaryOpImpl(TERNARY_OP) + JuliaComparisonLevelOpImpl(COMPARISON_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('i') + JuliaComparisonLevelOperatorImpl(COMPARISON_LEVEL_OPERATOR) + PsiElement(LESS_THAN_SYM)('<') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('lc') + PsiElement(QUESTION_SYM)('?') + JuliaRangeOpImpl(RANGE_OP) + JuliaIntegerImpl(INTEGER) + PsiElement(INT_LITERAL)('64') + PsiElement(COLON_SYM)(':') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('last_chunk_len') + PsiElement(RIGHT_BRACKET)(')') + JuliaStatementsImpl(STATEMENTS) + PsiElement(EOL)('\n') + JuliaIfExprImpl(IF_EXPR) + PsiElement(IF_KEYWORD)('if') + JuliaComparisonLevelOpImpl(COMPARISON_LEVEL_OP) + JuliaMultiplyLevelOpImpl(MULTIPLY_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('Imsk') + JuliaMultiplyLevelOperatorImpl(MULTIPLY_LEVEL_OPERATOR) + PsiElement(BITWISE_AND_SYM)('&') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('u') + JuliaComparisonLevelOperatorImpl(COMPARISON_LEVEL_OPERATOR) + PsiElement(UNEQUAL_SYM)('!=') + JuliaIntegerImpl(INTEGER) + PsiElement(INT_LITERAL)('0') + PsiElement(EOL)('\n') + JuliaStatementsImpl(STATEMENTS) + JuliaAndOpImpl(AND_OP) + JuliaComparisonLevelOpImpl(COMPARISON_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('lx') + JuliaComparisonLevelOperatorImpl(COMPARISON_LEVEL_OPERATOR) + PsiElement(LESS_THAN_SYM)('<') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('c') + PsiElement(AND_SYM)('&&') + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('throw_setindex_mismatch') + PsiElement(LEFT_BRACKET)('(') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('X') + PsiElement(COMMA_SYM)(',') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('c') + PsiElement(RIGHT_BRACKET)(')') + PsiElement(EOL)('\n') + JuliaApplyMacroOpImpl(APPLY_MACRO_OP) + JuliaMacroSymbolImpl(MACRO_SYMBOL) + PsiElement(MACRO_SYM)('@inbounds') + JuliaAssignOpImpl(ASSIGN_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('x') + PsiElement(EQ_SYM)('=') + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('convert') + PsiElement(LEFT_BRACKET)('(') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('Bool') + PsiElement(COMMA_SYM)(',') + JuliaApplyIndexOpImpl(APPLY_INDEX_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('X') + PsiElement(LEFT_M_BRACKET)('[') + JuliaExprWrapperImpl(EXPR_WRAPPER) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('c') + PsiElement(RIGHT_M_BRACKET)(']') + PsiElement(RIGHT_BRACKET)(')') + PsiElement(EOL)('\n') + JuliaAssignOpImpl(ASSIGN_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('C') + PsiElement(EQ_SYM)('=') + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('ifelse') + PsiElement(LEFT_BRACKET)('(') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('x') + PsiElement(COMMA_SYM)(',') + JuliaPlusLevelOpImpl(PLUS_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('C') + JuliaPlusLevelOperatorImpl(PLUS_LEVEL_OPERATOR) + PsiElement(BITWISE_OR_SYM)('|') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('u') + PsiElement(COMMA_SYM)(',') + JuliaMultiplyLevelOpImpl(MULTIPLY_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('C') + JuliaMultiplyLevelOperatorImpl(MULTIPLY_LEVEL_OPERATOR) + PsiElement(BITWISE_AND_SYM)('&') + JuliaBitWiseNotOpImpl(BIT_WISE_NOT_OP) + PsiElement(BITWISE_NOT_SYM)('~') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('u') + PsiElement(RIGHT_BRACKET)(')') + PsiElement(EOL)('\n') + JuliaAssignLevelOpImpl(ASSIGN_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('c') + JuliaAssignLevelOperatorImpl(ASSIGN_LEVEL_OPERATOR) + PsiElement(PLUS_ASSIGN_SYM)('+=') + JuliaIntegerImpl(INTEGER) + PsiElement(INT_LITERAL)('1') + PsiElement(EOL)('\n') + PsiElement(END_KEYWORD)('end') + PsiElement(EOL)('\n') + JuliaAssignLevelOpImpl(ASSIGN_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('u') + JuliaAssignLevelOperatorImpl(ASSIGN_LEVEL_OPERATOR) + PsiElement(SHL_ASSIGN_SYM)('<<=') + JuliaIntegerImpl(INTEGER) + PsiElement(INT_LITERAL)('1') + PsiElement(EOL)('\n') PsiElement(END_KEYWORD)('end') \ No newline at end of file diff --git a/testData/parsing/ParseImport.txt b/testData/parsing/ParseImport.txt index 6062a33c..001c66c2 100644 --- a/testData/parsing/ParseImport.txt +++ b/testData/parsing/ParseImport.txt @@ -36,8 +36,9 @@ FILE JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('Base') PsiElement(COLON_SYM)(':') - JuliaSymbolImpl(SYMBOL) - PsiElement(PLUS_SYM)('+') + JuliaMemberAccessImpl(MEMBER_ACCESS) + JuliaOpAsSymbolImpl(OP_AS_SYMBOL) + PsiElement(PLUS_SYM)('+') PsiElement(COMMA_SYM)(',') JuliaMemberAccessImpl(MEMBER_ACCESS) JuliaOpAsSymbolImpl(OP_AS_SYMBOL) diff --git a/testData/parsing/ParseIssue204.txt b/testData/parsing/ParseIssue204.txt index ab175a1a..12cddb74 100644 --- a/testData/parsing/ParseIssue204.txt +++ b/testData/parsing/ParseIssue204.txt @@ -1254,8 +1254,9 @@ FILE JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('Intrinsics') PsiElement(COLON_SYM)(':') - JuliaSymbolImpl(SYMBOL) - PsiElement(SYM)('sle_int') + JuliaMemberAccessImpl(MEMBER_ACCESS) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('sle_int') PsiElement(COMMA_SYM)(',') JuliaMemberAccessImpl(MEMBER_ACCESS) JuliaSymbolImpl(SYMBOL) @@ -1672,8 +1673,9 @@ FILE JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('Intrinsics') PsiElement(COLON_SYM)(':') - JuliaSymbolImpl(SYMBOL) - PsiElement(SYM)('eq_int') + JuliaMemberAccessImpl(MEMBER_ACCESS) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('eq_int') PsiElement(COMMA_SYM)(',') JuliaMemberAccessImpl(MEMBER_ACCESS) JuliaSymbolImpl(SYMBOL) diff --git a/testData/parsing/ParseIssue213.txt b/testData/parsing/ParseIssue213.txt index 164d21a7..b839343b 100644 --- a/testData/parsing/ParseIssue213.txt +++ b/testData/parsing/ParseIssue213.txt @@ -12,8 +12,9 @@ FILE JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('Base') PsiElement(COLON_SYM)(':') - JuliaSymbolImpl(SYMBOL) - PsiElement(MULTIPLY_SYM)('*') + JuliaMemberAccessImpl(MEMBER_ACCESS) + JuliaOpAsSymbolImpl(OP_AS_SYMBOL) + PsiElement(MULTIPLY_SYM)('*') PsiElement(COMMA_SYM)(',') JuliaMemberAccessImpl(MEMBER_ACCESS) JuliaOpAsSymbolImpl(OP_AS_SYMBOL) diff --git a/testData/parsing/ParseIssue255.txt b/testData/parsing/ParseIssue255.txt index ec10811a..365db42d 100644 --- a/testData/parsing/ParseIssue255.txt +++ b/testData/parsing/ParseIssue255.txt @@ -400,20 +400,20 @@ FILE JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('i') PsiElement(IN_KEYWORD)('in') - JuliaColonOpImpl(COLON_OP) + JuliaRangeOpImpl(RANGE_OP) JuliaIntegerImpl(INTEGER) PsiElement(INT_LITERAL)('2') - JuliaColonSymBeginsImpl(COLON_SYM_BEGINS) - PsiElement(COLON_SYM)(':') + PsiElement(COLON_SYM)(':') + JuliaTupleImpl(TUPLE) PsiElement(LEFT_BRACKET)('(') - JuliaPlusLevelOpImpl(PLUS_LEVEL_OP) - JuliaSymbolImpl(SYMBOL) - PsiElement(SYM)('n') - JuliaPlusLevelOperatorImpl(PLUS_LEVEL_OPERATOR) - PsiElement(MINUS_SYM)('-') - JuliaIntegerImpl(INTEGER) - PsiElement(INT_LITERAL)('1') - PsiElement(RIGHT_BRACKET)(')') + JuliaPlusLevelOpImpl(PLUS_LEVEL_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('n') + JuliaPlusLevelOperatorImpl(PLUS_LEVEL_OPERATOR) + PsiElement(MINUS_SYM)('-') + JuliaIntegerImpl(INTEGER) + PsiElement(INT_LITERAL)('1') + PsiElement(RIGHT_BRACKET)(')') JuliaStatementsImpl(STATEMENTS) PsiElement(EOL)('\n') JuliaAssignOpImpl(ASSIGN_OP) diff --git a/testData/parsing/ParseIssue312.jl b/testData/parsing/ParseIssue312.jl index 749b0c73..ac2b6434 100644 --- a/testData/parsing/ParseIssue312.jl +++ b/testData/parsing/ParseIssue312.jl @@ -1,4 +1,15 @@ (+, -, *, /) (-, +, /, *) (*, -, /, +) -(^, -, +, /) \ No newline at end of file +(^, -, +, /) + +if isexpr(x, :.) + emmm +end +if isexpr(ex, :->) && length(ex.args) > 1 + return docm(source, mod, ex.args...) +else + # TODO: this is a shim to continue to allow `@doc` for looking up docstrings + REPL = Base.REPL_MODULE_REF[] + return REPL.lookup_doc(ex) +end \ No newline at end of file diff --git a/testData/parsing/ParseIssue312.txt b/testData/parsing/ParseIssue312.txt index b9901c6a..24009e34 100644 --- a/testData/parsing/ParseIssue312.txt +++ b/testData/parsing/ParseIssue312.txt @@ -58,4 +58,115 @@ FILE PsiElement(COMMA_SYM)(',') JuliaSymbolImpl(SYMBOL) PsiElement(DIVIDE_SYM)('/') - PsiElement(RIGHT_BRACKET)(')') \ No newline at end of file + PsiElement(RIGHT_BRACKET)(')') + PsiElement(EOL)('\n\n') + JuliaIfExprImpl(IF_EXPR) + PsiElement(IF_KEYWORD)('if') + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('isexpr') + PsiElement(LEFT_BRACKET)('(') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('x') + PsiElement(COMMA_SYM)(',') + JuliaQuoteOpImpl(QUOTE_OP) + PsiElement(COLON_SYM)(':') + PsiElement(DOT_SYM)('.') + PsiElement(RIGHT_BRACKET)(')') + PsiElement(EOL)('\n') + JuliaStatementsImpl(STATEMENTS) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('emmm') + PsiElement(EOL)('\n') + PsiElement(END_KEYWORD)('end') + PsiElement(EOL)('\n') + JuliaIfExprImpl(IF_EXPR) + PsiElement(IF_KEYWORD)('if') + JuliaAndOpImpl(AND_OP) + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('isexpr') + PsiElement(LEFT_BRACKET)('(') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('ex') + PsiElement(COMMA_SYM)(',') + JuliaQuoteOpImpl(QUOTE_OP) + PsiElement(COLON_SYM)(':') + PsiElement(LAMBDA_ABSTRACTION)('->') + PsiElement(RIGHT_BRACKET)(')') + PsiElement(AND_SYM)('&&') + JuliaComparisonLevelOpImpl(COMPARISON_LEVEL_OP) + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('length') + PsiElement(LEFT_BRACKET)('(') + JuliaMemberAccessOpImpl(MEMBER_ACCESS_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('ex') + PsiElement(DOT_SYM)('.') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('args') + PsiElement(RIGHT_BRACKET)(')') + JuliaComparisonLevelOperatorImpl(COMPARISON_LEVEL_OPERATOR) + PsiElement(GREATER_THAN_SYM)('>') + JuliaIntegerImpl(INTEGER) + PsiElement(INT_LITERAL)('1') + PsiElement(EOL)('\n') + JuliaStatementsImpl(STATEMENTS) + JuliaReturnExprImpl(RETURN_EXPR) + PsiElement(RETURN_KEYWORD)('return') + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('docm') + PsiElement(LEFT_BRACKET)('(') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('source') + PsiElement(COMMA_SYM)(',') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('mod') + PsiElement(COMMA_SYM)(',') + JuliaSpliceOpImpl(SPLICE_OP) + JuliaMemberAccessOpImpl(MEMBER_ACCESS_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('ex') + PsiElement(DOT_SYM)('.') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('args') + PsiElement(SLICE_SYM)('...') + PsiElement(RIGHT_BRACKET)(')') + PsiElement(EOL)('\n') + JuliaElseClauseImpl(ELSE_CLAUSE) + PsiElement(ELSE_KEYWORD)('else') + JuliaStatementsImpl(STATEMENTS) + PsiElement(EOL)('\n') + PsiComment(LINE_COMMENT)('# TODO: this is a shim to continue to allow `@doc` for looking up docstrings') + PsiElement(EOL)('\n') + JuliaAssignOpImpl(ASSIGN_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('REPL') + PsiElement(EQ_SYM)('=') + JuliaMemberAccessOpImpl(MEMBER_ACCESS_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('Base') + PsiElement(DOT_SYM)('.') + JuliaArrayImpl(ARRAY) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('REPL_MODULE_REF') + PsiElement(LEFT_M_BRACKET)('[') + PsiElement(RIGHT_M_BRACKET)(']') + PsiElement(EOL)('\n') + JuliaReturnExprImpl(RETURN_EXPR) + PsiElement(RETURN_KEYWORD)('return') + JuliaMemberAccessOpImpl(MEMBER_ACCESS_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('REPL') + PsiElement(DOT_SYM)('.') + JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('lookup_doc') + PsiElement(LEFT_BRACKET)('(') + JuliaSymbolImpl(SYMBOL) + PsiElement(SYM)('ex') + PsiElement(RIGHT_BRACKET)(')') + PsiElement(EOL)('\n') + PsiElement(END_KEYWORD)('end') \ No newline at end of file diff --git a/testData/parsing/ParseRed.txt b/testData/parsing/ParseRed.txt index 98cdb0f7..f11ea992 100644 --- a/testData/parsing/ParseRed.txt +++ b/testData/parsing/ParseRed.txt @@ -13,8 +13,7 @@ FILE PsiElement(COMMA_SYM)(',') JuliaQuoteOpImpl(QUOTE_OP) PsiElement(COLON_SYM)(':') - JuliaOpAsSymbolImpl(OP_AS_SYMBOL) - PsiElement(SUBTYPE_SYM)('<:') + PsiElement(SUBTYPE_SYM)('<:') PsiElement(COMMA_SYM)(',') JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('r') @@ -27,8 +26,7 @@ FILE JuliaQuoteOpImpl(QUOTE_OP) PsiElement(COLON_SYM)(':') PsiElement(LEFT_BRACKET)('(') - JuliaOpAsSymbolImpl(OP_AS_SYMBOL) - PsiElement(SUBTYPE_SYM)('<:') + PsiElement(SUBTYPE_SYM)('<:') PsiElement(RIGHT_BRACKET)(')') PsiElement(EOL)('\n\n') JuliaApplyFunctionOpImpl(APPLY_FUNCTION_OP) @@ -44,8 +42,7 @@ FILE PsiElement(COMMA_SYM)(',') JuliaQuoteOpImpl(QUOTE_OP) PsiElement(COLON_SYM)(':') - JuliaOpAsSymbolImpl(OP_AS_SYMBOL) - PsiElement(SUPERTYPE_SYM)('>:') + PsiElement(SUPERTYPE_SYM)('>:') PsiElement(COMMA_SYM)(',') JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('r') @@ -597,10 +594,11 @@ FILE JuliaSymbolImpl(SYMBOL) PsiElement(SYM)('toolz') PsiElement(COLON_SYM)(':') - JuliaSymbolImpl(SYMBOL) - PsiElement(LEFT_BRACKET)('(') - PsiElement(INTERPOLATE_SYM)('$') - PsiElement(RIGHT_BRACKET)(')') + JuliaMemberAccessImpl(MEMBER_ACCESS) + JuliaOpAsSymbolImpl(OP_AS_SYMBOL) + PsiElement(LEFT_BRACKET)('(') + PsiElement(INTERPOLATE_SYM)('$') + PsiElement(RIGHT_BRACKET)(')') PsiElement(EOL)('\n\n') JuliaAssignOpImpl(ASSIGN_OP) JuliaSymbolImpl(SYMBOL) @@ -924,7 +922,7 @@ FILE PsiElement(LEFT_BRACKET)('(') JuliaUnaryInterpolateOpImpl(UNARY_INTERPOLATE_OP) PsiElement(INTERPOLATE_SYM)('$') - PsiErrorElement:, , , , , , , AND_SYM, BLOCK_COMMENT_START, COLON_SYM, COMMA_SYM, DOUBLE_COLON, EOL, EQ_SYM, FOR_KEYWORD, IMPLICIT_MULTIPLY_SYM, LAMBDA_ABSTRACTION, LEFT_BRACKET, LEFT_B_BRACKET, LINE_COMMENT, MULTIPLY_SYM, OR_SYM or SLICE_SYM expected, got ',' + PsiErrorElement:, , , , , , , AND_SYM, BLOCK_COMMENT_START, COMMA_SYM, DOUBLE_COLON, EOL, EQ_SYM, FOR_KEYWORD, IMPLICIT_MULTIPLY_SYM, LAMBDA_ABSTRACTION, LEFT_BRACKET, LEFT_B_BRACKET, LINE_COMMENT, MULTIPLY_SYM, OR_SYM or SLICE_SYM expected, got ',' PsiElement(COMMA_SYM)(',') JuliaNotOpImpl(NOT_OP)