From a9fa4e3ac30c05cf0268aeb0c2501d96a78d1852 Mon Sep 17 00:00:00 2001 From: bryankenote Date: Tue, 31 Dec 2024 14:30:46 -0800 Subject: [PATCH] update bnf and codegen --- .../intellij/parser/FsdParser.java | 67 +-- .../intellij/parser/FsdParserUtil.java | 6 + .../intellij/psi/FsdServiceSpec.java | 6 +- .../facilityapi/intellij/psi/FsdTypes.java | 4 - .../facilityapi/intellij/psi/FsdVisitor.java | 4 - .../psi/impl/FsdServiceItemsImpl.java | 4 - .../intellij/psi/impl/FsdServiceSpecImpl.java | 10 +- .../io/github/facilityapi/intellij/fsd.bnf | 4 +- .../facilityapi/intellij/lexer/_FsdLexer.flex | 444 ++---------------- .../intellij/tools/FsdFoldingBuilder.kt | 2 +- 10 files changed, 105 insertions(+), 446 deletions(-) create mode 100644 src/main/gen/io/github/facilityapi/intellij/parser/FsdParserUtil.java diff --git a/src/main/gen/io/github/facilityapi/intellij/parser/FsdParser.java b/src/main/gen/io/github/facilityapi/intellij/parser/FsdParser.java index 2e2d4ae4..0946b1c4 100644 --- a/src/main/gen/io/github/facilityapi/intellij/parser/FsdParser.java +++ b/src/main/gen/io/github/facilityapi/intellij/parser/FsdParser.java @@ -4,7 +4,7 @@ import com.intellij.lang.PsiBuilder; import com.intellij.lang.PsiBuilder.Marker; import static io.github.facilityapi.intellij.psi.FsdTypes.*; -import static com.intellij.lang.parser.GeneratedParserUtilBase.*; +import static io.github.facilityapi.intellij.parser.FsdParserUtil.*; import com.intellij.psi.tree.IElementType; import com.intellij.lang.ASTNode; import com.intellij.psi.tree.TokenSet; @@ -787,52 +787,61 @@ private static boolean service_item_recover_0(PsiBuilder b, int l) { } /* ********************************************************** */ - // ('{' decorated_service_item* '}') | decorated_service_item - public static boolean service_items(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "service_items")) return false; + // (service identifier ';' decorated_service_item*) | (service identifier '{' decorated_service_item* '}') + public static boolean service_spec(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "service_spec")) return false; + if (!nextTokenIs(b, SERVICE)) return false; boolean r; - Marker m = enter_section_(b, l, _NONE_, SERVICE_ITEMS, ""); - r = service_items_0(b, l + 1); - if (!r) r = decorated_service_item(b, l + 1); - exit_section_(b, l, m, r, false, null); + Marker m = enter_section_(b); + r = service_spec_0(b, l + 1); + if (!r) r = service_spec_1(b, l + 1); + exit_section_(b, m, SERVICE_SPEC, r); return r; } - // '{' decorated_service_item* '}' - private static boolean service_items_0(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "service_items_0")) return false; + // service identifier ';' decorated_service_item* + private static boolean service_spec_0(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "service_spec_0")) return false; boolean r; Marker m = enter_section_(b); - r = consumeToken(b, LEFT_BRACE); - r = r && service_items_0_1(b, l + 1); - r = r && consumeToken(b, RIGHT_BRACE); + r = consumeTokens(b, 0, SERVICE, IDENTIFIER, SEMI); + r = r && service_spec_0_3(b, l + 1); exit_section_(b, m, null, r); return r; } // decorated_service_item* - private static boolean service_items_0_1(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "service_items_0_1")) return false; + private static boolean service_spec_0_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "service_spec_0_3")) return false; while (true) { int c = current_position_(b); if (!decorated_service_item(b, l + 1)) break; - if (!empty_element_parsed_guard_(b, "service_items_0_1", c)) break; + if (!empty_element_parsed_guard_(b, "service_spec_0_3", c)) break; } return true; } - /* ********************************************************** */ - // service identifier service_items - public static boolean service_spec(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "service_spec")) return false; - if (!nextTokenIs(b, SERVICE)) return false; - boolean r, p; - Marker m = enter_section_(b, l, _NONE_, SERVICE_SPEC, null); - r = consumeTokens(b, 1, SERVICE, IDENTIFIER); - p = r; // pin = 1 - r = r && service_items(b, l + 1); - exit_section_(b, l, m, r, p, null); - return r || p; + // service identifier '{' decorated_service_item* '}' + private static boolean service_spec_1(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "service_spec_1")) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeTokens(b, 0, SERVICE, IDENTIFIER, LEFT_BRACE); + r = r && service_spec_1_3(b, l + 1); + r = r && consumeToken(b, RIGHT_BRACE); + exit_section_(b, m, null, r); + return r; + } + + // decorated_service_item* + private static boolean service_spec_1_3(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "service_spec_1_3")) return false; + while (true) { + int c = current_position_(b); + if (!decorated_service_item(b, l + 1)) break; + if (!empty_element_parsed_guard_(b, "service_spec_1_3", c)) break; + } + return true; } /* ********************************************************** */ diff --git a/src/main/gen/io/github/facilityapi/intellij/parser/FsdParserUtil.java b/src/main/gen/io/github/facilityapi/intellij/parser/FsdParserUtil.java new file mode 100644 index 00000000..4aa70764 --- /dev/null +++ b/src/main/gen/io/github/facilityapi/intellij/parser/FsdParserUtil.java @@ -0,0 +1,6 @@ +package io.github.facilityapi.intellij.parser; + +import com.intellij.lang.parser.GeneratedParserUtilBase; + +public class FsdParserUtil extends GeneratedParserUtilBase { +} diff --git a/src/main/gen/io/github/facilityapi/intellij/psi/FsdServiceSpec.java b/src/main/gen/io/github/facilityapi/intellij/psi/FsdServiceSpec.java index a2295246..e07a9955 100644 --- a/src/main/gen/io/github/facilityapi/intellij/psi/FsdServiceSpec.java +++ b/src/main/gen/io/github/facilityapi/intellij/psi/FsdServiceSpec.java @@ -7,10 +7,10 @@ public interface FsdServiceSpec extends PsiElement { - @Nullable - FsdServiceItems getServiceItems(); + @NotNull + List getDecoratedServiceItemList(); - @Nullable + @NotNull PsiElement getIdentifier(); } diff --git a/src/main/gen/io/github/facilityapi/intellij/psi/FsdTypes.java b/src/main/gen/io/github/facilityapi/intellij/psi/FsdTypes.java index 90246639..20a27df1 100644 --- a/src/main/gen/io/github/facilityapi/intellij/psi/FsdTypes.java +++ b/src/main/gen/io/github/facilityapi/intellij/psi/FsdTypes.java @@ -31,7 +31,6 @@ public interface FsdTypes { IElementType REFERENCE_TYPE = new FsdElementType("REFERENCE_TYPE"); IElementType REQUEST_FIELDS = new FsdElementType("REQUEST_FIELDS"); IElementType RESPONSE_FIELDS = new FsdElementType("RESPONSE_FIELDS"); - IElementType SERVICE_ITEMS = new FsdElementType("SERVICE_ITEMS"); IElementType SERVICE_SPEC = new FsdElementType("SERVICE_SPEC"); IElementType TYPE = new FsdElementType("TYPE"); IElementType TYPE_PARAMETER = new FsdElementType("TYPE_PARAMETER"); @@ -148,9 +147,6 @@ else if (type == REQUEST_FIELDS) { else if (type == RESPONSE_FIELDS) { return new FsdResponseFieldsImpl(node); } - else if (type == SERVICE_ITEMS) { - return new FsdServiceItemsImpl(node); - } else if (type == SERVICE_SPEC) { return new FsdServiceSpecImpl(node); } diff --git a/src/main/gen/io/github/facilityapi/intellij/psi/FsdVisitor.java b/src/main/gen/io/github/facilityapi/intellij/psi/FsdVisitor.java index 1151c9b9..1169b0b7 100644 --- a/src/main/gen/io/github/facilityapi/intellij/psi/FsdVisitor.java +++ b/src/main/gen/io/github/facilityapi/intellij/psi/FsdVisitor.java @@ -99,10 +99,6 @@ public void visitResponseFields(@NotNull FsdResponseFields o) { visitPsiElement(o); } - public void visitServiceItems(@NotNull FsdServiceItems o) { - visitPsiElement(o); - } - public void visitServiceSpec(@NotNull FsdServiceSpec o) { visitPsiElement(o); } diff --git a/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceItemsImpl.java b/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceItemsImpl.java index 86545cce..58761878 100644 --- a/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceItemsImpl.java +++ b/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceItemsImpl.java @@ -17,10 +17,6 @@ public FsdServiceItemsImpl(@NotNull ASTNode node) { super(node); } - public void accept(@NotNull FsdVisitor visitor) { - visitor.visitServiceItems(this); - } - @Override public void accept(@NotNull PsiElementVisitor visitor) { if (visitor instanceof FsdVisitor) accept((FsdVisitor)visitor); diff --git a/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceSpecImpl.java b/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceSpecImpl.java index 8d0d25b1..12c2d654 100644 --- a/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceSpecImpl.java +++ b/src/main/gen/io/github/facilityapi/intellij/psi/impl/FsdServiceSpecImpl.java @@ -28,15 +28,15 @@ public void accept(@NotNull PsiElementVisitor visitor) { } @Override - @Nullable - public FsdServiceItems getServiceItems() { - return findChildByClass(FsdServiceItems.class); + @NotNull + public List getDecoratedServiceItemList() { + return PsiTreeUtil.getChildrenOfTypeAsList(this, FsdDecoratedServiceItem.class); } @Override - @Nullable + @NotNull public PsiElement getIdentifier() { - return findChildByType(IDENTIFIER); + return findNotNullChildByType(IDENTIFIER); } } diff --git a/src/main/kotlin/io/github/facilityapi/intellij/fsd.bnf b/src/main/kotlin/io/github/facilityapi/intellij/fsd.bnf index 2454b018..83e9bd21 100644 --- a/src/main/kotlin/io/github/facilityapi/intellij/fsd.bnf +++ b/src/main/kotlin/io/github/facilityapi/intellij/fsd.bnf @@ -1,5 +1,6 @@ { parserClass="io.github.facilityapi.intellij.parser.FsdParser" + parserUtilClass="io.github.facilityapi.intellij.parser.FsdParserUtil" psiClassPrefix="Fsd" psiImplClassSuffix="Impl" @@ -42,8 +43,7 @@ definition ::= (attribute_list* service_spec) markdown_remarks* -service_spec ::= (service identifier service_items[';']) { pin=1 } -service_items ::= ('{' decorated_service_item* '}') | decorated_service_item +service_spec ::= (service identifier ';' decorated_service_item*) | (service identifier '{' decorated_service_item* '}') { pin=1 } decorated_service_item ::= attribute_list* service_item private service_item ::= (extern_decl | enum_spec | data_spec | method_spec | error_set_spec) { recoverWhile=service_item_recover } private service_item_recover ::= !('[' | '}' | extern | enum | data | errors | method) diff --git a/src/main/kotlin/io/github/facilityapi/intellij/lexer/_FsdLexer.flex b/src/main/kotlin/io/github/facilityapi/intellij/lexer/_FsdLexer.flex index bb69d2dd..9dba330e 100644 --- a/src/main/kotlin/io/github/facilityapi/intellij/lexer/_FsdLexer.flex +++ b/src/main/kotlin/io/github/facilityapi/intellij/lexer/_FsdLexer.flex @@ -11,7 +11,7 @@ import static io.github.facilityapi.intellij.psi.FsdTypes.*; %{ public _FsdLexer() { - this((java.io.Reader)null); + this((java.io.Reader)null); } %} @@ -26,405 +26,61 @@ EOL=\R WHITE_SPACE=\s+ COMMENT="//"[^\r\n]* -IDENTIFIER=[a-zA-Z0-9_]+ +SPACE=[ \t\n\x0B\f\r]+ +IDENTIFIER=[a-zA-Z_0-9]+ +TYPENAME=[a-zA-Z_0-9]+ +ATTRIBUTENAME=[a-zA-Z_0-9]+ ATTRIBUTEPARAMETERVALUE=\"(([^\"\\]+|\\[\"\\/bfnrt]|\\u[0-9a-fA-f]{4})*)\"|([0-9a-zA-Z.+_-]+) NUMBER=[0-9]+(\.[0-9]*)? -MARKDOWN_HEADING=#[^\r\n]* -MARKDOWN_TEXT=.+ - -%state MARKDOWN_SECTION -%state SERVICE_ATTRIBUTE, SERVICE_ATTRIBUTE_PARAMETER_LIST, SERVICE_ATTRIBUTE_ARGUMENT -%state SERVICE_BODY, SERVICE_BODY_ATTRIBUTE, SERVICE_BODY_ATTRIBUTE_PARAMETER_LIST, SERVICE_BODY_ATTRIBUTE_ARGUMENT -%state METHOD_BODY, METHOD_BODY_TYPE, METHOD_BODY_TYPE_END, METHOD_BODY_ATTRIBUTE, METHOD_BODY_ATTRIBUTE_PARAMETER_LIST, METHOD_BODY_ATTRIBUTE_ARGUMENT -%state RESPONSE_SEPARATOR, RESPONSE_BODY, RESPONSE_BODY_TYPE, RESPONSE_BODY_TYPE_END, RESPONSE_BODY_ATTRIBUTE, RESPONSE_BODY_ATTRIBUTE_PARAMETER_LIST, RESPONSE_BODY_ATTRIBUTE_ARGUMENT -%state DATA_BODY, DATA_BODY_TYPE, DATA_BODY_TYPE_END, DATA_BODY_ATTRIBUTE, DATA_BODY_ATTRIBUTE_PARAMETER_LIST, DATA_BODY_ATTRIBUTE_ARGUMENT -%state LIST_BODY, LIST_BODY_ATTRIBUTE, LIST_BODY_ATTRIBUTE_PARAMETER_LIST, LIST_BODY_ATTRIBUTE_ARGUMENT -%state EXTERN_DECL +MARKDOWNHEADING=#[^\r\n]* +MARKDOWNTEXT=.+ %% { - {WHITE_SPACE} { return WHITE_SPACE; } - - "service" { yybegin(SERVICE_BODY); return SERVICE; } - - "[" { yybegin(SERVICE_ATTRIBUTE); return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - - {COMMENT} { return COMMENT; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "(" { yybegin(SERVICE_ATTRIBUTE_PARAMETER_LIST); return LEFT_PAREN; } - ")" { return RIGHT_PAREN; } - - {IDENTIFIER} { return ATTRIBUTENAME; } - , { return COMMA; } - ] { yybegin(YYINITIAL); return RIGHT_BRACKET; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - ")" { yybegin(SERVICE_ATTRIBUTE); return RIGHT_PAREN; } - , { return COMMA; } - - {IDENTIFIER} { yybegin(SERVICE_ATTRIBUTE_ARGUMENT); return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - ":" { return COLON; } - {ATTRIBUTEPARAMETERVALUE} { yybegin(SERVICE_ATTRIBUTE_PARAMETER_LIST); return ATTRIBUTEPARAMETERVALUE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "extern" { yybegin(EXTERN_DECL); return EXTERN; } - "method" { yybegin(METHOD_BODY); return METHOD; } - "data" { yybegin(DATA_BODY); return DATA; } - "errors" { yybegin(LIST_BODY); return ERRORS; } - "enum" { yybegin(LIST_BODY); return ENUM; } - - "{" { return LEFT_BRACE; } - "}" { yybegin(MARKDOWN_SECTION); return RIGHT_BRACE; } - "[" { yybegin(SERVICE_BODY_ATTRIBUTE); return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - - {IDENTIFIER} { return IDENTIFIER; } - {COMMENT} { return COMMENT; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "(" { yybegin(SERVICE_BODY_ATTRIBUTE_PARAMETER_LIST); return LEFT_PAREN; } - ")" { return RIGHT_PAREN; } - - {IDENTIFIER} { return ATTRIBUTENAME; } - , { return COMMA; } - ] { yybegin(SERVICE_BODY); return RIGHT_BRACKET; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - ")" { yybegin(SERVICE_BODY_ATTRIBUTE); return RIGHT_PAREN; } - , { return COMMA; } - - {IDENTIFIER} { yybegin(SERVICE_BODY_ATTRIBUTE_ARGUMENT); return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - ":" { return COLON; } - {ATTRIBUTEPARAMETERVALUE} { yybegin(SERVICE_BODY_ATTRIBUTE_PARAMETER_LIST); return ATTRIBUTEPARAMETERVALUE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "{" { return LEFT_BRACE; } - "}" { yybegin(RESPONSE_SEPARATOR); return RIGHT_BRACE; } - ":" { yybegin(METHOD_BODY_TYPE); return COLON; } - "[" { yybegin(METHOD_BODY_ATTRIBUTE); return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - {COMMENT} { return COMMENT; } - {IDENTIFIER} { return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "(" { yybegin(METHOD_BODY_ATTRIBUTE_PARAMETER_LIST); return LEFT_PAREN; } - ")" { return RIGHT_PAREN; } - - {IDENTIFIER} { return ATTRIBUTENAME; } - , { return COMMA; } - ] { yybegin(METHOD_BODY); return RIGHT_BRACKET; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - ")" { yybegin(METHOD_BODY_ATTRIBUTE); return RIGHT_PAREN; } - , { return COMMA; } - - {IDENTIFIER} { yybegin(METHOD_BODY_ATTRIBUTE_ARGUMENT); return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - ":" { return COLON; } - {ATTRIBUTEPARAMETERVALUE} { yybegin(METHOD_BODY_ATTRIBUTE_PARAMETER_LIST); return ATTRIBUTEPARAMETERVALUE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - {COMMENT} { return COMMENT; } - - "string" { yybegin(METHOD_BODY_TYPE_END); return STRING; } - "boolean" { yybegin(METHOD_BODY_TYPE_END); return BOOLEAN; } - "int32" { yybegin(METHOD_BODY_TYPE_END); return INT32; } - "int64" { yybegin(METHOD_BODY_TYPE_END); return INT64; } - "double" { yybegin(METHOD_BODY_TYPE_END); return DOUBLE; } - "decimal" { yybegin(METHOD_BODY_TYPE_END); return DECIMAL; } - "datetime" { yybegin(METHOD_BODY_TYPE_END); return DATETIME; } - "bytes" { yybegin(METHOD_BODY_TYPE_END); return BYTES; } - "object" { yybegin(METHOD_BODY_TYPE_END); return OBJECT; } - "map" { yybegin(METHOD_BODY_TYPE_END); return MAP; } - "result" { yybegin(METHOD_BODY_TYPE_END); return RESULT; } - "nullable" { yybegin(METHOD_BODY_TYPE_END); return NULLABLE; } - "error" { yybegin(METHOD_BODY_TYPE_END); return ERROR; } - - {IDENTIFIER} { yybegin(METHOD_BODY_TYPE_END); return TYPENAME; } - - "}" { yybegin(RESPONSE_SEPARATOR); return RIGHT_BRACE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - {COMMENT} { return COMMENT; } - - "<" { yybegin(METHOD_BODY_TYPE); return LEFT_ANGLE; } - ">" { return RIGHT_ANGLE; } - "[" { return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - "!" { return BANG; } - - ";" { yybegin(METHOD_BODY); return SEMI; } - - // Identifiers shouldn't be here, so break back into the body definition - {IDENTIFIER} { yybegin(METHOD_BODY); return IDENTIFIER; } - "}" { yybegin(RESPONSE_SEPARATOR); return RIGHT_BRACE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - {COMMENT} { return COMMENT; } - - ":" { yybegin(RESPONSE_BODY); return COLON; } - "}" { yybegin(MARKDOWN_SECTION); return RIGHT_BRACE; } - - "method" { yybegin(METHOD_BODY); return METHOD; } - "data" { yybegin(DATA_BODY); return DATA; } - "errors" { yybegin(LIST_BODY); return ERRORS; } - "enum" { yybegin(LIST_BODY); return ENUM; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "{" { return LEFT_BRACE; } - "}" { yybegin(SERVICE_BODY); return RIGHT_BRACE; } - ":" { yybegin(RESPONSE_BODY_TYPE); return COLON; } - "[" { yybegin(RESPONSE_BODY_ATTRIBUTE); return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - {COMMENT} { return COMMENT; } - {IDENTIFIER} { return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "(" { yybegin(RESPONSE_BODY_ATTRIBUTE_PARAMETER_LIST); return LEFT_PAREN; } - ")" { return RIGHT_PAREN; } - - {IDENTIFIER} { return ATTRIBUTENAME; } - , { return COMMA; } - ] { yybegin(RESPONSE_BODY); return RIGHT_BRACKET; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - ")" { yybegin(RESPONSE_BODY_ATTRIBUTE); return RIGHT_PAREN; } - , { return COMMA; } - - {IDENTIFIER} { yybegin(RESPONSE_BODY_ATTRIBUTE_ARGUMENT); return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - ":" { return COLON; } - {ATTRIBUTEPARAMETERVALUE} { yybegin(RESPONSE_BODY_ATTRIBUTE_PARAMETER_LIST); return ATTRIBUTEPARAMETERVALUE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - {COMMENT} { return COMMENT; } - - "string" { yybegin(RESPONSE_BODY_TYPE_END); return STRING; } - "boolean" { yybegin(RESPONSE_BODY_TYPE_END); return BOOLEAN; } - "int32" { yybegin(RESPONSE_BODY_TYPE_END); return INT32; } - "int64" { yybegin(RESPONSE_BODY_TYPE_END); return INT64; } - "double" { yybegin(RESPONSE_BODY_TYPE_END); return DOUBLE; } - "decimal" { yybegin(RESPONSE_BODY_TYPE_END); return DECIMAL; } - "datetime" { yybegin(RESPONSE_BODY_TYPE_END); return DATETIME; } - "bytes" { yybegin(RESPONSE_BODY_TYPE_END); return BYTES; } - "object" { yybegin(RESPONSE_BODY_TYPE_END); return OBJECT; } - "map" { yybegin(RESPONSE_BODY_TYPE_END); return MAP; } - "result" { yybegin(RESPONSE_BODY_TYPE_END); return RESULT; } - "nullable" { yybegin(RESPONSE_BODY_TYPE_END); return NULLABLE; } - "error" { yybegin(RESPONSE_BODY_TYPE_END); return ERROR; } - - {IDENTIFIER} { yybegin(RESPONSE_BODY_TYPE_END); return TYPENAME; } - - "}" { yybegin(SERVICE_BODY); return RIGHT_BRACE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - {COMMENT} { return COMMENT; } - - "<" { yybegin(RESPONSE_BODY_TYPE); return LEFT_ANGLE; } - ">" { return RIGHT_ANGLE; } - "[" { return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - "!" { return BANG; } - - ";" { yybegin(RESPONSE_BODY); return SEMI; } - - // Identifiers shouldn't be here, so break back into the body definition - {IDENTIFIER} { yybegin(RESPONSE_BODY); return IDENTIFIER; } - "}" { yybegin(SERVICE_BODY); return RIGHT_BRACE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "{" { return LEFT_BRACE; } - "}" { yybegin(SERVICE_BODY); return RIGHT_BRACE; } - ":" { yybegin(DATA_BODY_TYPE); return COLON; } - "[" { yybegin(DATA_BODY_ATTRIBUTE); return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - {COMMENT} { return COMMENT; } - {IDENTIFIER} { return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "(" { yybegin(DATA_BODY_ATTRIBUTE_PARAMETER_LIST); return LEFT_PAREN; } - ")" { return RIGHT_PAREN; } - - {IDENTIFIER} { return ATTRIBUTENAME; } - , { return COMMA; } - ] { yybegin(DATA_BODY); return RIGHT_BRACKET; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - ")" { yybegin(DATA_BODY_ATTRIBUTE); return RIGHT_PAREN; } - , { return COMMA; } - - {IDENTIFIER} { yybegin(DATA_BODY_ATTRIBUTE_ARGUMENT); return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - ":" { return COLON; } - {ATTRIBUTEPARAMETERVALUE} { yybegin(DATA_BODY_ATTRIBUTE_PARAMETER_LIST); return ATTRIBUTEPARAMETERVALUE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - {COMMENT} { return COMMENT; } - - "string" { yybegin(DATA_BODY_TYPE_END); return STRING; } - "boolean" { yybegin(DATA_BODY_TYPE_END); return BOOLEAN; } - "int32" { yybegin(DATA_BODY_TYPE_END); return INT32; } - "int64" { yybegin(DATA_BODY_TYPE_END); return INT64; } - "double" { yybegin(DATA_BODY_TYPE_END); return DOUBLE; } - "decimal" { yybegin(DATA_BODY_TYPE_END); return DECIMAL; } - "datetime" { yybegin(DATA_BODY_TYPE_END); return DATETIME; } - "bytes" { yybegin(DATA_BODY_TYPE_END); return BYTES; } - "object" { yybegin(DATA_BODY_TYPE_END); return OBJECT; } - "map" { yybegin(DATA_BODY_TYPE_END); return MAP; } - "result" { yybegin(DATA_BODY_TYPE_END); return RESULT; } - "nullable" { yybegin(DATA_BODY_TYPE_END); return NULLABLE; } - "error" { yybegin(DATA_BODY_TYPE_END); return ERROR; } - - {IDENTIFIER} { yybegin(DATA_BODY_TYPE_END); return TYPENAME; } - - "}" { yybegin(SERVICE_BODY); return RIGHT_BRACE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - {COMMENT} { return COMMENT; } - - "<" { yybegin(DATA_BODY_TYPE); return LEFT_ANGLE; } - ">" { return RIGHT_ANGLE; } - "[" { return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - "!" { return BANG; } - - ";" { yybegin(DATA_BODY); return SEMI; } - - // Identifiers shouldn't be here, so break back into the body definition - {IDENTIFIER} { yybegin(DATA_BODY); return IDENTIFIER; } - "}" { yybegin(SERVICE_BODY); return RIGHT_BRACE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "{" { return LEFT_BRACE; } - "}" { yybegin(SERVICE_BODY); return RIGHT_BRACE; } - "," { return COMMA; } - "[" { yybegin(LIST_BODY_ATTRIBUTE); return LEFT_BRACKET; } - "]" { return RIGHT_BRACKET; } - {COMMENT} { return COMMENT; } - {IDENTIFIER} { return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "(" { yybegin(LIST_BODY_ATTRIBUTE_PARAMETER_LIST); return LEFT_PAREN; } - ")" { return RIGHT_PAREN; } - - {IDENTIFIER} { return ATTRIBUTENAME; } - , { return COMMA; } - ] { yybegin(LIST_BODY); return RIGHT_BRACKET; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - ")" { yybegin(LIST_BODY_ATTRIBUTE); return RIGHT_PAREN; } - , { return COMMA; } - - {IDENTIFIER} { yybegin(LIST_BODY_ATTRIBUTE_ARGUMENT); return IDENTIFIER; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - ":" { return COLON; } - {ATTRIBUTEPARAMETERVALUE} { yybegin(LIST_BODY_ATTRIBUTE_PARAMETER_LIST); return ATTRIBUTEPARAMETERVALUE; } -} - - { - {WHITE_SPACE} { return WHITE_SPACE; } - - "data" { return DATA; } - "enum" { return ENUM; } - - ";" { yybegin(SERVICE_BODY); return SEMI; } - - {COMMENT} { return COMMENT; } - {IDENTIFIER} { return IDENTIFIER; } -} + {WHITE_SPACE} { return WHITE_SPACE; } + + "(" { return LEFT_PAREN; } + ")" { return RIGHT_PAREN; } + "{" { return LEFT_BRACE; } + "}" { return RIGHT_BRACE; } + "[" { return LEFT_BRACKET; } + "]" { return RIGHT_BRACKET; } + "<" { return LEFT_ANGLE; } + ">" { return RIGHT_ANGLE; } + "," { return COMMA; } + ";" { return SEMI; } + ":" { return COLON; } + "!" { return BANG; } + "service" { return SERVICE; } + "extern" { return EXTERN; } + "enum" { return ENUM; } + "data" { return DATA; } + "errors" { return ERRORS; } + "method" { return METHOD; } + "string" { return STRING; } + "boolean" { return BOOLEAN; } + "int32" { return INT32; } + "int64" { return INT64; } + "double" { return DOUBLE; } + "decimal" { return DECIMAL; } + "datetime" { return DATETIME; } + "bytes" { return BYTES; } + "object" { return OBJECT; } + "map" { return MAP; } + "result" { return RESULT; } + "error" { return ERROR; } + "nullable" { return NULLABLE; } + + {COMMENT} { return COMMENT; } + {SPACE} { return SPACE; } + {IDENTIFIER} { return IDENTIFIER; } + {TYPENAME} { return TYPENAME; } + {ATTRIBUTENAME} { return ATTRIBUTENAME; } + {ATTRIBUTEPARAMETERVALUE} { return ATTRIBUTEPARAMETERVALUE; } + {NUMBER} { return NUMBER; } + {MARKDOWNHEADING} { return MARKDOWNHEADING; } + {MARKDOWNTEXT} { return MARKDOWNTEXT; } - { - \r { return WHITE_SPACE; } - \n { return WHITE_SPACE; } - {MARKDOWN_HEADING} { return MARKDOWNHEADING; } - {MARKDOWN_TEXT} { return MARKDOWNTEXT; } } [^] { return BAD_CHARACTER; } diff --git a/src/main/kotlin/io/github/facilityapi/intellij/tools/FsdFoldingBuilder.kt b/src/main/kotlin/io/github/facilityapi/intellij/tools/FsdFoldingBuilder.kt index 5629f722..1ed208f8 100644 --- a/src/main/kotlin/io/github/facilityapi/intellij/tools/FsdFoldingBuilder.kt +++ b/src/main/kotlin/io/github/facilityapi/intellij/tools/FsdFoldingBuilder.kt @@ -26,7 +26,7 @@ class FsdFoldingBuilder : FoldingBuilderEx(), DumbAware { PsiTreeUtil.findChildrenOfType(root, foldable).mapNotNull { child -> when (child) { is FsdServiceSpec -> { - val serviceItems = child.serviceItems ?: return@mapNotNull null + val serviceItems = child val startOffset = serviceItems.textRange.startOffset + 1 val endOffset = serviceItems.textRange.endOffset - 1