Skip to content

Commit d306724

Browse files
authored
Fix valid class tweaker files initially erroring until reopened (#2608)
* Fix valid class tweaker files initially erroring until reopened The slightly hacky fix utilises a "fake token" that matches real-looking line starts. It's unused in the parser so the user will still see an error when possible, but eliminating the BAD_CHARACTER inputs for valid *characters* seems to fix the incorrect error highlighting. * CtParser: Make invalid_entry_start_holder private to remove unused PSI itf * Clarify comment
1 parent 6ad3fd7 commit d306724

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/main/grammars/CtLexer.flex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ TYPE_VARIABLE=T[^;\n]+;
6262
ACCESS_ELEMENT=accessible|transitive-accessible|extendable|transitive-extendable|mutable|transitive-mutable
6363
INJECT_INTERFACE_ELEMENT=inject-interface|transitive-inject-interface
6464
EXTEND_ENUM_ELEMENT=extend-enum|transitive-extend-enum
65+
INCOMPLETE_ENTRY_START=[a-zA-Z-]+
6566
CLASS_ELEMENT=class
6667
METHOD_ELEMENT=method
6768
FIELD_ELEMENT=field
@@ -78,6 +79,9 @@ WHITE_SPACE=\s
7879
{ACCESS_ELEMENT} { yybegin(AW_ENTRY); return ACCESS_ELEMENT; }
7980
{INJECT_INTERFACE_ELEMENT} { yybegin(ITF_ENTRY_KEY); return INJECT_INTERFACE_ELEMENT; }
8081
{EXTEND_ENUM_ELEMENT} { yybegin(ENUM_NAME); return EXTEND_ENUM_ELEMENT; }
82+
// Create tokens for incomplete or invalid inputs too if they look like real inputs (same characters)
83+
// to prevent a bug where the entire file is erroring until reopened.
84+
{INCOMPLETE_ENTRY_START} { return INCOMPLETE_ENTRY_START; }
8185
}
8286

8387
<HEADER> {

src/main/grammars/CtParser.bnf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,6 @@ desc_element ::= OPEN_BRACKET* (PRIMITIVE | CLASS_VALUE) {
136136
signature ::= CLASS_NAME_ELEMENT (LESS_THAN signature_element+ GREATER_THAN)?
137137
signature_element ::= OPEN_BRACKET* (PRIMITIVE | TYPE_VARIABLE | signature_class_element)
138138
signature_class_element ::= ASTERISK | ( (PLUS | MINUS)? SIGNATURE_CLASS_VALUE_START (LESS_THAN signature_element GREATER_THAN)? SIGNATURE_CLASS_VALUE_END )
139+
140+
// Unused rule to generate the INCOMPLETE_ENTRY_START token type used in the lexer.
141+
private incomplete_entry_start_holder ::= INCOMPLETE_ENTRY_START

0 commit comments

Comments
 (0)