Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
f9294411
Commit
f9294411
authored
6 years ago
by
alexey.afanasiev
Browse files
Options
Download
Email Patches
Plain Diff
[groovy] refactor named argument grammar
parent
7e8d2891
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
plugins/groovy/groovy-psi/gen/org/jetbrains/plugins/groovy/lang/parser/GroovyGeneratedParser.java
+60
-4
...ins/plugins/groovy/lang/parser/GroovyGeneratedParser.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/groovy.bnf
+13
-2
...i/src/org/jetbrains/plugins/groovy/lang/parser/groovy.bnf
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/parserUtils.kt
+1
-24
...c/org/jetbrains/plugins/groovy/lang/parser/parserUtils.kt
with
74 additions
and
30 deletions
+74
-30
plugins/groovy/groovy-psi/gen/org/jetbrains/plugins/groovy/lang/parser/GroovyGeneratedParser.java
+
60
-
4
View file @
f9294411
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// This is a generated file. Not intended for manual editing.
package
org.jetbrains.plugins.groovy.lang.parser
;
...
...
@@ -961,14 +963,43 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
}
/* ********************************************************** */
// spread_list_argument | named_argument |
<<parseE
xpression
OrMapArgument expression>>
// spread_list_argument | named_argument |
e
xpression
(map_argument_label map_argument)?
static
boolean
argument
(
PsiBuilder
b
,
int
l
)
{
if
(!
recursion_guard_
(
b
,
l
,
"argument"
))
return
false
;
boolean
r
;
Marker
m
=
enter_section_
(
b
);
r
=
spread_list_argument
(
b
,
l
+
1
);
if
(!
r
)
r
=
named_argument
(
b
,
l
+
1
);
if
(!
r
)
r
=
parseExpressionOrMapArgument
(
b
,
l
+
1
,
expression_parser_
);
if
(!
r
)
r
=
argument_2
(
b
,
l
+
1
);
exit_section_
(
b
,
m
,
null
,
r
);
return
r
;
}
// expression (map_argument_label map_argument)?
private
static
boolean
argument_2
(
PsiBuilder
b
,
int
l
)
{
if
(!
recursion_guard_
(
b
,
l
,
"argument_2"
))
return
false
;
boolean
r
;
Marker
m
=
enter_section_
(
b
);
r
=
expression
(
b
,
l
+
1
,
-
1
);
r
=
r
&&
argument_2_1
(
b
,
l
+
1
);
exit_section_
(
b
,
m
,
null
,
r
);
return
r
;
}
// (map_argument_label map_argument)?
private
static
boolean
argument_2_1
(
PsiBuilder
b
,
int
l
)
{
if
(!
recursion_guard_
(
b
,
l
,
"argument_2_1"
))
return
false
;
argument_2_1_0
(
b
,
l
+
1
);
return
true
;
}
// map_argument_label map_argument
private
static
boolean
argument_2_1_0
(
PsiBuilder
b
,
int
l
)
{
if
(!
recursion_guard_
(
b
,
l
,
"argument_2_1_0"
))
return
false
;
boolean
r
;
Marker
m
=
enter_section_
(
b
);
r
=
map_argument_label
(
b
,
l
+
1
);
r
=
r
&&
map_argument
(
b
,
l
+
1
);
exit_section_
(
b
,
m
,
null
,
r
);
return
r
;
}
...
...
@@ -978,7 +1009,7 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
public
static
boolean
argument_label
(
PsiBuilder
b
,
int
l
)
{
if
(!
recursion_guard_
(
b
,
l
,
"argument_label"
))
return
false
;
boolean
r
;
Marker
m
=
enter_section_
(
b
,
l
,
_
NON
E_
,
ARGUMENT_LABEL
,
"<argument label>"
);
Marker
m
=
enter_section_
(
b
,
l
,
_
COLLAPS
E_
,
ARGUMENT_LABEL
,
"<argument label>"
);
r
=
consumeTokenFast
(
b
,
IDENTIFIER
);
if
(!
r
)
r
=
string_literal_tokens
(
b
,
l
+
1
);
if
(!
r
)
r
=
parsePrimitiveType
(
b
,
l
+
1
);
...
...
@@ -4306,6 +4337,32 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
return
r
||
p
;
}
/* ********************************************************** */
// ':' expression
public
static
boolean
map_argument
(
PsiBuilder
b
,
int
l
)
{
if
(!
recursion_guard_
(
b
,
l
,
"map_argument"
))
return
false
;
if
(!
nextTokenIsFast
(
b
,
T_COLON
))
return
false
;
boolean
r
,
p
;
Marker
m
=
enter_section_
(
b
,
l
,
_LEFT_
,
NAMED_ARGUMENT
,
null
);
r
=
consumeTokenFast
(
b
,
T_COLON
);
p
=
r
;
// pin = 1
r
=
r
&&
expression
(
b
,
l
+
1
,
-
1
);
exit_section_
(
b
,
l
,
m
,
r
,
p
,
null
);
return
r
||
p
;
}
/* ********************************************************** */
// &':'
public
static
boolean
map_argument_label
(
PsiBuilder
b
,
int
l
)
{
if
(!
recursion_guard_
(
b
,
l
,
"map_argument_label"
))
return
false
;
if
(!
nextTokenIsFast
(
b
,
T_COLON
))
return
false
;
boolean
r
;
Marker
m
=
enter_section_
(
b
,
l
,
_LEFT_
|
_AND_
,
ARGUMENT_LABEL
,
null
);
r
=
consumeTokenFast
(
b
,
T_COLON
);
exit_section_
(
b
,
l
,
m
,
r
,
false
,
null
);
return
r
;
}
/* ********************************************************** */
// [mb_nl declaration_type_element]
static
boolean
mb_declaration_type_element
(
PsiBuilder
b
,
int
l
)
{
...
...
@@ -8076,5 +8133,4 @@ public class GroovyGeneratedParser implements PsiParser, LightPsiParser {
static
final
Parser
T_RBRACK_parser_
=
(
b
,
l
)
->
consumeToken
(
b
,
T_RBRACK
);
static
final
Parser
T_RPAREN_parser_
=
(
b
,
l
)
->
consumeToken
(
b
,
T_RPAREN
);
static
final
Parser
capital_class_type_element_0_1_parser_
=
(
b
,
l
)
->
refWasCapitalized
(
b
,
l
+
1
);
static
final
Parser
expression_parser_
=
(
b
,
l
)
->
expression
(
b
,
l
+
1
,
-
1
);
}
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/groovy.bnf
+
13
-
2
View file @
f9294411
// Copyright 2000-201
8
JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-201
9
JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
{
generate = [
psi = 'no'
...
...
@@ -1133,7 +1133,18 @@ application_argument_list ::= <<applicationArguments application_arguments>>
private application_arguments ::= argument (',' mb_nl argument)*
private parse_argument ::= <<parseArgument argument>>
private argument ::= spread_list_argument | named_argument | <<parseExpressionOrMapArgument expression>>
private argument ::= spread_list_argument | named_argument | expression (map_argument_label map_argument)?
left map_argument_label ::= &':'
{
elementType = argument_label
consumeTokenMethod = 'consumeTokenFast'
}
left map_argument ::= ':' expression
{
pin = 1
consumeTokenMethod = 'consumeTokenFast'
elementType = named_argument
}
spread_list_argument ::= !<<isApplicationArguments>> '*' expression { consumeTokenMethod = 'consumeTokenFast' }
named_argument ::= argument_label named_argument_tail
private named_argument_tail ::= ':' expression
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/parser/parserUtils.kt
+
1
-
24
View file @
f9294411
// Copyright 2000-201
8
JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-201
9
JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
@
file
:
JvmName
(
"GroovyParserUtils"
)
@
file
:
Suppress
(
"UNUSED_PARAMETER"
,
"LiftReturnOrAssignment"
)
...
...
@@ -261,29 +261,6 @@ fun parseApplication(builder: PsiBuilder, level: Int,
}
}
fun
parseExpressionOrMapArgument
(
builder
:
PsiBuilder
,
level
:
Int
,
expression
:
Parser
):
Boolean
{
val
argumentMarker
=
builder
.
mark
()
val
labelMarker
=
builder
.
mark
()
if
(
expression
.
parse
(
builder
,
level
+
1
))
{
if
(
T_COLON
===
builder
.
tokenType
)
{
labelMarker
.
done
(
ARGUMENT_LABEL
)
builder
.
advanceLexer
()
report_error_
(
builder
,
expression
.
parse
(
builder
,
level
+
1
))
argumentMarker
.
done
(
NAMED_ARGUMENT
)
}
else
{
labelMarker
.
drop
()
argumentMarker
.
drop
()
}
return
true
}
else
{
labelMarker
.
drop
()
argumentMarker
.
rollbackTo
()
return
false
}
}
fun
parseKeyword
(
builder
:
PsiBuilder
,
level
:
Int
):
Boolean
=
builder
.
advanceIf
(
KEYWORDS
)
fun
parsePrimitiveType
(
builder
:
PsiBuilder
,
level
:
Int
):
Boolean
=
builder
.
advanceIf
(
primitiveTypes
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment