/** Returns the start location of the next token */ private Location startLoc() { Token t = getToken(1); return new Location(beginLine + t.beginLine, beginColumn + t.beginColumn, 0, 0); }
/** Marks 'node' with the start position in 'locPrefix' and the end position of the last token. Returns 'node' (which simplifies many uses of this function). */ private <T extends ASTNode> T markLoc(Location locPrefix, T node) { return markLocExplicit(Location.apply(locPrefix.startLine(), locPrefix.startColumn(), token.endLine, token.endColumn), node); }
public int compare(ModuleItem o1, ModuleItem o2) { int endLine1 = o1.getLocation().endLine(), endCol1 = o1.getLocation().endColumn(); int endLine2 = o2.getLocation().endLine(), endCol2 = o2.getLocation().endColumn(); if (endLine1 < endLine2 || endLine1 == endLine2 && endCol1 < endCol2) return -1; if (endLine1 > endLine2 || endLine1 == endLine2 && endCol1 > endCol2) return 1; return 0; } }
public K gen(Rule r, K body) { if (!cover || !r.att().getOptional(Source.class).isPresent()) { return body; } K left = RewriteToTop.toLeft(body); K right = RewriteToTop.toRight(body); String file = r.att().get(Source.class).source(); if (file.startsWith(JarInfo.getKBase())) { return body; } int line = r.att().get(Location.class).startLine(); int col = r.att().get(Location.class).startColumn(); String loc = file + ":" + line + ":" + col; String id = r.att().get("UNIQUE_ID"); allRulesFile.print(id); allRulesFile.print(" "); allRulesFile.println(loc); if (r.att().contains("macro") || r.att().contains("alias")) { //handled by macro expander return body; } return KRewrite(left, KSequence(KApply(KLabel("#logToFile"), KToken(StringUtil.enquoteKString(files.resolveKompiled("coverage.txt").getAbsolutePath()), Sorts.String()), KToken(StringUtil.enquoteKString(id + '\n'), Sorts.String())), right)); }
private static String getSourceLocation(Rule rule) { String s; // Return null, if location information is not available. Source source = rule.getSource(); s = source.toString() + ":" + rule.getLocation().toString(); return s; } }
&& rule.getLocation().startLine() == options.auditingLine) { matchedRules.add(rule);
private static String getSourceLocation(Term term) { String s = null; // Return null, if location information is not available. Term t = term.getCellContentsByName("<k>").get(0); if (t instanceof KSequence && ((KSequence) t).concreteSize() > 0) { t = ((KSequence) t).get(0); } if (t instanceof KItem) { Source source = t.getSource(); s = source.toString() + ":" + t.getLocation().toString(); } return s; }
/** Marks 'node' with the start and end location of the last token. Returns 'node' (which simplifies many uses of this function). */ private <T extends ASTNode> T tokenLoc(T node) { return markLoc(new Location(beginLine + token.beginLine, beginColumn + token.beginColumn, 0, 0), node); }
public static String loadFragment(File file, Location location) { try (Stream<String> lines = new BufferedReader(new InputStreamReader(new FileInputStream(file))).lines() .skip(location.startLine() - 1) .limit(location.endLine() - location.startLine() + 1)) { return lines.collect(Collectors.joining("\n")); } catch (IOException e) { throw KEMException.criticalError("Could not read from file " + file.getAbsolutePath(), e); } }
protected Term apply(KList klist, MetaData metaData) { Term term; Location loc = new Location(metaData.start.line, metaData.start.column, metaData.end.line, metaData.end.column); Source source = metaData.source; if (isToken) { String value = metaData.input.subSequence(metaData.start.position, metaData.end.position).toString(); term = Constant.apply(value, label, Optional.of(loc), Optional.of(source)); } else if (needsLabel) { term = TermCons.apply(klist.items(), label, loc, source); } else { return klist; } return term; } }
/** Adds a comment to the current module or definition list */ void comment(Token token) { String str = token.image; if (str.startsWith("//")) str = str.substring(2, str.length() - 1); // remove // and \n from beginning and end else str = str.substring(2, str.length() - 2); // remove /* and */ from beginning and end LiterateCommentType lcType = LiterateCommentType.COMMON; if (str.startsWith("@")) { lcType = LiterateCommentType.LATEX; str = str.substring(1); } else if (str.startsWith("!")) { lcType = LiterateCommentType.PREAMBLE; str = str.substring(1); } Location loc = new Location(token.beginLine, token.beginColumn, token.endLine, token.endColumn); if (module == null) { items.add(markLocExplicit(loc, new LiterateDefinitionComment(str, lcType))); } else { module.appendModuleItem(markLocExplicit(loc, new LiterateModuleComment(str, lcType))); } }
public static K parse(String kast, Source source) { KoreParser parser = new KoreParser(new StringReader(kast)); try { return parser.k(); } catch (ParseException e) { throw KEMException.outerParserError("Encountered " + e.tokenImage[e.currentToken.next.kind] + ".\u005cnWas expecting one of: " + Stream.of(e.expectedTokenSequences) // using an anonymous class because JavaCC doesn't support Java 8 syntax. .map(new Function<int[], String>() { public String apply(int[] is) { StringBuilder sb = new StringBuilder(); for (int i : is) { sb.append(e.tokenImage[i]); sb.append(" "); } sb.deleteCharAt(sb.length() - 1); return sb.toString(); } }).collect(Collectors.toList()).toString(), e, source, new Location(e.currentToken.next.beginLine, e.currentToken.next.beginColumn, e.currentToken.next.endLine, e.currentToken.next.endColumn)); } catch (TokenMgrError e) { throw KEMException.innerParserError(e.getMessage(), e, source, null); } }
if (kind == -1) { String msg = "Scanner error: unexpected character sequence '" + value + "'."; Location loc = new Location(lines[t.startLoc], columns[t.startLoc], lines[t.endLoc], columns[t.endLoc]); throw new ParseFailedException(new KException(
/** Parses a given string that was read from 'source'. */ public static List<DefinitionItem> parse( Source source, String string, Context context) { Outer parser = new Outer(new StringReader(string)); parser.source = source; parser.context = context; try { return parser.Start(); } catch (ParseException e) { throw KEMException.outerParserError("Encountered " + e.tokenImage[e.currentToken.next.kind] + ".\u005cnWas expecting one of: " + Stream.of(e.expectedTokenSequences) // using an anonymous class because JavaCC doesn't support Java 8 syntax. .map(new Function<int[], String>() { public String apply(int[] is) { StringBuilder sb = new StringBuilder(); for (int i : is) { sb.append(e.tokenImage[i]); sb.append(" "); } sb.deleteCharAt(sb.length() - 1); return sb.toString(); } }).collect(Collectors.toList()).toString(), e, source, new Location(e.currentToken.next.beginLine, e.currentToken.next.beginColumn, e.currentToken.next.endLine, e.currentToken.next.endColumn)); } catch (TokenMgrError e) { // TODO: report location throw KEMException.outerParserError(e.getMessage(), e, source, null); } }
/** * Retrieves the location from an XML element * * @param elem * @return the location stored in XML or Constants.GENERATED_LOCATION if no location found. */ public static Location getElementLocation(Element elem) { if (elem != null && elem.hasAttribute(Constants.LOC_loc_ATTR)) { Scanner scanner = new Scanner(elem.getAttribute(Constants.LOC_loc_ATTR)).useDelimiter("[,)]").skip("\\("); int beginLine = scanner.nextInt(); int beginCol = scanner.nextInt(); int endLine = scanner.nextInt(); int endCol = scanner.nextInt(); return new Location(beginLine, beginCol, endLine, endCol); } else return null; }
"Parse error: unexpected end of file." : "Parse error: unexpected token '" + s.input[perror.position].value + "'."; Location loc = new Location(perror.startLine, perror.startColumn, perror.endLine, perror.endColumn); Source source = perror.source;
@Test(expected = ParseFailedException.class) public void testNoKLabel() throws Exception { throwFirstLeftException(TermCons.apply(ConsPStack.from(Arrays.asList(bar, foo)), noKLabelProduction, new Location(0, 0, 0, 0), new Source(""))); }