Skip to content

Commit

Permalink
Undo fix for #2701, fixes #3472
Browse files Browse the repository at this point in the history
  • Loading branch information
slideclimb committed Mar 23, 2024
1 parent ff086f2 commit 92cc9b6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 76 deletions.
19 changes: 3 additions & 16 deletions src/nl/hannahsten/texifyidea/grammar/Bibtex.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
extends("entry")="com.intellij.extapi.psi.StubBasedPsiElementBase<nl.hannahsten.texifyidea.index.stub.BibtexEntryStub>"
implements("entry")="com.intellij.psi.PsiNameIdentifierOwner"
implements("id")="com.intellij.psi.PsiNameIdentifierOwner"

tokens = [
RAW_TEXT_TOKEN='RAW_TEXT'
]

}

bibtexFile ::= (entry | comment)*
Expand Down Expand Up @@ -47,28 +42,20 @@ tag ::= comment* key comment* ASSIGNMENT comment* content comment* {
mixin="nl.hannahsten.texifyidea.psi.impl.BibtexTagImplMixin"
}

key ::= VERBATIM_IDENTIFIER | IDENTIFIER
key ::= IDENTIFIER

content ::= (string (CONCATENATE string)+) | string | NUMBER | key

string ::= defined_string | quoted_verbatim | braced_verbatim | quoted_string | braced_string
string ::= defined_string | quoted_string | braced_string

defined_string ::= key {
mixin="nl.hannahsten.texifyidea.psi.impl.BibtexDefinedStringImplMixin"
}

quoted_string ::= QUOTES normal_text? END_QUOTES { pin=1 }

// pin=3 because it would get in the way of the quoted string otherwise.
quoted_verbatim ::= QUOTES raw_text* END_QUOTES { pin=3 }

braced_string ::= OPEN_BRACE normal_text* CLOSE_BRACE { pin=1 }

// pin=3 because it would get in the way of the braced string otherwise.
braced_verbatim ::= OPEN_BRACE raw_text* CLOSE_BRACE { pin=3 }

comment ::= COMMENT_TOKEN

normal_text ::= NORMAL_TEXT_WORD+

raw_text ::= RAW_TEXT_TOKEN+
normal_text ::= NORMAL_TEXT_WORD+
35 changes: 2 additions & 33 deletions src/nl/hannahsten/texifyidea/grammar/BibtexLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,7 @@ import static nl.hannahsten.texifyidea.psi.BibtexTypes.*;
%eof}

%{
private Deque<Integer> stack = new ArrayDeque<>();


public void yypushState(int newState) {
stack.push(yystate());
yybegin(newState);
}

public void yypopState() {
yybegin(stack.pop());
}

int braceCount = 0;
boolean verbatim = false;
%}

