@Override public boolean reportError(SyntaxError type, SourceInfo info, String... args) { SourceInfo isp = null; if (info != null) { isp = new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition(), ctxSource.getStartIndex() + info.getStartIndex(), ctxSource.getStartIndex() + info.getStopIndex() + 1, info.getSource()); } return super.reportError(type, isp, args); }
/** * @param info1 * A source info object. * @param info2 * A source info object. * @return {@code true} if source position of info1 object occurs before * position of info2 object. */ private static boolean before(SourceInfo info1, SourceInfo info2) { boolean source = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) < 0); boolean sourceEqual = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) == 0); boolean lineNr = sourceEqual && (info1.getLineNumber() < info2.getLineNumber()); boolean lineNrEqual = (info1.getLineNumber() == info2.getLineNumber()); boolean position = sourceEqual && lineNrEqual && (info1.getCharacterPosition() < info2.getCharacterPosition()); return source || lineNr || position; }
@Override public SourceInfo getSourceInfo(TerminalNode leaf) { Token symbol = (leaf == null) ? null : leaf.getSymbol(); return (symbol == null) ? null : new InputStreamPosition(symbol.getLine(), symbol.getCharPositionInLine(), ctxSource.getStartIndex() + symbol.getStartIndex(), ctxSource.getStartIndex() + symbol.getStopIndex() + 1, ctxSource.getSource()); } };
/** * @return The source of this exception, or {@code null} if no source is * available. */ @Override public String getSource() { if (this.info != null) { return this.info.getSource(); } else { return null; } }
/** * @return Line number where exception occurred, or {@code -1} if no line nr * is available. */ @Override public int getLineNumber() { if (this.info != null) { return this.info.getLineNumber(); } else { return -1; } }
/** * @return Character position where exception occurred, or {@code -1} if no * position is available. */ @Override public int getCharacterPosition() { if (this.info != null) { return this.info.getCharacterPosition(); } else { return -1; } }
@Override public int getStartIndex() { if (this.info != null) { return this.info.getStartIndex(); } else { return -1; } }
@Override public int getStopIndex() { if (this.info != null) { return this.info.getStopIndex(); } else { return -1; } }
/** * Reports parsing errors that occurred while parsing embedded language * fragments. * * @param parser * The parser that generated the errors. * @param relativeLineNr * Relative source code line position (start of the embedded fragment * in source). * @param relativeCharPos * Relative source code character position (start of the embedded * fragment in source). */ protected void reportEmbeddedLanguageErrors(CognitiveKR ckr) { for (SourceInfo error : ckr.getErrors()) { reportError(SyntaxError.EMBEDDED_LANGUAGE_ERROR, error, KRFactory.getName(this.program.getKRInterface()), error.getMessage()); } }
/** * Checks wether the position if the first source info is before the second * one. * * @param info1 * A source info object. * @param info2 * A source info object. * @return {@code true} if source position of info1 object occurs before * position of info2 object. */ private static boolean before(SourceInfo info1, SourceInfo info2) { boolean source = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) < 0); boolean sourceEqual = info1.getSource() != null && info2.getSource() != null && (info1.getSource().compareTo(info2.getSource()) == 0); boolean lineNr = sourceEqual && (info1.getLineNumber() < info2.getLineNumber()); boolean lineNrEqual = (info1.getLineNumber() == info2.getLineNumber()); boolean position = sourceEqual && lineNrEqual && (info1.getCharacterPosition() < info2.getCharacterPosition()); return source || lineNr || position; } }
@Override public SourceInfo getSourceInfo(TerminalNode leaf) { Token symbol = (leaf == null) ? null : leaf.getSymbol(); return (symbol == null) ? null : new InputStreamPosition(symbol.getLine(), symbol.getCharPositionInLine(), ctxSource.getStartIndex() + symbol.getStartIndex(), ctxSource.getStartIndex() + symbol.getStopIndex() + 1, ctxSource.getSource()); } };
/** * @return The source file used to construct this program. */ public File getSourceFile() { return new File(this.info.getSource()); }
module.setRuleEvaluationOrder(getProgram().getRuleEvaluationOrder()); module.setName(getProgram().getName() + "_" + module.getSourceInfo().getLineNumber()); module.setAnonymous();
for (final SourceInfo error : ckr.getErrors()) { this.firstPass.reportError(SyntaxError.EMBEDDED_LANGUAGE_ERROR, error, KRFactory.getName(this.program.getKRInterface()), error.getMessage());
@Override public boolean reportError(SyntaxError type, SourceInfo info, String... args) { SourceInfo isp = null; if (info != null) { isp = new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition(), ctxSource.getStartIndex() + info.getStartIndex(), ctxSource.getStartIndex() + info.getStopIndex() + 1, info.getSource()); } return super.reportError(type, isp, args); }
@Override public int compareTo(SourceInfo o) { if (getSource() == null) { if (o.getSource() != null) { return -1; } } else { if (o.getSource() == null) { return 1; } // both files not null. int filecompare = getSource().compareTo(o.getSource()); if (filecompare != 0) { return filecompare; } } // files are equal (or both null). int linecompare = getLineNumber() - o.getLineNumber(); if (linecompare != 0) { return linecompare; } // lines are equal return getCharacterPosition() - o.getCharacterPosition(); } }
private SourceInfo getSourceInfo(TerminalNode leaf) { Token symbol = (leaf == null) ? null : leaf.getSymbol(); return (symbol == null) ? null : new SourceInfoObject(this.source.getSource(), symbol.getLine(), symbol.getCharPositionInLine(), this.source.getStartIndex() + symbol.getStartIndex(), this.source.getStartIndex() + symbol.getStopIndex()); }
@Override public int compareTo(SourceInfo o) { return this.source.compareTo(o.getSource()); }
/** * Report syntax error. * * Collects details about the exact position in the input stream from an ANTLR * ParserRuleContext object. * * @param type * The type of syntax error that is added. * @param info * Source info object. * @param args * Additional info to be inserted into warning message. */ public boolean reportError(SyntaxError type, SourceInfo info, String... args) { // FIXME: Make SourceInfo in KRTools abstract class and move code from // InputStreamPosition to SourceInfo. // Map onto input stream position for pretty printing of code location. SourceInfo isp = null; if (info != null) { isp = new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition(), info.getStartIndex(), info.getStopIndex(), info.getSource()); } return this.registry.addSyntaxError(new ParserError(type, isp, args)); }
@Override public int compareTo(SourceInfo o) { if (getSource() == null) { if (o.getSource() != null) { return -1; } } else { if (o.getSource() == null) { return 1; } // both files not null. int filecompare = getSource().compareTo(o.getSource()); if (filecompare != 0) { return filecompare; } } // files are equal (or both null). int linecompare = getLineNumber() - o.getLineNumber(); if (linecompare != 0) { return linecompare; } // lines are equal return getCharacterPosition() - o.getCharacterPosition(); }