diff --git a/AfterRewrite.php b/AfterRewrite.php new file mode 100755 index 0000000..ddeeab1 --- /dev/null +++ b/AfterRewrite.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php + 1) { + $line = str_replace("yyreset", "yyreset_GOMI", $line); + } + $out .= $line; + } else if (preg_match("/private boolean zzRefill\(/", $line)) { + $count_zzRefill++; + if ($count_zzRefill > 1) { + $line = str_replace("zzRefill", "zzRefill_GOMI", $line); + } + $out .= $line; + } else if (preg_match("/Character\.charCount\(zzInput\)/", $line)){ + $out .= "// ".$line; + } else if (preg_match("/if\ \(eof\)/", $line)){ + $passCheckpoint++; + $out .= $line; + } else { + if (preg_match("/zzInput = Character\.codePointAt\(zzBufferL\,\ zzCurrentPosL\,\ zzEndReadL\)/", $line)) { + $out .= " zzInput = zzBufferL[zzCurrentPosL++]; \n"; + } else { + $out .= $line; + } + } +} + +// もとのファイルに書き出し +// echo $out; +file_put_contents($argv[1], $out); +echo "Overwrote to {$argv[1]} .\n"; diff --git a/App.java b/App.java new file mode 100644 index 0000000..78dc59c --- /dev/null +++ b/App.java @@ -0,0 +1,14 @@ +package info.istlab.SyntaxEditor; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + StyleTestDemo.main(null); + } +} diff --git a/InMemJavaC.java b/InMemJavaC.java new file mode 100644 index 0000000..b2b8e74 --- /dev/null +++ b/InMemJavaC.java @@ -0,0 +1,20 @@ +package info.istlab.SyntaxEditor; + +import org.mdkt.compiler.InMemoryJavaCompiler; + +public class InMemJavaC { + + public InMemJavaC(String src){ + Class> helloClass; + try { + helloClass = InMemoryJavaCompiler.newInstance().compile("Hello", src ); + System.out.println(helloClass.getClass().getName()); + + System.out.println(helloClass.getDeclaredConstructor().newInstance().toString()); + } catch (Exception e1) { + e1.printStackTrace(); + } + + } + +} diff --git a/MyTokenMaker.java b/MyTokenMaker.java new file mode 100644 index 0000000..167f03c --- /dev/null +++ b/MyTokenMaker.java @@ -0,0 +1,1319 @@ +// DO NOT EDIT +// Generated by JFlex 1.8.2 http://jflex.de/ +// source: myTokenMaker.flex + +/* + * 11/13/2004 + * + * TokenMaker4MyRSJTextArea.java - Scanner for the Java programming language. + * + * This library is distributed under a modified BSD license. See the included + * LICENSE file for details. + */ +// package org.fife.ui.rsyntaxtextarea.modes; +package info.istlab.SyntaxEditor; + +import java.io.IOException; +import java.io.Reader; + +import javax.swing.text.Segment; + +import org.fife.ui.rsyntaxtextarea.AbstractJFlexCTokenMaker; +import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rsyntaxtextarea.TokenImpl; +import org.fife.ui.rsyntaxtextarea.TokenTypes; + + +/** + * Scanner for the Java programming language.
+ *
+ * This implementation was created using
+ * JFlex 1.4.1; however, the generated file
+ * was modified for performance. Memory allocation needs to be almost
+ * completely removed to be competitive with the handwritten lexers (subclasses
+ * of AbstractTokenMaker
), so this class has been modified so that
+ * Strings are never allocated (via yytext()), and the scanner never has to
+ * worry about refilling its buffer (needlessly copying chars around).
+ * We can achieve this because RText always scans exactly 1 line of tokens at a
+ * time, and hands the scanner this line as an array of characters (a Segment
+ * really). Since tokens contain pointers to char arrays instead of Strings
+ * holding their contents, there is no need for allocating new memory for
+ * Strings.
+ * + * The actual algorithm generated for scanning has, of course, not been + * modified.
+ * + * If you wish to regenerate this file yourself, keep in mind the following: + *
JavaTokenMaker.java
file will contain two
+ * definitions of both zzRefill
and yyreset
.
+ * You should hand-delete the second of each definition (the ones
+ * generated by the lexer), as these generated methods modify the input
+ * buffer, which we'll never have to do.yylex()
on the generated scanner
+ * directly; rather, you should use getTokenList
as you would
+ * with any other TokenMaker
instance.When a lead/high surrogate has been read from the input stream into the final
+ * {@link #zzBuffer} position, this will have a value of 1; otherwise, it will have a value of 0.
+ */
+ private int zzFinalHighSurrogate = 0;
+
+ /** Number of newlines encountered up to the start of the matched text. */
+ @SuppressWarnings("unused")
+ private int yyline;
+
+ /** Number of characters from the last newline up to the start of the matched text. */
+ @SuppressWarnings("unused")
+ private int yycolumn;
+
+ /** Number of characters up to the start of the matched text. */
+ @SuppressWarnings("unused")
+ private long yychar;
+
+ /** Whether the scanner is currently at the beginning of a line. */
+ @SuppressWarnings("unused")
+ private boolean zzAtBOL = true;
+
+ /** Whether the user-EOF-code has already been executed. */
+ @SuppressWarnings("unused")
+ private boolean zzEOFDone;
+
+ /* user code: */
+
+
+ /**
+ * Constructor. This must be here because JFlex does not generate a
+ * no-parameter constructor.
+ */
+ public MyTokenMaker() {
+ }
+
+
+ /**
+ * Adds the token specified to the current linked list of tokens.
+ *
+ * @param tokenType The token's type.
+ * @see #addToken(int, int, int)
+ */
+ private void addHyperlinkToken(int start, int end, int tokenType) {
+ int so = start + offsetShift;
+ addToken(zzBuffer, start,end, tokenType, so, true);
+ }
+
+
+ /**
+ * Adds the token specified to the current linked list of tokens.
+ *
+ * @param tokenType The token's type.
+ */
+ private void addToken(int tokenType) {
+ addToken(zzStartRead, zzMarkedPos-1, tokenType);
+ }
+
+
+ /**
+ * Adds the token specified to the current linked list of tokens.
+ *
+ * @param tokenType The token's type.
+ * @see #addHyperlinkToken(int, int, int)
+ */
+ private void addToken(int start, int end, int tokenType) {
+ int so = start + offsetShift;
+ addToken(zzBuffer, start,end, tokenType, so, false);
+ }
+
+
+ /**
+ * Adds the token specified to the current linked list of tokens.
+ *
+ * @param array The character array.
+ * @param start The starting offset in the array.
+ * @param end The ending offset in the array.
+ * @param tokenType The token's type.
+ * @param startOffset The offset in the document at which this token
+ * occurs.
+ * @param hyperlink Whether this token is a hyperlink.
+ */
+ @Override
+ public void addToken(char[] array, int start, int end, int tokenType,
+ int startOffset, boolean hyperlink) {
+ super.addToken(array, start,end, tokenType, startOffset, hyperlink);
+ zzStartRead = zzMarkedPos;
+ }
+
+
+ @Override
+ public String[] getLineCommentStartAndEnd(int languageIndex) {
+ return new String[] { "//", null };
+ }
+
+
+ /**
+ * Returns the first token in the linked list of tokens generated
+ * from text
. This method must be implemented by
+ * subclasses so they can correctly implement syntax highlighting.
+ *
+ * @param text The text from which to get tokens.
+ * @param initialTokenType The token type we should start with.
+ * @param startOffset The offset into the document at which
+ * text
starts.
+ * @return The first Token
in a linked list representing
+ * the syntax highlighted text.
+ */
+ public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
+
+ resetTokenList();
+ this.offsetShift = -text.offset + startOffset;
+
+ // Start off in the proper state.
+ int state;
+ switch (initialTokenType) {
+ case TokenTypes.COMMENT_MULTILINE:
+ state = MLC;
+ start = text.offset;
+ break;
+ case TokenTypes.COMMENT_DOCUMENTATION:
+ state = DOCCOMMENT;
+ start = text.offset;
+ break;
+ case TokenTypes.LITERAL_STRING_DOUBLE_QUOTE:
+ state = TEXT_BLOCK;
+ start = text.offset;
+ break;
+ default:
+ state = YYINITIAL;
+ }
+
+ s = text;
+ try {
+ yyreset(zzReader);
+ yybegin(state);
+ return yylex();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ return new TokenImpl();
+ }
+
+ }
+
+
+ /**
+ * Refills the input buffer.
+ *
+ * @return true
if EOF was reached, otherwise
+ * false
.
+ */
+ 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
+ * cannot be reused (internal buffer is discarded and lost).
+ * Lexical state is set to YY_INITIAL.
+ *
+ * @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;
+ }
+
+
+
+
+ /**
+ * Creates a new scanner
+ *
+ * @param in the java.io.Reader to read input from.
+ */
+ public MyTokenMaker(java.io.Reader in) {
+ this.zzReader = in;
+ }
+
+ /**
+ * Translates raw input code points to DFA table row
+ */
+ private static int zzCMap(int input) {
+ int offset = input & 255;
+ return offset == input ? ZZ_CMAP_BLOCKS[offset] : ZZ_CMAP_BLOCKS[ZZ_CMAP_TOP[input >> 8] | offset];
+ }
+
+ /**
+ * Refills the input buffer.
+ *
+ * @return {@code false} iff there was new input.
+ * @exception java.io.IOException if any I/O-Error occurs
+ */
+ private boolean zzRefill_GOMI() throws java.io.IOException {
+
+ /* first: make room (if you can) */
+ if (zzStartRead > 0) {
+ zzEndRead += zzFinalHighSurrogate;
+ zzFinalHighSurrogate = 0;
+ System.arraycopy(zzBuffer, zzStartRead,
+ zzBuffer, 0,
+ zzEndRead - zzStartRead);
+
+ /* translate stored positions */
+ zzEndRead -= zzStartRead;
+ zzCurrentPos -= zzStartRead;
+ zzMarkedPos -= zzStartRead;
+ zzStartRead = 0;
+ }
+
+ /* is the buffer big enough? */
+ if (zzCurrentPos >= zzBuffer.length - zzFinalHighSurrogate) {
+ /* if not: blow it up */
+ char newBuffer[] = new char[zzBuffer.length * 2];
+ System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
+ zzBuffer = newBuffer;
+ zzEndRead += zzFinalHighSurrogate;
+ zzFinalHighSurrogate = 0;
+ }
+
+ /* fill the buffer with new input */
+ int requested = zzBuffer.length - zzEndRead;
+ int numRead = zzReader.read(zzBuffer, zzEndRead, requested);
+
+ /* not supposed to occur according to specification of java.io.Reader */
+ if (numRead == 0) {
+ throw new java.io.IOException(
+ "Reader returned 0 characters. See JFlex examples/zero-reader for a workaround.");
+ }
+ if (numRead > 0) {
+ zzEndRead += numRead;
+ if (Character.isHighSurrogate(zzBuffer[zzEndRead - 1])) {
+ if (numRead == requested) { // We requested too few chars to encode a full Unicode character
+ --zzEndRead;
+ zzFinalHighSurrogate = 1;
+ } else { // There is room in the buffer for at least one more char
+ int c = zzReader.read(); // Expecting to read a paired low surrogate char
+ if (c == -1) {
+ return true;
+ } else {
+ zzBuffer[zzEndRead++] = (char)c;
+ }
+ }
+ }
+ /* potentially more input available */
+ return false;
+ }
+
+ /* numRead < 0 ==> end of stream */
+ return true;
+ }
+
+
+ /**
+ * Closes the input reader.
+ *
+ * @throws java.io.IOException if the reader could not be closed.
+ */
+ public final void yyclose() throws java.io.IOException {
+ zzAtEOF = true; // indicate end of file
+ zzEndRead = zzStartRead; // invalidate buffer
+
+ if (zzReader != null) {
+ zzReader.close();
+ }
+ }
+
+
+ /**
+ * 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 cannot be reused (internal + * buffer is discarded and lost). Lexical state is set to {@code ZZ_INITIAL}. + * + *
Internal scan buffer is resized down to its initial length, if it has grown. + * + * @param reader The new input stream. + */ + public final void yyreset_GOMI(java.io.Reader reader) { + zzReader = reader; + zzEOFDone = false; + yyResetPosition(); + zzLexicalState = YYINITIAL; + if (zzBuffer.length > ZZ_BUFFERSIZE) { + zzBuffer = new char[ZZ_BUFFERSIZE]; + } + } + + /** + * Resets the input position. + */ + private final void yyResetPosition() { + zzAtBOL = true; + zzAtEOF = false; + zzCurrentPos = 0; + zzMarkedPos = 0; + zzStartRead = 0; + zzEndRead = 0; + zzFinalHighSurrogate = 0; + yyline = 0; + yycolumn = 0; + yychar = 0L; + } + + + /** + * Returns whether the scanner has reached the end of the reader it reads from. + * + * @return whether the scanner has reached EOF. + */ + public final boolean yyatEOF() { + return zzAtEOF; + } + + + /** + * Returns the current lexical state. + * + * @return the current lexical state. + */ + public final int yystate() { + return zzLexicalState; + } + + + /** + * Enters a new lexical state. + * + * @param newState the new lexical state + */ + public final void yybegin(int newState) { + zzLexicalState = newState; + } + + + /** + * Returns the text matched by the current regular expression. + * + * @return the matched text. + */ + public final String yytext() { + return new String(zzBuffer, zzStartRead, zzMarkedPos-zzStartRead); + } + + + /** + * Returns the character at the given position from the matched text. + * + *
It is equivalent to {@code yytext().charAt(pos)}, but faster. + * + * @param position the position of the character to fetch. A value from 0 to {@code yylength()-1}. + * + * @return the character at {@code position}. + */ + public final char yycharat(int position) { + return zzBuffer[zzStartRead + position]; + } + + + /** + * How many characters were matched. + * + * @return the length of the matched text region. + */ + public final int yylength() { + return zzMarkedPos-zzStartRead; + } + + + /** + * Reports an error that occurred while scanning. + * + *
In a well-formed scanner (no or only correct usage of {@code yypushback(int)} and a + * match-all fallback rule) this method will only be called with things that + * "Can't Possibly Happen". + * + *
If this method is called, something is seriously wrong (e.g. a JFlex bug producing a faulty + * scanner etc.). + * + *
Usual syntax/scanner level error handling should be done in error fallback rules. + * + * @param errorCode the code of the error message to display. + */ + private static void zzScanError(int errorCode) { + String message; + try { + message = ZZ_ERROR_MSG[errorCode]; + } catch (ArrayIndexOutOfBoundsException e) { + message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; + } + + throw new Error(message); + } + + + /** + * Pushes the specified amount of characters back into the input stream. + * + *
They will be read again by then next call of the scanning method. + * + * @param number the number of characters to be read again. This number must not be greater than + * {@link #yylength()}. + */ + public void yypushback(int number) { + if ( number > yylength() ) + zzScanError(ZZ_PUSHBACK_2BIG); + + zzMarkedPos -= number; + } + + + + + /** + * Resumes scanning until the next regular expression is matched, the end of input is encountered + * or an I/O-Error occurs. + * + * @return the next token. + * @exception java.io.IOException if any I/O-Error occurs. + */ + public org.fife.ui.rsyntaxtextarea.Token yylex() throws java.io.IOException { + int zzInput; + int zzAction; + + // cached fields: + int zzCurrentPosL; + int zzMarkedPosL; + int zzEndReadL = zzEndRead; + char[] zzBufferL = zzBuffer; + + int [] zzTransL = ZZ_TRANS; + int [] zzRowMapL = ZZ_ROWMAP; + int [] zzAttrL = ZZ_ATTRIBUTE; + + while (true) { + zzMarkedPosL = zzMarkedPos; + + zzAction = -1; + + zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; + + zzState = ZZ_LEXSTATE[zzLexicalState]; + + // set up zzAction for empty match case: + int zzAttributes = zzAttrL[zzState]; + if ( (zzAttributes & 1) == 1 ) { + zzAction = zzState; + } + + + zzForAction: { + while (true) { + + if (zzCurrentPosL < zzEndReadL) { + zzInput = zzBufferL[zzCurrentPosL++]; +// zzCurrentPosL += Character.charCount(zzInput); + } + else if (zzAtEOF) { + zzInput = YYEOF; + break zzForAction; + } + else { + // store back cached positions + zzCurrentPos = zzCurrentPosL; + zzMarkedPos = zzMarkedPosL; + boolean eof = zzRefill(); + // get translated positions and possibly new buffer + zzCurrentPosL = zzCurrentPos; + zzMarkedPosL = zzMarkedPos; + zzBufferL = zzBuffer; + zzEndReadL = zzEndRead; + if (eof) { + zzInput = YYEOF; + break zzForAction; + } + else { + zzInput = zzBufferL[zzCurrentPosL++]; +// zzCurrentPosL += Character.charCount(zzInput); + } + } + int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMap(zzInput) ]; + if (zzNext == -1) break zzForAction; + zzState = zzNext; + + zzAttributes = zzAttrL[zzState]; + if ( (zzAttributes & 1) == 1 ) { + zzAction = zzState; + zzMarkedPosL = zzCurrentPosL; + if ( (zzAttributes & 8) == 8 ) break zzForAction; + } + + } + } + + // store back cached position + zzMarkedPos = zzMarkedPosL; + + if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { + zzAtEOF = true; + switch (zzLexicalState) { + case YYINITIAL: { + addNullToken(); return firstToken; + } // fall though + case 180: break; + case MLC: { + addToken(start,zzStartRead-1, TokenTypes.COMMENT_MULTILINE); return firstToken; + } // fall though + case 181: break; + case DOCCOMMENT: { + yybegin(YYINITIAL); addToken(start,zzEndRead, TokenTypes.COMMENT_DOCUMENTATION); return firstToken; + } // fall though + case 182: break; + case EOL_COMMENT: { + addToken(start,zzStartRead-1, TokenTypes.COMMENT_EOL); addNullToken(); return firstToken; + } // fall though + case 183: break; + case TEXT_BLOCK: { + addToken(start,zzStartRead-1, TokenTypes.LITERAL_STRING_DOUBLE_QUOTE); return firstToken; + } // fall though + case 184: break; + default: + return null; + } + } + else { + switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { + case 1: + { + } + // fall through + case 21: break; + case 2: + { addToken(TokenTypes.IDENTIFIER); + } + // fall through + case 22: break; + case 3: + { addToken(TokenTypes.WHITESPACE); + } + // fall through + case 23: break; + case 4: + { addNullToken(); return firstToken; + } + // fall through + case 24: break; + case 5: + { addToken(TokenTypes.ANNOTATION); + } + // fall through + case 25: break; + case 6: + { addToken(start,zzStartRead-1, TokenTypes.COMMENT_MULTILINE); return firstToken; + } + // fall through + case 26: break; + case 7: + { addToken(start,zzStartRead-1, TokenTypes.COMMENT_DOCUMENTATION); return firstToken; + } + // fall through + case 27: break; + case 8: + { addToken(start,zzStartRead-1, TokenTypes.COMMENT_EOL); addNullToken(); return firstToken; + } + // fall through + case 28: break; + case 9: + { addToken(start,zzStartRead-1, TokenTypes.LITERAL_STRING_DOUBLE_QUOTE); return firstToken; + } + // fall through + case 29: break; + case 10: + { /* Skip escaped chars, handles case: '\"""'. */ + } + // fall through + case 30: break; + case 11: + { start = zzMarkedPos-2; yybegin(MLC); + } + // fall through + case 31: break; + case 12: + { start = zzMarkedPos-2; yybegin(EOL_COMMENT); + } + // fall through + case 32: break; + case 13: + { yybegin(YYINITIAL); addToken(start,zzStartRead+1, TokenTypes.COMMENT_MULTILINE); + } + // fall through + case 33: break; + case 14: + { yybegin(YYINITIAL); addToken(start,zzStartRead+1, TokenTypes.COMMENT_DOCUMENTATION); + } + // fall through + case 34: break; + case 15: + { int temp=zzStartRead; addToken(start,zzStartRead-1, TokenTypes.COMMENT_DOCUMENTATION); addToken(temp,zzMarkedPos-1, TokenTypes.COMMENT_MARKUP); start = zzMarkedPos; + } + // fall through + case 35: break; + case 16: + { start = zzMarkedPos-3; yybegin(DOCCOMMENT); + } + // fall through + case 36: break; + case 17: + { yybegin(YYINITIAL); addToken(start,zzStartRead+2, TokenTypes.LITERAL_STRING_DOUBLE_QUOTE); + } + // fall through + case 37: break; + case 18: + { addToken(TokenTypes.COMMENT_MULTILINE); + } + // fall through + case 38: break; + case 19: + { addToken(TokenTypes.COMMENT_EOL); + } + // fall through + case 39: break; + case 20: + { int temp = zzStartRead; + if (start <= zzStartRead - 1) { + addToken(start,zzStartRead-1, TokenTypes.COMMENT_DOCUMENTATION); + } + addToken(temp,zzMarkedPos-1, TokenTypes.COMMENT_KEYWORD); + start = zzMarkedPos; + } + // fall through + case 40: break; + default: + zzScanError(ZZ_NO_MATCH); + } + } + } + } + + +} diff --git a/StyleTestDemo.java b/StyleTestDemo.java new file mode 100644 index 0000000..95f9cd0 --- /dev/null +++ b/StyleTestDemo.java @@ -0,0 +1,128 @@ +package info.istlab.SyntaxEditor; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.plaf.FontUIResource; + +import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; +import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; +import org.fife.ui.rsyntaxtextarea.SyntaxScheme; +import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rsyntaxtextarea.TokenMakerFactory; + +public class StyleTestDemo extends JFrame { + + RSyntaxTextArea textArea; + AbstractTokenMakerFactory atmf; + + public StyleTestDemo() { + + JPanel contentPane = new JPanel(new BorderLayout()); + textArea = new RSyntaxTextArea(); + + String[] syntaxis = new String[] { "My"}; + atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance(); + for (String syn : syntaxis) { + atmf.putMapping("text/" + syn, "info.istlab.SyntaxEditor." + syn + "TokenMaker"); + } + textArea.setSyntaxEditingStyle("text/" + syntaxis[0]); + + // textArea.setCurrentLineHighlightColor(null); // カーソル行のハイライト色 + textArea.setHighlightCurrentLine(false); // カーソル行のハイライトを消す + // textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); + + SyntaxScheme scheme = textArea.getSyntaxScheme(); + scheme.getStyle(Token.COMMENT_EOL).background = Color.cyan; + scheme.getStyle(Token.COMMENT_DOCUMENTATION).background = Color.cyan.brighter(); + scheme.getStyle(Token.COMMENT_KEYWORD).background = Color.green; + scheme.getStyle(Token.COMMENT_MARKUP).background = Color.gray; + scheme.getStyle(Token.COMMENT_MULTILINE).background = Color.yellow; + + textArea.setText("initial text /*.java \ncomment // com\n https://www.istlab.info/ \n aaa /** asdf\n aaa \n */ \n aaa /* asdf\n aaa \n */ \n" + + "== コンパイル開始 ==\n> cd ~/NWP/src\n> javac -encoding UTF-8 j1/*.java\n==== end ===\n=== コンパイル終了 == (ALT+Wで閉じる)\n"); + // textArea.setText("abc"); + textArea.revalidate(); + + // textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); + textArea.setCodeFoldingEnabled(true); + textArea.setFont(new FontUIResource("sansserif", Font.PLAIN, 20)); + // contentPane.add(new RTextScrollPane(textArea, false)); // 行番号を消す + + setContentPane(contentPane); + setTitle("MySyntax Demo"); + setDefaultCloseOperation(EXIT_ON_CLOSE); //ウィンドウのXを押したらプログラムを終了する + + JPanel north = new JPanel(); + JButton loadB = new JButton("Load"); + loadB.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + InputStream is = getClass().getResourceAsStream("/Hello.java"); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + StringBuilder sb = new StringBuilder(); + String line; + try { + while ((line = br.readLine()) != null) { + sb.append(line + "\n"); + } + } catch (IOException e1) { + e1.printStackTrace(); + } + textArea.setText(sb.toString()); + + } + }); + north.add(loadB); + + JButton saveB = new JButton("Save"); + saveB.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + System.out.println(textArea.getText()); + } + }); + north.add(saveB); + + JButton execB = new JButton("Exec"); + execB.addActionListener(e -> new InMemJavaC(textArea.getText())); + north.add(execB); + + for(String syn: syntaxis){ + JButton javaB = new JButton(syn); + javaB.addActionListener(e -> { + textArea.setSyntaxEditingStyle("text/"+syn); + }); + north.add(javaB); + } + + add(north, BorderLayout.NORTH); + pack(); + setLocationRelativeTo(null); + + } + + public static void main(String[] args) { + // Instantiate GUI on the EDT. + SwingUtilities.invokeLater(() -> { + try { + String laf = UIManager.getSystemLookAndFeelClassName(); + UIManager.setLookAndFeel(laf); + } catch (Exception e) { + /* Never happens */ } + new StyleTestDemo().setVisible(true); + }); + } +} \ No newline at end of file diff --git a/myTokenMaker.flex b/myTokenMaker.flex new file mode 100644 index 0000000..ccdc4f4 --- /dev/null +++ b/myTokenMaker.flex @@ -0,0 +1,419 @@ +/* + * 11/13/2004 + * + * TokenMaker4MyRSJTextArea.java - Scanner for the Java programming language. + * + * This library is distributed under a modified BSD license. See the included + * LICENSE file for details. + */ +// package org.fife.ui.rsyntaxtextarea.modes; +package info.istlab.SyntaxEditor; + +import java.io.*; +import javax.swing.text.Segment; + +import org.fife.ui.rsyntaxtextarea.*; + + +/** + * Scanner for the Java programming language.
+ *
+ * This implementation was created using
+ * JFlex 1.4.1; however, the generated file
+ * was modified for performance. Memory allocation needs to be almost
+ * completely removed to be competitive with the handwritten lexers (subclasses
+ * of AbstractTokenMaker
), so this class has been modified so that
+ * Strings are never allocated (via yytext()), and the scanner never has to
+ * worry about refilling its buffer (needlessly copying chars around).
+ * We can achieve this because RText always scans exactly 1 line of tokens at a
+ * time, and hands the scanner this line as an array of characters (a Segment
+ * really). Since tokens contain pointers to char arrays instead of Strings
+ * holding their contents, there is no need for allocating new memory for
+ * Strings.
+ * + * The actual algorithm generated for scanning has, of course, not been + * modified.
+ * + * If you wish to regenerate this file yourself, keep in mind the following: + *
JavaTokenMaker.java
file will contain two
+ * definitions of both zzRefill
and yyreset
.
+ * You should hand-delete the second of each definition (the ones
+ * generated by the lexer), as these generated methods modify the input
+ * buffer, which we'll never have to do.yylex()
on the generated scanner
+ * directly; rather, you should use getTokenList
as you would
+ * with any other TokenMaker
instance.text
. This method must be implemented by
+ * subclasses so they can correctly implement syntax highlighting.
+ *
+ * @param text The text from which to get tokens.
+ * @param initialTokenType The token type we should start with.
+ * @param startOffset The offset into the document at which
+ * text
starts.
+ * @return The first Token
in a linked list representing
+ * the syntax highlighted text.
+ */
+ public Token getTokenList(Segment text, int initialTokenType, int startOffset) {
+
+ resetTokenList();
+ this.offsetShift = -text.offset + startOffset;
+
+ // Start off in the proper state.
+ int state;
+ switch (initialTokenType) {
+ case TokenTypes.COMMENT_MULTILINE:
+ state = MLC;
+ start = text.offset;
+ break;
+ case TokenTypes.COMMENT_DOCUMENTATION:
+ state = DOCCOMMENT;
+ start = text.offset;
+ break;
+ case TokenTypes.LITERAL_STRING_DOUBLE_QUOTE:
+ state = TEXT_BLOCK;
+ start = text.offset;
+ break;
+ default:
+ state = YYINITIAL;
+ }
+
+ s = text;
+ try {
+ yyreset(zzReader);
+ yybegin(state);
+ return yylex();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ return new TokenImpl();
+ }
+
+ }
+
+
+ /**
+ * Refills the input buffer.
+ *
+ * @return true
if EOF was reached, otherwise
+ * false
.
+ */
+ 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
+ * cannot be reused (internal buffer is discarded and lost).
+ * Lexical state is set to YY_INITIAL.
+ *
+ * @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])
+LetterOrUnderscore = ({Letter}|"_")
+NonzeroDigit = ([1-9])
+BinaryDigit = ([0-1])
+Digit = ("0"|{NonzeroDigit})
+HexDigit = ({Digit}|[A-Fa-f])
+OctalDigit = ([0-7])
+AnyCharacterButApostropheOrBackSlash = ([^\\'])
+AnyCharacterButDoubleQuoteOrBackSlash = ([^\\\"\n])
+EscapedSourceCharacter = ("u"{HexDigit}{HexDigit}{HexDigit}{HexDigit})
+Escape = ("\\"(([bstnfr\"'\\])|([0123]{OctalDigit}?{OctalDigit}?)|({OctalDigit}{OctalDigit}?)|{EscapedSourceCharacter}))
+NonSeparator = ([^\t\f\r\n\ \(\)\{\}\[\]\;\,\.\=\>\<\!\~\?\:\+\-\*\/\&\|\^\%\"\']|"#"|"\\")
+IdentifierStart = ([:jletter:])
+IdentifierPart = ([:jletterdigit:]|("\\"{EscapedSourceCharacter}))
+
+LineTerminator = (\n)
+WhiteSpace = ([ \t\f])
+
+CharLiteral = ([\']({AnyCharacterButApostropheOrBackSlash}|{Escape})[\'])
+UnclosedCharLiteral = ([\'][^\'\n]*)
+ErrorCharLiteral = ({UnclosedCharLiteral}[\'])
+StringLiteral = ([\"]({AnyCharacterButDoubleQuoteOrBackSlash}|{Escape})*[\"])
+UnclosedStringLiteral = ([\"]([\\].|[^\\\"])*[^\"]?)
+ErrorStringLiteral = ({UnclosedStringLiteral}[\"])
+
+MLCBegin = "/*"
+MLCEnd = "*/"
+DocCommentBegin = "/**"
+LineCommentBegin = "//"
+/*LineCommentBegin = ("//"|"===")*/
+MessageBegin = "==="([^\n\(\)]+)
+CommandEcho = ">\ "([^\n\)]+)
+
+DigitOrUnderscore = ({Digit}|[_])
+DigitsAndUnderscoresEnd = ({DigitOrUnderscore}*{Digit})
+IntegerHelper = (({NonzeroDigit}{DigitsAndUnderscoresEnd}?)|"0")
+IntegerLiteral = ({IntegerHelper}[lL]?)
+
+BinaryDigitOrUnderscore = ({BinaryDigit}|[_])
+BinaryDigitsAndUnderscores = ({BinaryDigit}({BinaryDigitOrUnderscore}*{BinaryDigit})?)
+BinaryLiteral = ("0"[bB]{BinaryDigitsAndUnderscores})
+
+HexDigitOrUnderscore = ({HexDigit}|[_])
+HexDigitsAndUnderscores = ({HexDigit}({HexDigitOrUnderscore}*{HexDigit})?)
+OctalDigitOrUnderscore = ({OctalDigit}|[_])
+OctalDigitsAndUnderscoresEnd= ({OctalDigitOrUnderscore}*{OctalDigit})
+HexHelper = ("0"(([xX]{HexDigitsAndUnderscores})|({OctalDigitsAndUnderscoresEnd})))
+HexLiteral = ({HexHelper}[lL]?)
+
+FloatHelper1 = ([fFdD]?)
+FloatHelper2 = ([eE][+-]?{Digit}+{FloatHelper1})
+FloatLiteral1 = ({Digit}+"."({FloatHelper1}|{FloatHelper2}|{Digit}+({FloatHelper1}|{FloatHelper2})))
+FloatLiteral2 = ("."{Digit}+({FloatHelper1}|{FloatHelper2}))
+FloatLiteral3 = ({Digit}+{FloatHelper2})
+FloatLiteral = ({FloatLiteral1}|{FloatLiteral2}|{FloatLiteral3}|({Digit}+[fFdD]))
+
+ErrorNumberFormat = (({IntegerLiteral}|{HexLiteral}|{FloatLiteral}){NonSeparator}+)
+BooleanLiteral = ("true"|"false")
+
+Separator = ([\(\)\{\}\[\]])
+Separator2 = ([\;,.])
+
+NonAssignmentOperator = ("+"|"-"|"<="|"^"|"++"|"<"|"*"|">="|"%"|"--"|">"|"/"|"!="|"?"|">>"|"!"|"&"|"=="|":"|">>"|"~"|"|"|"&&"|">>>")
+AssignmentOperator = ("="|"-="|"*="|"/="|"|="|"&="|"^="|"+="|"%="|"<<="|">>="|">>>=")
+Operator = ({NonAssignmentOperator}|{AssignmentOperator})
+
+CurrentBlockTag = ("author"|"deprecated"|"exception"|"param"|"return"|"see"|"serial"|"serialData"|"serialField"|"since"|"throws"|"version")
+ProposedBlockTag = ("category"|"example"|"tutorial"|"index"|"exclude"|"todo"|"internal"|"obsolete"|"threadsafety")
+BlockTag = ({CurrentBlockTag}|{ProposedBlockTag})
+InlineTag = ("code"|"docRoot"|"inheritDoc"|"link"|"linkplain"|"literal"|"value")
+
+Identifier = ({IdentifierStart}{IdentifierPart}*)
+ErrorIdentifier = ({NonSeparator}+)
+
+Annotation = ("@"{Identifier}?)
+
+URLGenDelim = ([:\/\?#\[\]@])
+URLSubDelim = ([\!\$&'\(\)\*\+,;=])
+URLUnreserved = ({LetterOrUnderscore}|{Digit}|[\-\.\~])
+URLCharacter = ({URLGenDelim}|{URLSubDelim}|{URLUnreserved}|[%])
+URLCharacters = ({URLCharacter}*)
+URLEndCharacter = ([\/\$]|{Letter}|{Digit})
+/* URL = (((https?|f(tp|ile))"://"|"www.")({URLCharacters}{URLEndCharacter})?) */
+
+
+%state MLC
+%state DOCCOMMENT
+%state EOL_COMMENT
+%state TEXT_BLOCK
+
+%%
+
+