Commit c1748319 authored by Johannes Roith's avatar Johannes Roith

Offsets are not accurate, error reporting now correctly underlines affected ranges.

parent 9b968351
......@@ -435,7 +435,7 @@ action_code_part ::=
if (context.action_code!=null)
errMan.Warning(ErrorSource.Parser,
"Redundant action code (skipping)",
Position.fromLocation(user_codexleft));
Range.fromLocations(actxleft, smixright));
else { /* save the user included code string */
context.action_code = user_code;
......@@ -445,8 +445,7 @@ action_code_part ::=
debug_id,
SpecialCodeBlock.BlockType.Action,
user_code,
new Range(Position.fromLocation(actxleft),
Position.fromLocation(smixright))));
Range.fromLocations(actxleft, smixright)));
}
:}
;
......@@ -459,7 +458,7 @@ parser_code_part ::=
if (context.parser_code!=null)
errMan.Warning(ErrorSource.Parser,
"Redundant parser code (skipping)",
Position.fromLocation(user_codexleft));
Range.fromLocations(prsxleft, smixright));
else { /* save the user included code string */
context.parser_code = user_code;
int debug_id = get_new_debug_id();
......@@ -480,7 +479,7 @@ init_code ::=
{:
if (context.init_code!=null)
errMan.Warning(ErrorSource.Parser, "Redundant init code (skipping)",
Position.fromLocation(user_codexleft));
Range.fromLocations(initxleft, smixright));
else {/* save the user code */
context.init_code = user_code;
int debug_id = get_new_debug_id();
......@@ -501,7 +500,7 @@ scan_code ::=
{:
if (context.scan_code!=null)
errMan.Warning(ErrorSource.Parser, "Redundant scan code (skipping)",
Position.fromLocation(user_codexleft));
Range.fromLocations(scanxleft, smixright));
else {
/* save the user code */
context.scan_code = user_code;
......@@ -531,7 +530,7 @@ symbol ::=
(String) tid,
(List<Terminal>) lst,
new Range(Position.fromLocation(txleft),
Position.fromLocation(txright))));
Position.fromLocation(lstxright))));
:}
|
TERMINAL : t
......@@ -539,7 +538,7 @@ symbol ::=
parserResult.symbols.add(new TerminalDeclaration(
(List<Terminal>) lst,
new Range(Position.fromLocation(txleft),
Position.fromLocation(txright))));
Position.fromLocation(lstxright))));
;
:}
|
......@@ -550,7 +549,7 @@ symbol ::=
(String) tid,
(List<NonTerminal>) lst,
new Range(Position.fromLocation(ntxleft),
Position.fromLocation(ntxright))));
Position.fromLocation(lstxright))));
:}
|
non_terminal : nt
......@@ -558,7 +557,7 @@ symbol ::=
parserResult.symbols.add(new NonTerminalDeclaration(
(List<NonTerminal>) lst,
new Range(Position.fromLocation(ntxleft),
Position.fromLocation(ntxright))));
Position.fromLocation(lstxright))));
:}
|
......@@ -697,7 +696,7 @@ term_id ::= symbol_id:sym
{
/* issue a message */
errMan.Error(ErrorSource.Parser, "Terminal \"" + sym +
"\" has not been declared", Position.fromLocation(symxleft));
"\" has not been declared", Range.fromLocations(symxleft, symxright));
}
RESULT = sym;
:};
......@@ -713,7 +712,7 @@ start_spec ::=
{
errMan.Error(ErrorSource.Parser,
"Start non terminal \"" + start_name + "\" has not been declared",
Position.fromLocation(start_namexleft));
Range.fromLocations(start_namexleft, start_namexright));
}
else
{
......@@ -756,12 +755,11 @@ production ::=
lhs_nt = (non_terminal)non_terms.get(lhs_id);
/* if it wasn't declared, emit a message */
if (lhs_nt == null)
{
if (lhs_nt == null) {
if (errMan.getErrorCount() == 0)
errMan.Warning(ErrorSource.Parser, "LHS non terminal \"" + lhs_id +
"\" has not been declared",
Position.fromLocation(lhs_idxleft));
Range.fromLocations(lhs_idxleft, lhs_idxright));
}
/* reset the rhs accumulation */
......@@ -836,7 +834,7 @@ rhs ::=
// fix crash.
errMan.Error(ErrorSource.Parser,
"could not resolve symbol!",
Position.fromLocation(term_namexleft));
Range.fromLocations(term_namexleft, term_namexright));
}
if (sp != null)
sym = sp.the_symbol();
......@@ -955,7 +953,7 @@ prod_part ::=
if (symb == null) {
if (errMan.getErrorCount() == 0)
errMan.Error(ErrorSource.Parser, "Symbol \"" + symid +
"\" has not been declared", Position.fromLocation(symidxleft));
"\" has not been declared", Range.fromLocations(symidxleft, symidxright));
}
else {
/* add a labeled production part */
......@@ -1069,7 +1067,7 @@ new_term_id ::=
{
/* issue a message */
errMan.Error(ErrorSource.Parser, "Symbol \"" + term_id +
"\" has already been declared", Position.fromLocation(term_idxleft));
"\" has already been declared", Range.fromLocations(term_idxleft, term_idxright));
}
else
{
......@@ -1100,7 +1098,7 @@ new_non_term_id ::=
{
/* issue a message */
errMan.Error(ErrorSource.Parser, "Symbol \"" + non_term_id +
"\" has already been declared", Position.fromLocation(non_term_idxleft));
"\" has already been declared", Range.fromLocations(non_term_idxleft, non_term_idxright));
}
else
{
......@@ -1139,6 +1137,7 @@ nt_id ::=
errMan.Error(ErrorSource.Parser,
"Illegal use of reserved word",
Position.fromLocation(exleft));
RESULT="ILLEGAL";
:}
;
......@@ -1189,6 +1188,7 @@ robust_id ::= /* all ids that aren't reserved words in Java */
errMan.Error(ErrorSource.Parser,
"Illegal use of reserved word",
Position.fromLocation(exleft));
RESULT="ILLEGAL";
:}
;
......
......@@ -69,6 +69,10 @@ public class ErrorManager
public void Warning(ErrorSource source, String msg, Position start) {
Warning(source, msg, start, null);
}
public void Warning(ErrorSource source, String msg, Range range) {
Warning(source, msg, range.getBegin(), range.getEnd());
}
public void Warning(ErrorSource source, String msg, Position start, Position end) {
er.report(ErrorType.Warning, source, null, msg, start, end);
......@@ -109,6 +113,10 @@ public class ErrorManager
public void Error(ErrorSource source, String msg, Position start) {
Error(source, msg, start, null);
}
public void Error(ErrorSource source, String msg, Range range) {
Error(source, msg, range.getBegin(), range.getEnd());
}
public void Error(ErrorSource source, String msg, Position start, Position end) {
er.report(ErrorType.Error, source, null, msg, start, end);
......
......@@ -123,7 +123,15 @@ ident = ([:jletter:] | "_" ) ([:jletterdigit:] | [:jletter:] | "_" )*
}
<CODESEG> {
":}" { yybegin(YYINITIAL); return symbolFactory.newSymbol("CODE_STRING",CODE_STRING, new Location(csline, cscolumn, csoffset),new Location(yyline+1,yycolumn+1+yylength(), csoffset+yylength()), sb.toString()); }
":}" {
String _codeseg_str = sb.toString();
yybegin(YYINITIAL);
return symbolFactory.newSymbol("CODE_STRING",CODE_STRING,
new Location(csline, cscolumn, csoffset),
new Location(yyline+1,yycolumn+1+yylength(),
csoffset + _codeseg_str.length() + 4
), _codeseg_str);
}
.|\n { sb.append(yytext()); }
}
......
......@@ -114,9 +114,12 @@ public class CupEditorErrorReporter implements IErrorReporter {
marker.setAttribute(IMarker.LOCATION, msg.start.toLongString());
marker.setAttribute(IMarker.LINE_NUMBER, msg.start.getLine());
marker.setAttribute(IMarker.CHAR_START, msg.start.getOffsetFromStart());
if (msg.end != null && msg.start.getLine() == msg.end.getLine()) {
if (msg.start.getColumn() < msg.end.getColumn())
if (msg.end != null) {
int sl = msg.start.getLine();
int el = msg.end.getLine();
int sc = msg.start.getColumn();
int ec = msg.end.getColumn();
if ((sl == el && sc < ec) || sl < el)
marker.setAttribute(IMarker.CHAR_END, msg.end.getOffsetFromStart());
}
}
......
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