Grammatik um recordPattern erweitert

This commit is contained in:
luca9913 2023-03-24 04:44:52 +01:00
parent 0311f5ed77
commit 9a780127c0
2 changed files with 29 additions and 7 deletions

View File

@ -575,7 +575,7 @@ switchBlockStatementGroup
; ;
switchLabel switchLabel
: CASE (constantExpression=expression | enumConstantName=IDENTIFIER | typeType varName=identifier) ':' : CASE (constantExpression=expression | enumConstantName=IDENTIFIER | pattern) ':'
| DEFAULT ':' | DEFAULT ':'
; ;
@ -652,7 +652,30 @@ expression
// Java17 // Java17
pattern pattern
: variableModifier* typeType? annotation* identifier : primaryPattern
| guardedPattern
;
primaryPattern
: typePattern
| recordPattern
| '(' pattern ')'
;
recordPattern
: typeType recordStructurePattern identifier?
;
typePattern
: variableModifier* typeType? identifier
;
recordStructurePattern
: '(' recordComponentPatternList? ')'
;
recordComponentPatternList
: pattern (',' pattern)*
; ;
// Java8 // Java8
@ -691,14 +714,13 @@ switchExpression
// Java17 // Java17
switchLabeledRule switchLabeledRule
: CASE (expressionList | NULL_LITERAL | guardedPattern) (ARROW | COLON) switchRuleOutcome : CASE (expressionList | NULL_LITERAL | pattern) (ARROW | COLON) switchRuleOutcome
| DEFAULT (ARROW | COLON) switchRuleOutcome | DEFAULT (ARROW | COLON) switchRuleOutcome
; ;
// Java17 // Java17
guardedPattern guardedPattern
: '(' guardedPattern ')' : variableModifier* typeType? annotation* identifier ('&&' expression)*
| variableModifier* typeType annotation* identifier ('&&' expression)*
| guardedPattern '&&' expression | guardedPattern '&&' expression
; ;

View File

@ -13,8 +13,7 @@ import de.dhbwstuttgart.parser.JavaTXParser;
import org.junit.Test; import org.junit.Test;
/** /**
* Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der * Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. Der dabei erstellte Syntaxbaum wird nicht kontrolliert.
* dabei erstellte Syntaxbaum wird nicht kontrolliert.
* *
* @author janulrich * @author janulrich
* *
@ -26,6 +25,7 @@ public class GeneralParserTest {
public void run() { public void run() {
List<String> filenames = new ArrayList<String>(); List<String> filenames = new ArrayList<String>();
filenames.add("NewTest.jav"); filenames.add("NewTest.jav");
filenames.add("FieldInitializationTest.jav"); filenames.add("FieldInitializationTest.jav");
filenames.add("ImportTest.jav"); filenames.add("ImportTest.jav");