Commit 6eb200a0 authored by Johannes Roith's avatar Johannes Roith
Browse files

Syntax highlighting for Java comments.

parent c7d5d101
......@@ -37,7 +37,7 @@ public class JavaScanner
private Lexer lexer;
public JavaScanner(Reader r) {
this.lexer = new Lexer(r);
this.lexer = new Lexer(r, true);
}
public JavaSymbol next_token() throws IOException {
......
......@@ -65,6 +65,12 @@ public class JavaSymbol {
return s.sym == Sym.BOOLEAN_LITERAL;
}
public boolean isComment() {
if (s == null)
return false;
return s.sym == Sym.COMMENT;
}
private static final HashSet<Integer> keywords = new HashSet<Integer>();
static {
......
......@@ -5,6 +5,7 @@ import java.io.Reader;
import java.io.LineNumberReader;
import java_cup.runtime.ComplexSymbolFactory;
import java_cup.runtime.Symbol;
import de.in.tum.www2.cup.ErrorManager;
import de.in.tum.www2.java.internal.onefivelexer.Sym;
......@@ -23,9 +24,11 @@ public class Lexer implements java_cup.runtime.Scanner {
int line_pos = 1;
int line_num = 0;
LineList lineL = new LineList(-line_pos, null); // sentinel for line #0
public Lexer(Reader reader) {
boolean acceptComments;
public Lexer(Reader reader, boolean acceptComments) {
this(reader, 2); // by default, use a Java 1.2-compatible lexer.
this.acceptComments = acceptComments;
}
public Lexer(Reader reader, int java_minor_version) {
this.reader = new LineNumberReader(new EscapedUnicodeReader(reader));
......@@ -104,11 +107,22 @@ public class Lexer implements java_cup.runtime.Scanner {
do {
startpos = lineL.head + line_pos;
ie = getInputElement();
if (ie instanceof DocumentationComment)
comment = ((Comment)ie).getComment();
if (ie instanceof DocumentationComment) {
comment = ((Comment)ie).getComment();
}
if (ie instanceof Comment && acceptComments)
break;
} while (!(ie instanceof Token));
endpos = lineL.head + line_pos - 1;
if (ie instanceof Comment) {
java_cup.runtime.Symbol sym = new Symbol(Sym.COMMENT, comment);
sym.left = startpos; sym.right = endpos;
return sym;
}
//System.out.println(ie.toString()); // uncomment to debug lexer.
java_cup.runtime.Symbol sym = ((Token)ie).token();
// fix up left/right positions.
......
package de.in.tum.www2.java.internal.onefivelexer;
public interface Sym {
// manually added.
public static final int COMMENT = 107;
/* terminals */
public static final int AT = 94;
public static final int SHORT = 4;
......@@ -216,7 +221,8 @@ public interface Sym {
"STRICTFP",
"ASSERT",
"ELLIPSIS",
"ENUM"
"ENUM",
"COMMENT"
};
}
......@@ -263,6 +263,9 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
}
}
static final Token javaComment = new Token(new TextAttribute(
CupTextEditor.COMMENT));
static final Token javaKeyword = new Token(new TextAttribute(
CupTextEditor.JAVA_KEYWORD));
......@@ -286,6 +289,9 @@ public class CupSourceViewerConfiguration extends SourceViewerConfiguration {
if (last.isEOF())
return Token.EOF;
if (last.isComment())
return javaComment;
if (last.isKeyword() || last.isBooleanLiteral() || last.isNullLiteral())
return javaKeyword;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment