From f43460b2ef4c46387b0849c8a296b0cbbed5263c Mon Sep 17 00:00:00 2001 From: Johannes Mey <johannes.mey@tu-dresden.de> Date: Tue, 16 Nov 2021 17:03:36 +0100 Subject: [PATCH] some grammar and lexer fixes and an interface for attribute PSI elements --- src/main/grammar/Aspect.bnf | 33 +++++++++++++++---- src/main/grammar/Aspect.flex | 18 ++++++++-- .../aspect/psi/JastAddAspectAttribute.java | 6 ++++ .../impl/JastAddAspectCollAttributeImpl.java | 12 +++++++ .../impl/JastAddAspectInhAttributeImpl.java | 12 +++++++ .../impl/JastAddAspectSynAttributeImpl.java | 12 +++++++ 6 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/jastadd/tooling/aspect/psi/JastAddAspectAttribute.java create mode 100644 src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectCollAttributeImpl.java create mode 100644 src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectInhAttributeImpl.java create mode 100644 src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectSynAttributeImpl.java diff --git a/src/main/grammar/Aspect.bnf b/src/main/grammar/Aspect.bnf index da2d4a5..c888580 100644 --- a/src/main/grammar/Aspect.bnf +++ b/src/main/grammar/Aspect.bnf @@ -89,8 +89,16 @@ aspect_interface_member_declaration ::= ( aspect_nested_class_declaration | aspect_interface_field_declaration ) aspect_interface_syn_attribute_declaration ::= annotation* SYN LAZY? FINAL? aspect_type attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR expression_in_brackets)? SEMICOLON +{ + implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute" + extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectSynAttributeImpl" +} aspect_interface_inh_attribute_declaration ::= annotation* INH LAZY? FINAL? aspect_type attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR expression_in_brackets)? SEMICOLON +{ + implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute" + extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectInhAttributeImpl" +} aspect_interface_method_declaration ::= (PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | NATIVE | SYNCHRONIZED )* aspect_result_type method_declarator (THROWS name_list ) SEMICOLON @@ -111,22 +119,35 @@ aspect_refine_constructor_declaration ::= REFINE IDENTIFIER (PUBLIC | PROTECTED aspect_field_declaration ::= modifiers aspect_type IDENTIFIER DOT variable_declarator (COMMA variable_declarator)* SEMICOLON aspect_syn_attribute_declaration ::= annotation* SYN NTA? LAZY? FINAL? aspect_type IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR expression_in_brackets)? ( ASSIGN expression SEMICOLON | block | SEMICOLON ) +{ + implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute" + extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectSynAttributeImpl" +} -aspect_inh_attribute_declaration ::= annotation* INH NTA? LAZY? FINAL? aspect_type IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? (CIRCULAR expression_in_brackets)? SEMICOLON +aspect_inh_attribute_declaration ::= annotation* INH NTA? LAZY? FINAL? aspect_type IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)* )? RPAREN (CIRCULAR expression_in_brackets)? SEMICOLON +{ + implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute" + extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectInhAttributeImpl" +} +// FIXME parentheses are not required around the WHEN expression? aspect_rewrite ::= REWRITE IDENTIFIER (IDENTIFIER DOT IDENTIFIER LPAREN RPAREN)? LBRACE ((WHEN LPAREN expression RPAREN)? TO aspect_type ( expression SEMICOLON | block ))+ RBRACE aspect_syn_equation ::= annotation* EQUATION IDENTIFIER DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN ( ASSIGN expression SEMICOLON | block ) aspect_refine_syn_equation ::= REFINE IDENTIFIER EQUATION IDENTIFIER attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block) -aspect_inh_equation ::= annotation* EQUATION IDENTIFIER DOT IDENTIFIER LPAREN (INT IDENTIFIER)? DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression | block) +aspect_inh_equation ::= annotation* EQUATION IDENTIFIER DOT IDENTIFIER LPAREN (INT IDENTIFIER)? RPAREN DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block) -aspect_refine_inh_equation ::= REFINE IDENTIFIER EQUATION IDENTIFIER DOT IDENTIFIER LPAREN (INT IDENTIFIER)? RPAREN DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression | block) +aspect_refine_inh_equation ::= REFINE IDENTIFIER EQUATION IDENTIFIER DOT IDENTIFIER LPAREN (INT IDENTIFIER)? RPAREN DOT attribute_name LPAREN (type IDENTIFIER (COMMA type IDENTIFIER)*)? RPAREN (ASSIGN expression SEMICOLON | block) collection_attribute ::= annotation* COLL aspect_type IDENTIFIER DOT attribute_name LPAREN RPAREN CIRCULAR? (expression_in_brackets)? (WITH IDENTIFIER)? (ROOT IDENTIFIER)? SEMICOLON +{ + implements="org.jastadd.tooling.aspect.psi.JastAddAspectAttribute" + extends="org.jastadd.tooling.aspect.psi.impl.JastAddAspectCollAttributeImpl" +} -collection_contribution ::= annotation* CONTRIBUTES ( NTA expression TO IDENTIFIER DOT attribute_name LPAREN RPAREN | EACH? expression (WHEN expression)? TO IDENTIFIER DOT attribute_name LPAREN RPAREN (FOR EACH? expression)? | block TO IDENTIFIER DOT attribute_name LPAREN RPAREN ) SEMICOLON +collection_contribution ::= annotation* IDENTIFIER CONTRIBUTES ( NTA expression TO IDENTIFIER DOT attribute_name LPAREN RPAREN | EACH? expression (WHEN expression)? TO IDENTIFIER DOT attribute_name LPAREN RPAREN (FOR EACH? expression)? | block TO IDENTIFIER DOT attribute_name LPAREN RPAREN ) SEMICOLON aspect_add_interface ::= IO IMPLEMENTS type_name_list SEMICOLON @@ -192,7 +213,7 @@ assignment_operator ::= ASSIGN | STARASSIGN | SLASHASSIGN | REMASSIGN | PLUSASSI conditional_expression ::= conditional_or_expression ( QUESTIONMARK expression COLON conditional_expression)? -conditional_or_expression ::= conditional_and_expression ( SC_OR expression COLON conditional_expression )* +conditional_or_expression ::= conditional_and_expression ( SC_OR conditional_and_expression )* conditional_and_expression ::= inclusive_or_expression ( SC_AND inclusive_or_expression )* @@ -238,7 +259,7 @@ boolean_literal ::= TRUE | FALSE null_literal ::= NULL -arguments ::= LPAREN argument_list RPAREN +arguments ::= LPAREN argument_list? RPAREN argument_list ::= expression (COMMA expression)* diff --git a/src/main/grammar/Aspect.flex b/src/main/grammar/Aspect.flex index a1c9036..a99a55c 100644 --- a/src/main/grammar/Aspect.flex +++ b/src/main/grammar/Aspect.flex @@ -28,6 +28,7 @@ MultiLineComment = "/*" [^*]+ [*]+([^*/][^*]*[*]+)*[/] NotBrace = ( [^{}/]+ | [/][^{}/*] )+ +NotBracket = ( [^\[\]/]+ | [/][^\[\]/*] )+ // from jjt DecimalLiteral = [1-9] [0-9]* @@ -50,6 +51,7 @@ Identifier = [:jletter:] [:jletterdigit:]* %state EXPECT_CLASS_ANYTHING_LBRACE_ANYTHING_RBRACE %state CLASS_ANYTHING_LBRACE_ANYTHING_RBRACE %state LBRACE_ANYTHING_RBRACE +%state LBRACKET_ANYTHING_RBRACKET %state JAVA_IN_PAREN %state COLLECTION_DECL %state ATTRIBUTE_DEFINITION @@ -94,6 +96,17 @@ Identifier = [:jletter:] [:jletterdigit:]* {NotBrace} {} } +<LBRACKET_ANYTHING_RBRACKET> { + {SingleLineComment} {} + {FormalComment} {} + {MultiLineComment} {} + {CharacterLiteral} {} + {StringLiteral} {} + "[" { counter++; System.out.println("<INC>"); } + "]" { System.out.println("<DEC>"); counter--; if (counter==0) { System.out.println("<EXIT>"); yybegin(COLLECTION_DECL); return AspectTypes.LBRACKET_ANYTHING_RBRACKET; } } + {NotBracket} {System.out.println("<NB>" + yytext());} +} + <YYINITIAL,COLLECTION_DECL,ATTRIBUTE_DEFINITION> { "abstract" { return AspectTypes.ABSTRACT; } //"assert" { return AspectTypes.ASSERT; } @@ -126,7 +139,7 @@ Identifier = [:jletter:] [:jletterdigit:]* "interface" { return AspectTypes.INTERFACE; } "long" { return AspectTypes.LONG; } "native" { return AspectTypes.NATIVE; } -//"new" { return AspectTypes.NEW; } + "new" { return AspectTypes.NEW; } "null" { return AspectTypes.NULL; } //"package" { return AspectTypes.PACKAGE; } "private" { return AspectTypes.PRIVATE; } @@ -139,7 +152,7 @@ Identifier = [:jletter:] [:jletterdigit:]* "super" { return AspectTypes.SUPER; } //"switch" { return AspectTypes.SWITCH; } "synchronized" { return AspectTypes.SYNCHRONIZED; } -//"this" { return AspectTypes.THIS; } + "this" { return AspectTypes.THIS; } //"throw" { return AspectTypes.THROW; } "throws" { return AspectTypes.THROWS; } "transient" { return AspectTypes.TRANSIENT; } @@ -174,6 +187,7 @@ Identifier = [:jletter:] [:jletterdigit:]* <COLLECTION_DECL> { "with" { return AspectTypes.WITH; } "root" { return AspectTypes.ROOT; } + "[" { yybegin(LBRACKET_ANYTHING_RBRACKET); System.out.println("<ENTER>"); counter = 1; } } <ATTRIBUTE_DEFINITION> { diff --git a/src/main/java/org/jastadd/tooling/aspect/psi/JastAddAspectAttribute.java b/src/main/java/org/jastadd/tooling/aspect/psi/JastAddAspectAttribute.java new file mode 100644 index 0000000..3641ed2 --- /dev/null +++ b/src/main/java/org/jastadd/tooling/aspect/psi/JastAddAspectAttribute.java @@ -0,0 +1,6 @@ +package org.jastadd.tooling.aspect.psi; + +import com.intellij.psi.PsiElement; + +public interface JastAddAspectAttribute extends PsiElement { +} diff --git a/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectCollAttributeImpl.java b/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectCollAttributeImpl.java new file mode 100644 index 0000000..0381a57 --- /dev/null +++ b/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectCollAttributeImpl.java @@ -0,0 +1,12 @@ +package org.jastadd.tooling.aspect.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import org.jastadd.tooling.aspect.psi.JastAddAspectAttribute; +import org.jetbrains.annotations.NotNull; + +public abstract class JastAddAspectCollAttributeImpl extends ASTWrapperPsiElement implements JastAddAspectAttribute { + public JastAddAspectCollAttributeImpl(@NotNull ASTNode node) { + super(node); + } +} diff --git a/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectInhAttributeImpl.java b/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectInhAttributeImpl.java new file mode 100644 index 0000000..6bd54d1 --- /dev/null +++ b/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectInhAttributeImpl.java @@ -0,0 +1,12 @@ +package org.jastadd.tooling.aspect.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import org.jastadd.tooling.aspect.psi.JastAddAspectAttribute; +import org.jetbrains.annotations.NotNull; + +public abstract class JastAddAspectInhAttributeImpl extends ASTWrapperPsiElement implements JastAddAspectAttribute { + public JastAddAspectInhAttributeImpl(@NotNull ASTNode node) { + super(node); + } +} diff --git a/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectSynAttributeImpl.java b/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectSynAttributeImpl.java new file mode 100644 index 0000000..1b9443a --- /dev/null +++ b/src/main/java/org/jastadd/tooling/aspect/psi/impl/JastAddAspectSynAttributeImpl.java @@ -0,0 +1,12 @@ +package org.jastadd.tooling.aspect.psi.impl; + +import com.intellij.extapi.psi.ASTWrapperPsiElement; +import com.intellij.lang.ASTNode; +import org.jastadd.tooling.aspect.psi.JastAddAspectAttribute; +import org.jetbrains.annotations.NotNull; + +public abstract class JastAddAspectSynAttributeImpl extends ASTWrapperPsiElement implements JastAddAspectAttribute { + public JastAddAspectSynAttributeImpl(@NotNull ASTNode node) { + super(node); + } +} -- GitLab