WHITE_SPACE=([\ \t\f]|"\r"|"\n"|"\r\n")+
Expand All @@ -52,11 +39,9 @@ TYPE_TOKEN=@[a-zA-Z_]+
COMMENT_TOKEN=%[^\r\n]*
// Characters disallowed by bibtex or biber (non-ascii or not depends on LaTeX compiler)
IDENTIFIER=[^,{}\(\)\"#%'=~\\ \n]+
VERBATIM_IDENTIFIER="url"
NUMBER=[0-9-]+
NORMAL_TEXT_WORD=([^\"]|\\\" )+
NORMAL_TEXT_BRACED_STRING=[^{} ]+
ANY_CHAR=[^]

%state XXAFTERTYPETOKEN
%state XXENTRY
Expand All @@ -71,8 +56,6 @@ ANY_CHAR=[^]

%xstate XXCOMMENT
%xstate XXCOMMENT_STRING
%xstate XXQUOTED_VERBATIM
%xstate XXBRACED_VERBATIM
%%
{COMMENT_TOKEN} { return COMMENT_TOKEN; }

Expand Down Expand Up @@ -109,7 +92,6 @@ ANY_CHAR=[^]

<XXCOMMENT_STRING> {
{CLOSE_BRACE} { yybegin(XXAFTERENTRY); return COMMENT_TOKEN; }
{ANY_CHAR} { return COMMENT_TOKEN; }
}

// Preamble: @preamble{ "some string" }
Expand Down Expand Up @@ -152,11 +134,10 @@ ANY_CHAR=[^]
// Complete entry.
<XXENTRY> {
{NUMBER} { return NUMBER; }
{VERBATIM_IDENTIFIER} { verbatim = true; return VERBATIM_IDENTIFIER; }
{IDENTIFIER} { return IDENTIFIER; }
{ASSIGNMENT} { return ASSIGNMENT; }
{OPEN_BRACE} { if (verbatim) yypushState(XXBRACED_VERBATIM); else yybegin(XXBRACED_STRING); return OPEN_BRACE; }
{QUOTES} { if (verbatim) yypushState(XXQUOTED_VERBATIM); else yybegin(XXQUOTED_STRING); return QUOTES; }
{OPEN_BRACE} { yybegin(XXBRACED_STRING); return OPEN_BRACE; }
{QUOTES} { yybegin(XXQUOTED_STRING); return QUOTES; }
{CONCATENATE} { return CONCATENATE; }
{SEPARATOR} { return SEPARATOR; }
{CLOSE_BRACE} { yybegin(XXAFTERENTRY); return CLOSE_BRACE; }
Expand All @@ -182,18 +163,6 @@ ANY_CHAR=[^]
{NORMAL_TEXT_BRACED_STRING} { return NORMAL_TEXT_WORD; }
}

// { Braced text } in an entry where all characters are allowed.
<XXBRACED_VERBATIM> {
{CLOSE_BRACE} { yypopState(); verbatim = false; return CLOSE_BRACE; }
{ANY_CHAR} { return RAW_TEXT_TOKEN; }
}

// "Quoted text" in an entry where all characters are allowed.
<XXQUOTED_VERBATIM> {
{QUOTES} { yypopState(); verbatim = false; return END_QUOTES; }
{ANY_CHAR} { return RAW_TEXT_TOKEN; }
}

{WHITE_SPACE} { return WHITE_SPACE; }

[^] { return BAD_CHARACTER; }
24 changes: 0 additions & 24 deletions src/nl/hannahsten/texifyidea/highlighting/BibtexAnnotator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.psi.PsiElement
import nl.hannahsten.texifyidea.psi.BibtexBracedString
import nl.hannahsten.texifyidea.psi.BibtexBracedVerbatim
import nl.hannahsten.texifyidea.psi.BibtexEntry
import nl.hannahsten.texifyidea.psi.BibtexKey
import nl.hannahsten.texifyidea.psi.BibtexQuotedString
import nl.hannahsten.texifyidea.psi.BibtexQuotedVerbatim
import nl.hannahsten.texifyidea.util.parser.parentOfType
import nl.hannahsten.texifyidea.util.tokenType
import java.util.*
Expand All @@ -22,9 +20,7 @@ open class BibtexAnnotator : Annotator {
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
when (element) {
is BibtexBracedString -> annotate(element, holder)
is BibtexBracedVerbatim -> annotate(element, holder)
is BibtexQuotedString -> annotate(element, holder)
is BibtexQuotedVerbatim -> annotate(element, holder)
is BibtexKey -> annotate(element, holder)
}
}
Expand All @@ -39,16 +35,6 @@ open class BibtexAnnotator : Annotator {
.create()
}

/**
* Adds syntax highlighting to all {Braced Verbatim Strings}.
*/
private fun annotate(bracedVerbatim: BibtexBracedVerbatim, holder: AnnotationHolder) {
holder.newAnnotation(HighlightSeverity.INFORMATION, "")
.range(bracedVerbatim)
.textAttributes(BibtexSyntaxHighlighter.VALUE)
.create()
}

/**
* Adds syntax highlighting to all "Quoted Strings".
*/
Expand All @@ -59,16 +45,6 @@ open class BibtexAnnotator : Annotator {
.create()
}

/**
* Adds syntax highlighting to all "Quoted Verbatim Strings".
*/
private fun annotate(quotedVerbatim: BibtexQuotedVerbatim, holder: AnnotationHolder) {
holder.newAnnotation(HighlightSeverity.INFORMATION, "")
.range(quotedVerbatim)
.textAttributes(BibtexSyntaxHighlighter.STRING)
.create()
}

/**
* Adds syntax highlighting to all Keys.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ open class BibtexSyntaxHighlighter : SyntaxHighlighterBase() {
BibtexTypes.OPEN_BRACE, BibtexTypes.CLOSE_BRACE, BibtexTypes.OPEN_PARENTHESIS -> BRACES_KEYS
BibtexTypes.COMMENT, BibtexTypes.COMMENT_TOKEN -> COMMENT_KEYS
BibtexTypes.CONCATENATE -> CONCATENATION_KEYS
BibtexTypes.IDENTIFIER, BibtexTypes.VERBATIM_IDENTIFIER -> IDENTIFIER_KEYS
BibtexTypes.IDENTIFIER -> IDENTIFIER_KEYS
BibtexTypes.KEY -> KEY_KEYS
BibtexTypes.NUMBER -> NUMBER_KEYS
BibtexTypes.TYPE_TOKEN -> TYPE_TOKEN_KEYS
BibtexTypes.STRING, BibtexTypes.QUOTED_STRING, BibtexTypes.QUOTED_VERBATIM -> STRING_KEYS
BibtexTypes.CONTENT, BibtexTypes.BRACED_STRING, BibtexTypes.BRACED_VERBATIM -> VALUE_KEYS
BibtexTypes.STRING, BibtexTypes.QUOTED_STRING -> STRING_KEYS
BibtexTypes.CONTENT, BibtexTypes.BRACED_STRING -> VALUE_KEYS
else -> EMPTY_KEYS
}
}

0 comments on commit 92cc9b6

Please sign in to comment.