Skip to content

Commit

Permalink
Update bytecode syntax highlighting grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
rcx committed Jul 17, 2019
1 parent f0abafd commit 9e7f396
Show file tree
Hide file tree
Showing 2 changed files with 516 additions and 553 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// COMPILE THIS FILE WITH GRAMMARKIT PLUGIN FOR INTELLIJ
// (JFLEX 1.7.0)
// OR ELSE IT WON'T FUCKING WORK
package club.bytecode.the.jda.gui.fileviewer;

import java.io.*;
import javax.swing.text.Segment;

import org.fife.ui.rsyntaxtextarea.*;


/**
* Scanner the JDA Bytecode.<p>
*
Expand Down Expand Up @@ -64,7 +66,6 @@ import org.fife.ui.rsyntaxtextarea.*;
public BytecodeTokenizer() {
}


/**
* Adds the token specified to the current linked list of tokens.
*
Expand All @@ -73,7 +74,7 @@ import org.fife.ui.rsyntaxtextarea.*;
*/
private void addHyperlinkToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start,end, tokenType, so, true);
addToken(zzBuffer.toString().toCharArray(), start,end, tokenType, so, true);
}


Expand All @@ -95,7 +96,7 @@ import org.fife.ui.rsyntaxtextarea.*;
*/
private void addToken(int start, int end, int tokenType) {
int so = start + offsetShift;
addToken(zzBuffer, start,end, tokenType, so, false);
addToken(zzBuffer.toString().toCharArray(), start,end, tokenType, so, false);
}


Expand Down Expand Up @@ -142,27 +143,26 @@ import org.fife.ui.rsyntaxtextarea.*;
public Token getTokenList(Segment text, int initialTokenType, int startOffset) {

resetTokenList();
this.offsetShift = -text.offset + startOffset;
this.offsetShift = startOffset;

// Start off in the proper state.
int state = Token.NULL;
switch (initialTokenType) {
case Token.COMMENT_MULTILINE:
state = MLC;
start = text.offset;
start = 0;
break;
case Token.COMMENT_DOCUMENTATION:
state = DOCCOMMENT;
start = text.offset;
start = 0;
break;
default:
state = Token.NULL;
}

s = text;
try {
yyreset(zzReader);
yybegin(state);
reset(text, 0, text.count, state);
return yylex();
} catch (IOException ioe) {
ioe.printStackTrace();
Expand All @@ -172,51 +172,6 @@ import org.fife.ui.rsyntaxtextarea.*;
}


/**
* Refills the input buffer.
*
* Note: this is the correct zzRefill. Delete the other one.
*
* @return <code>true</code> if EOF was reached, otherwise
* <code>false</code>.
*/
private boolean zzRefill() {
return zzCurrentPos>=s.offset+s.count;
}


/**
* Resets the scanner to read from a new input stream.
* Does not close the old reader.
*
* All internal variables are reset, the old input stream
* <b>cannot</b> be reused (internal buffer is discarded and lost).
* Lexical state is set to <tt>YY_INITIAL</tt>.
*
* Note: this is the correct yyreset. Delete the other one.
*
* @param reader the new input stream
*/
public final void yyreset(Reader reader) {
// 's' has been updated.
zzBuffer = s.array;
/*
* We replaced the line below with the two below it because zzRefill
* no longer "refills" the buffer (since the way we do it, it's always
* "full" the first time through, since it points to the segment's
* array). So, we assign zzEndRead here.
*/
zzStartRead = zzEndRead = s.offset;
zzStartRead = s.offset;
zzEndRead = zzStartRead + s.count - 1;
zzCurrentPos = zzMarkedPos = s.offset;
zzLexicalState = YYINITIAL;
zzReader = reader;
zzAtBOL = true;
zzAtEOF = false;
}


%}

Letter = ([A-Za-z])
Expand Down Expand Up @@ -346,6 +301,7 @@ URL = (((https?|f(tp|ile))"://"|"www.")({URLCharacters}{URLEndCharacter})?)
"super" |
"switch" |
"synchronized" |
"synthetic" |
"this" |
"throw" |
"throws" |
Expand Down
Loading

0 comments on commit 9e7f396

Please sign in to comment.