@Override public int getStopIndex() { if (this.info != null) { return this.info.getStopIndex(); } else { return -1; } }
@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 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 TestMentalStateCondition visitPost(PostContext ctx) { String post = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); if (post.trim().isEmpty()) { return null; } else { SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); TEST2GParser parser = prepareTestParser(post, info); TestmscContext mscContext = parser.testmsc(); TestValidator sub = getTestSub("postcondition", info); return sub.visitTestmsc(mscContext); } }
/** * 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 TestMentalStateCondition visitPre(PreContext ctx) { String pre = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); if (pre.trim().isEmpty()) { return null; } else { SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); TEST2GParser parser = prepareTestParser(pre, info); TestmscContext mscContext = parser.testmsc(); TestValidator sub = getTestSub("precondition", info); return sub.visitTestmsc(mscContext); } }
/** * Delegates parsing of terminal node of parameter list to KR parser. * * @param parlist * Terminal node representing a parameter list. * @param info * Source information. * @return {@code null} if there are no parameters, a list of terms otherwise. */ public List<Term> visitPARLIST(TerminalNode parlist, SourceInfo info) { List<Term> parameters = null; if (parlist != null) { try { CognitiveKR ckr = getCognitiveKR(); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); parameters = ckr.visitArguments(removeLeadTrailCharacters(parlist.getText()), info); reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } } if (parameters == null) { return new ArrayList<>(0); } else { return parameters; } }
krInfo = (krInfo == null) ? null : new InputStreamPosition(krInfo.getLineNumber(), krInfo.getCharacterPosition() + 1, krInfo.getStartIndex() + 1, krInfo.getStopIndex() - 1, krInfo.getSource());
@Override public ActionPostCondition visitPostadd(PostaddContext ctx) { String krFragment = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); Update post = null; try { CognitiveKR ckr = getCognitiveKR(); SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); post = ckr.visitBeliefInsert(krFragment, info); reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } return (post == null) ? null : new ActionPostCondition(post, false, getSourceInfo(ctx)); }
@Override public ActionPostCondition visitPostdel(PostdelContext ctx) { String krFragment = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); Update post = null; try { CognitiveKR ckr = getCognitiveKR(); SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); post = ckr.visitBeliefDelete(krFragment, info); reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } return (post == null) ? null : new ActionPostCondition(post, true, getSourceInfo(ctx)); }
@Override public ActionPostCondition visitPost(PostContext ctx) { String krFragment = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); Update post = null; try { CognitiveKR ckr = getCognitiveKR(); SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); post = ckr.visitBeliefInsert(krFragment, info); reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } return (post == null) ? null : new ActionPostCondition(post, false, getSourceInfo(ctx)); }
@Override public ActionPreCondition visitPre(PreContext ctx) { String krFragment = (ctx.KR_BLOCK() == null) ? "" : removeLeadTrailCharacters(ctx.KR_BLOCK().getText()); Query pre = null; Set<String> signatures = null; try { CognitiveKR ckr = getCognitiveKR(); SourceInfo info = getSourceInfo(ctx.KR_BLOCK()); info = (info == null) ? null : new InputStreamPosition(info.getLineNumber(), info.getCharacterPosition() + 1, info.getStartIndex() + 1, info.getStopIndex() - 1, info.getSource()); pre = ckr.visitBeliefQuery(krFragment, info); if (pre != null) { signatures = ckr.getUsedSignatures(pre); } reportEmbeddedLanguageErrors(ckr); } catch (ParserException e) { reportParsingException(e); } return (pre == null) ? null : new ActionPreCondition(pre, signatures, getSourceInfo(ctx)); }
krInfo = (krInfo == null) ? null : new InputStreamPosition(krInfo.getLineNumber(), krInfo.getCharacterPosition() + 1, krInfo.getStartIndex() + 1, krInfo.getStopIndex() - 1, krInfo.getSource()); try { Action<?> returned = null;