Support line numbers in grammar generator
This commit is contained in:
@@ -20,8 +20,8 @@ package org.jetbrains.jet.grammar;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class Annotation extends Token {
|
||||
public Annotation(CharSequence text) {
|
||||
super(text);
|
||||
public Annotation(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,8 +20,8 @@ package org.jetbrains.jet.grammar;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class Comment extends Token {
|
||||
public Comment(CharSequence text) {
|
||||
super(text);
|
||||
public Comment(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ConfluenceHyperlinksGenerator {
|
||||
result.append("{anchor:").append(declaration.getName()).append("}");
|
||||
if (!usedSymbols.contains(declaration.getName())) {
|
||||
// result.append("(!) *Unused!* ");
|
||||
System.out.println("Unused: " + token);
|
||||
System.out.println("Unused: " + token + " at line " + token.getLine());
|
||||
}
|
||||
Collection<String> myUsages = usages.get(declaration.getName());
|
||||
if (!myUsages.isEmpty()) {
|
||||
@@ -165,7 +165,7 @@ public class ConfluenceHyperlinksGenerator {
|
||||
Identifier identifier = (Identifier) token;
|
||||
if (!declaredSymbols.contains(identifier.getName())) {
|
||||
result.append("(!) *Undeclared!* ");
|
||||
System.out.println("Undeclared: " + token);
|
||||
System.out.println("Undeclared: " + token + " at line " + token.getLine());
|
||||
}
|
||||
}
|
||||
result.append(token);
|
||||
|
||||
@@ -22,8 +22,8 @@ package org.jetbrains.jet.grammar;
|
||||
public class Declaration extends Token {
|
||||
private final String name;
|
||||
|
||||
public Declaration(CharSequence text) {
|
||||
super(text);
|
||||
public Declaration(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
name = text.toString().substring(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ package org.jetbrains.jet.grammar;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class DocComment extends Token {
|
||||
public DocComment(CharSequence text) {
|
||||
super(text);
|
||||
public DocComment(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,12 @@ package org.jetbrains.jet.grammar;
|
||||
|
||||
%unicode
|
||||
%class _GrammarLexer
|
||||
%{
|
||||
private int line = 1;
|
||||
public int getCurrentLine() {
|
||||
return line;
|
||||
}
|
||||
%}
|
||||
%function advance
|
||||
%type Token
|
||||
%eof{ return;
|
||||
@@ -71,32 +77,33 @@ RAW_STRING_LITERAL = {THREE_QUO} {QUO_STRING_CHAR}* {THREE_QUO}?
|
||||
|
||||
%%
|
||||
|
||||
<YYINITIAL> {BLOCK_COMMENT} { return new Comment(yytext()); }
|
||||
<YYINITIAL> {DOC_COMMENT} { return new DocComment(yytext()); }
|
||||
<YYINITIAL> {BLOCK_COMMENT} { return new Comment(yytext(), line); }
|
||||
<YYINITIAL> {DOC_COMMENT} { return new DocComment(yytext(), line); }
|
||||
|
||||
<YYINITIAL> ({WHITE_SPACE_CHAR})+ { return new WhiteSpace(yytext()); }
|
||||
<YYINITIAL> "\n" | "\r" { line++; return new WhiteSpace(yytext(), line); }
|
||||
<YYINITIAL> ({WHITE_SPACE_CHAR})+ { return new WhiteSpace(yytext(), line); }
|
||||
|
||||
<YYINITIAL> {EOL_COMMENT} { return new Comment(yytext()); }
|
||||
<YYINITIAL> {EOL_COMMENT} { return new Comment(yytext(), line); }
|
||||
|
||||
<YYINITIAL> {STRING_LITERAL} { return new StringToken(yytext()); }
|
||||
<YYINITIAL> {ANGLE_STRING_LITERAL} { return new StringToken(yytext()); }
|
||||
<YYINITIAL> {IDENTIFIER} { return new Identifier(yytext()); }
|
||||
<YYINITIAL> "[" {IDENTIFIER} "]" { return new Annotation(yytext()); }
|
||||
<YYINITIAL> {DECLARATION_IDENTIFIER} { return new Declaration(yytext()); }
|
||||
<YYINITIAL> {STRING_LITERAL} { return new StringToken(yytext(), line); }
|
||||
<YYINITIAL> {ANGLE_STRING_LITERAL} { return new StringToken(yytext(), line); }
|
||||
<YYINITIAL> {IDENTIFIER} { return new Identifier(yytext(), line); }
|
||||
<YYINITIAL> "[" {IDENTIFIER} "]" { return new Annotation(yytext(), line); }
|
||||
<YYINITIAL> {DECLARATION_IDENTIFIER} { return new Declaration(yytext(), line); }
|
||||
|
||||
<YYINITIAL> ":" { return new SymbolToken(yytext()); }
|
||||
<YYINITIAL> "{" { return new SymbolToken("\\" + yytext()); }
|
||||
<YYINITIAL> "}" { return new SymbolToken("\\" + yytext()); }
|
||||
<YYINITIAL> "[" { return new SymbolToken("\\" + yytext()); }
|
||||
<YYINITIAL> "]" { return new SymbolToken("\\" + yytext()); }
|
||||
<YYINITIAL> "(" { return new SymbolToken("\\" + yytext()); }
|
||||
<YYINITIAL> ")" { return new SymbolToken("\\" + yytext()); }
|
||||
<YYINITIAL> "*" { return new SymbolToken(yytext()); }
|
||||
<YYINITIAL> "+" { return new SymbolToken(yytext()); }
|
||||
<YYINITIAL> "?" { return new SymbolToken(yytext()); }
|
||||
<YYINITIAL> "|" { return new SymbolToken(yytext()); }
|
||||
<YYINITIAL> "-" { return new SymbolToken(yytext()); }
|
||||
<YYINITIAL> "." { return new SymbolToken(yytext()); }
|
||||
<YYINITIAL> ":" { return new SymbolToken(yytext(), line); }
|
||||
<YYINITIAL> "{" { return new SymbolToken("\\" + yytext(), line); }
|
||||
<YYINITIAL> "}" { return new SymbolToken("\\" + yytext(), line); }
|
||||
<YYINITIAL> "[" { return new SymbolToken("\\" + yytext(), line); }
|
||||
<YYINITIAL> "]" { return new SymbolToken("\\" + yytext(), line); }
|
||||
<YYINITIAL> "(" { return new SymbolToken("\\" + yytext(), line); }
|
||||
<YYINITIAL> ")" { return new SymbolToken("\\" + yytext(), line); }
|
||||
<YYINITIAL> "*" { return new SymbolToken(yytext(), line); }
|
||||
<YYINITIAL> "+" { return new SymbolToken(yytext(), line); }
|
||||
<YYINITIAL> "?" { return new SymbolToken(yytext(), line); }
|
||||
<YYINITIAL> "|" { return new SymbolToken(yytext(), line); }
|
||||
<YYINITIAL> "-" { return new SymbolToken(yytext(), line); }
|
||||
<YYINITIAL> "." { return new SymbolToken(yytext(), line); }
|
||||
|
||||
<YYINITIAL> . { return new Other(yytext()); }
|
||||
<YYINITIAL> . { return new Other(yytext(), line); }
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ package org.jetbrains.jet.grammar;
|
||||
public class Identifier extends Token {
|
||||
private final String name;
|
||||
|
||||
public Identifier(CharSequence text) {
|
||||
super(text);
|
||||
public Identifier(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
name = text.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package org.jetbrains.jet.grammar;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class Other extends Token {
|
||||
public Other(CharSequence text) {
|
||||
super(text);
|
||||
public Other(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ package org.jetbrains.jet.grammar;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class StringToken extends Token {
|
||||
public StringToken(CharSequence text) {
|
||||
super(text);
|
||||
public StringToken(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,8 +20,8 @@ package org.jetbrains.jet.grammar;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class SymbolToken extends Token {
|
||||
public SymbolToken(CharSequence text) {
|
||||
super(text);
|
||||
public SymbolToken(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,15 +21,20 @@ package org.jetbrains.jet.grammar;
|
||||
*/
|
||||
public class Token {
|
||||
private final CharSequence text;
|
||||
private final int line;
|
||||
|
||||
public Token(CharSequence text) {
|
||||
public Token(CharSequence text, int line) {
|
||||
this.text = text;
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public CharSequence getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -20,8 +20,8 @@ package org.jetbrains.jet.grammar;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class WhiteSpace extends Token {
|
||||
public WhiteSpace(CharSequence text) {
|
||||
super(text);
|
||||
public WhiteSpace(CharSequence text, int line) {
|
||||
super(text, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,20 +1,4 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* The following code was generated by JFlex 1.4.3 on 9/9/11 9:32 PM */
|
||||
/* The following code was generated by JFlex 1.4.3 on 8/31/12 2:58 PM */
|
||||
|
||||
/* It's an automatically generated code. Do not modify it. */
|
||||
package org.jetbrains.jet.grammar;
|
||||
@@ -29,8 +13,8 @@ package org.jetbrains.jet.grammar;
|
||||
/**
|
||||
* This class is a scanner generated by
|
||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||
* on 9/9/11 9:32 PM from the specification file
|
||||
* <tt>/Users/abreslav/work/jet/grammar/src/org/jetbrains/jet/grammar/Grammar.flex</tt>
|
||||
* on 8/31/12 2:58 PM from the specification file
|
||||
* <tt>/Users/abreslav/work/kotlin/grammar/src/org/jetbrains/jet/grammar/Grammar.flex</tt>
|
||||
*/
|
||||
class _GrammarLexer {
|
||||
/** initial size of the lookahead buffer */
|
||||
@@ -53,13 +37,13 @@ class _GrammarLexer {
|
||||
* Translates characters to character classes
|
||||
*/
|
||||
private static final String ZZ_CMAP_PACKED =
|
||||
"\11\1\1\3\1\10\1\0\1\3\1\0\16\1\4\0\1\3\1\0"+
|
||||
"\1\13\1\0\1\2\1\0\1\5\1\0\1\20\1\20\1\7\1\11"+
|
||||
"\11\1\1\3\1\10\1\0\1\3\1\16\16\1\4\0\1\3\1\0"+
|
||||
"\1\13\1\0\1\2\1\0\1\5\1\0\1\21\1\21\1\7\1\11"+
|
||||
"\1\0\1\11\1\11\1\6\1\1\11\1\1\11\1\0\1\14\1\0"+
|
||||
"\1\15\1\11\1\0\1\2\1\2\2\2\1\2\1\2\5\2\1\2"+
|
||||
"\3\2\1\2\7\2\1\2\2\2\1\16\1\12\1\17\1\0\1\2"+
|
||||
"\3\2\1\2\7\2\1\2\2\2\1\17\1\12\1\20\1\0\1\2"+
|
||||
"\1\4\1\2\1\2\2\2\1\2\1\2\5\2\1\2\3\2\1\2"+
|
||||
"\7\2\1\2\2\2\1\20\1\11\1\20\1\0\41\1\2\0\4\2"+
|
||||
"\7\2\1\2\2\2\1\21\1\11\1\21\1\0\41\1\2\0\4\2"+
|
||||
"\4\0\1\2\2\0\1\1\7\0\1\2\4\0\1\2\5\0\27\2"+
|
||||
"\1\0\37\2\1\0\u013f\2\31\0\162\2\4\0\14\2\16\0\5\2"+
|
||||
"\11\0\1\2\21\0\130\1\5\0\23\1\12\0\1\2\13\0\1\2"+
|
||||
@@ -153,12 +137,12 @@ class _GrammarLexer {
|
||||
private static final int [] ZZ_ACTION = zzUnpackAction();
|
||||
|
||||
private static final String ZZ_ACTION_PACKED_0 =
|
||||
"\1\0\1\1\1\2\1\3\3\1\1\4\2\5\2\6"+
|
||||
"\1\0\1\7\2\10\2\5\2\0\1\2\1\10\1\11"+
|
||||
"\1\12\2\0\2\11\1\0\1\10\1\0";
|
||||
"\1\0\1\1\1\2\1\3\3\1\1\4\1\5\2\6"+
|
||||
"\1\5\2\7\1\0\1\10\2\11\2\6\2\0\1\2"+
|
||||
"\1\11\1\12\1\13\2\0\2\12\1\0\1\11\1\0";
|
||||
|
||||
private static int [] zzUnpackAction() {
|
||||
int [] result = new int[31];
|
||||
int [] result = new int[33];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
|
||||
return result;
|
||||
@@ -183,13 +167,14 @@ class _GrammarLexer {
|
||||
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
|
||||
|
||||
private static final String ZZ_ROWMAP_PACKED_0 =
|
||||
"\0\0\0\21\0\42\0\63\0\104\0\125\0\146\0\21"+
|
||||
"\0\167\0\210\0\231\0\21\0\252\0\273\0\314\0\335"+
|
||||
"\0\356\0\21\0\377\0\u0110\0\21\0\u0121\0\u0132\0\21"+
|
||||
"\0\u0143\0\u0154\0\u0165\0\21\0\u0176\0\21\0\u0187";
|
||||
"\0\0\0\22\0\44\0\66\0\110\0\132\0\154\0\22"+
|
||||
"\0\66\0\176\0\220\0\22\0\242\0\22\0\264\0\306"+
|
||||
"\0\330\0\352\0\374\0\22\0\u010e\0\u0120\0\22\0\u0132"+
|
||||
"\0\u0144\0\22\0\u0156\0\u0168\0\u017a\0\22\0\u018c\0\22"+
|
||||
"\0\u019e";
|
||||
|
||||
private static int [] zzUnpackRowMap() {
|
||||
int [] result = new int[31];
|
||||
int [] result = new int[33];
|
||||
int offset = 0;
|
||||
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
|
||||
return result;
|
||||
@@ -212,21 +197,21 @@ class _GrammarLexer {
|
||||
private static final int [] ZZ_TRANS = zzUnpackTrans();
|
||||
|
||||
private static final String ZZ_TRANS_PACKED_0 =
|
||||
"\2\2\1\3\1\4\1\5\1\6\1\7\1\10\1\4"+
|
||||
"\1\10\1\2\1\11\1\12\1\2\1\13\2\14\22\0"+
|
||||
"\2\3\21\0\1\4\4\0\1\4\12\0\1\15\20\0"+
|
||||
"\1\16\24\0\1\17\1\20\11\0\10\11\1\0\1\11"+
|
||||
"\1\21\1\22\5\11\10\12\1\0\1\12\1\22\2\12"+
|
||||
"\1\22\3\12\2\0\1\23\1\0\1\24\15\0\2\15"+
|
||||
"\1\0\1\25\15\0\2\16\16\0\10\17\1\0\10\17"+
|
||||
"\7\26\1\27\11\26\10\11\1\0\10\11\1\0\2\23"+
|
||||
"\14\0\1\30\3\0\1\31\16\0\7\26\1\32\11\26"+
|
||||
"\6\33\1\34\1\27\11\33\1\0\2\31\1\0\1\35"+
|
||||
"\14\0\6\26\1\36\1\32\11\26\7\33\1\37\11\33"+
|
||||
"\17\0\1\30\1\0\6\33\1\34\1\37\11\33";
|
||||
"\2\2\1\3\1\4\1\5\1\6\1\7\1\10\1\11"+
|
||||
"\1\10\1\2\1\12\1\13\1\2\1\14\1\15\2\16"+
|
||||
"\23\0\2\3\22\0\1\4\4\0\1\4\13\0\1\17"+
|
||||
"\21\0\1\20\25\0\1\21\1\22\12\0\10\12\1\0"+
|
||||
"\1\12\1\23\1\24\6\12\10\13\1\0\1\13\1\24"+
|
||||
"\2\13\1\24\4\13\2\0\1\25\1\0\1\26\16\0"+
|
||||
"\2\17\1\0\1\27\16\0\2\20\17\0\10\21\1\0"+
|
||||
"\11\21\7\30\1\31\12\30\10\12\1\0\11\12\1\0"+
|
||||
"\2\25\15\0\1\32\3\0\1\33\17\0\7\30\1\34"+
|
||||
"\12\30\6\35\1\36\1\31\12\35\1\0\2\33\1\0"+
|
||||
"\1\37\15\0\6\30\1\40\1\34\12\30\7\35\1\41"+
|
||||
"\12\35\20\0\1\32\1\0\6\35\1\36\1\41\12\35";
|
||||
|
||||
private static int [] zzUnpackTrans() {
|
||||
int [] result = new int[408];
|
||||
int [] result = new int[432];
|
||||
int offset = 0;
|
||||
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
|
||||
return result;
|
||||
@@ -267,12 +252,12 @@ class _GrammarLexer {
|
||||
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
||||
|
||||
private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
||||
"\1\0\1\11\5\1\1\11\3\1\1\11\1\0\4\1"+
|
||||
"\1\11\2\0\1\11\2\1\1\11\2\0\1\1\1\11"+
|
||||
"\1\0\1\11\1\0";
|
||||
"\1\0\1\11\5\1\1\11\3\1\1\11\1\1\1\11"+
|
||||
"\1\0\4\1\1\11\2\0\1\11\2\1\1\11\2\0"+
|
||||
"\1\1\1\11\1\0\1\11\1\0";
|
||||
|
||||
private static int [] zzUnpackAttribute() {
|
||||
int [] result = new int[31];
|
||||
int [] result = new int[33];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
|
||||
return result;
|
||||
@@ -330,6 +315,12 @@ class _GrammarLexer {
|
||||
/** denotes if the user-EOF-code has already been executed */
|
||||
private boolean zzEOFDone;
|
||||
|
||||
/* user code: */
|
||||
private int line = 1;
|
||||
public int getCurrentLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
|
||||
_GrammarLexer(java.io.Reader in) {
|
||||
this.zzReader = in;
|
||||
@@ -577,46 +568,50 @@ class _GrammarLexer {
|
||||
zzMarkedPos = zzMarkedPosL;
|
||||
|
||||
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
|
||||
case 6:
|
||||
{ return new SymbolToken("\\" + yytext());
|
||||
}
|
||||
case 11: break;
|
||||
case 10:
|
||||
{ return new Annotation(yytext());
|
||||
{ return new DocComment(yytext(), line);
|
||||
}
|
||||
case 12: break;
|
||||
case 1:
|
||||
{ return new Other(yytext());
|
||||
case 11:
|
||||
{ return new Annotation(yytext(), line);
|
||||
}
|
||||
case 13: break;
|
||||
case 5:
|
||||
{ return new StringToken(yytext());
|
||||
{ line++; return new WhiteSpace(yytext(), line);
|
||||
}
|
||||
case 14: break;
|
||||
case 8:
|
||||
{ return new Comment(yytext());
|
||||
case 2:
|
||||
{ return new Identifier(yytext(), line);
|
||||
}
|
||||
case 15: break;
|
||||
case 9:
|
||||
{ return new DocComment(yytext());
|
||||
case 3:
|
||||
{ return new WhiteSpace(yytext(), line);
|
||||
}
|
||||
case 16: break;
|
||||
case 4:
|
||||
{ return new SymbolToken(yytext());
|
||||
case 1:
|
||||
{ return new Other(yytext(), line);
|
||||
}
|
||||
case 17: break;
|
||||
case 7:
|
||||
{ return new Declaration(yytext());
|
||||
case 4:
|
||||
{ return new SymbolToken(yytext(), line);
|
||||
}
|
||||
case 18: break;
|
||||
case 2:
|
||||
{ return new Identifier(yytext());
|
||||
case 6:
|
||||
{ return new StringToken(yytext(), line);
|
||||
}
|
||||
case 19: break;
|
||||
case 3:
|
||||
{ return new WhiteSpace(yytext());
|
||||
case 8:
|
||||
{ return new Declaration(yytext(), line);
|
||||
}
|
||||
case 20: break;
|
||||
case 7:
|
||||
{ return new SymbolToken("\\" + yytext(), line);
|
||||
}
|
||||
case 21: break;
|
||||
case 9:
|
||||
{ return new Comment(yytext(), line);
|
||||
}
|
||||
case 22: break;
|
||||
default:
|
||||
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
||||
zzAtEOF = true;
|
||||
|
||||
Reference in New Issue
Block a user