public int getIndex() { return _source.getIndex(); } }
public String get_snippet() { return _source.get_snippet(); }
@Override public String toString() { StringBuilder lines = new StringBuilder(); if (context != null) { lines.append(context); lines.append("\n"); } if (contextMark != null && (problem == null || problemMark == null || contextMark.getName().equals(problemMark.getName()) || (contextMark.getLine() != problemMark.getLine()) || (contextMark .getColumn() != problemMark.getColumn()))) { lines.append(contextMark.toString()); lines.append("\n"); } if (problem != null) { lines.append(problem); lines.append("\n"); } if (problemMark != null) { lines.append(problemMark.toString()); lines.append("\n"); } if (note != null) { lines.append(note); lines.append("\n"); } return lines.toString(); }
private static Node buildYamlErrorNode(MarkedYAMLException e, String resourcePath) { final ErrorNode errorNode = new ErrorNode("Underlying error while parsing YAML syntax: '" + e.getMessage() + "'"); final Mark problemMark = e.getProblemMark(); errorNode.setStartPosition(new DefaultPosition(problemMark.getIndex(), problemMark.getLine(), 0, resourcePath, new DefaultResourceLoader())); errorNode.setEndPosition(new DefaultPosition(problemMark.getIndex() + 1, problemMark.getLine(), problemMark.getColumn(), resourcePath, new DefaultResourceLoader())); return errorNode; }
public int getLine() { return _source.getLine(); }
/** * Constructor * * @param content the YAML content to highlight * @param mark a mark to be pointed to (and certainly highlighted) in the YAML code */ YamlLocation(String content, Mark mark) { this(content, mark.getLine() + 1, mark.getColumn() + 1, mark.getPointer()); }
private static String formatYamlExceptionMessage(Resource res, YAMLException ye) { final StringBuilder sb = new StringBuilder(); sb.append("YAML parsing error in ").append(res); if (ye instanceof MarkedYAMLException) { final Mark mark = ((MarkedYAMLException) ye).getProblemMark(); final String snippet = mark != null ? mark.get_snippet() : null; final String problem = ((MarkedYAMLException) ye).getProblem(); if (mark != null) { sb.append(" at line ").append(mark.getLine()).append(", column ").append(mark.getColumn()); } if (snippet != null) { sb.append(":\n"); sb.append(snippet); } if (problem != null) { // TODO SnakeYaml tends to be a bit nasty about this "problem", e.g org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens() prints the actual char THEN it's representation, so you end up with a big fat actual tab in the message instead of JUST \t(TAB) // See https://code.google.com/p/snakeyaml/issues/detail?id=209 sb.append(": ").append(problem.replaceAll("\\s*\\t\\s*", " ")); } } else { sb.append(": ").append(ye.getMessage()); } return sb.toString(); } }
public int getColumn() { return _source.getColumn(); }
public MarkedYAMLException apply(MarkedYAMLException e, String yaml) throws IOException { Mark problemMark = e.getProblemMark(); Optional<YamlLine> prevLine = getLine(yaml, problemMark.getLine() - 1); Optional<YamlLine> line = getLine(problemMark.get_snippet(0, 100), 0); if (prevLine.isPresent() && line.isPresent()) { YamlLine prev = prevLine.get(); YamlLine current = line.get(); if (isIncorrectIndentation(prev, current)) { return incorrectIndentationException(prev, current, e); } else if (isItemOutsideSequence(prev, current)) { return itemOutsideSequence(e); } } return new YamlSyntaxErrorException(e.getMessage(), e); }
public Mark getMark() { return new Mark(name, this.index, this.line, this.column, this.dataWindow, this.pointer); }
@Override public String toString() { final String sourceInfix = source != null ? source + " " : ""; if (node == null) { return getClass().getName() + ": " + sourceInfix + getMessage(); } else { return getClass().getName() + ": " + sourceInfix + getMessage() + node.getStartMark().toString(); } }
public String getName() { return _source.getName(); }
@JRubyMethod public IRubyObject mark(ThreadContext context) { Ruby runtime = context.runtime; Event event = null; if (parser != null) { event = parser.peekEvent(); if (event == null) event = this.event; } if (event == null) { return ((RubyClass)context.runtime.getClassFromPath("Psych::Parser::Mark")).newInstance( context, runtime.newFixnum(0), runtime.newFixnum(0), runtime.newFixnum(0), Block.NULL_BLOCK ); } Mark mark = event.getStartMark(); return ((RubyClass)context.runtime.getClassFromPath("Psych::Parser::Mark")).newInstance( context, runtime.newFixnum(mark.getIndex()), runtime.newFixnum(mark.getLine()), runtime.newFixnum(mark.getColumn()), Block.NULL_BLOCK ); }
@Override public String toString() { StringBuilder lines = new StringBuilder(); if (context != null) { lines.append(context); lines.append("\n"); } if (contextMark != null && (problem == null || problemMark == null || contextMark.getName().equals(problemMark.getName()) || (contextMark.getLine() != problemMark.getLine()) || (contextMark .getColumn() != problemMark.getColumn()))) { lines.append(contextMark.toString()); lines.append("\n"); } if (problem != null) { lines.append(problem); lines.append("\n"); } if (problemMark != null) { lines.append(problemMark.toString()); lines.append("\n"); } if (note != null) { lines.append(note); lines.append("\n"); } return lines.toString(); }
public int getLine() { return _source.getLine(); }
public int getColumn() { return _source.getColumn(); }
public Mark getMark() { return new Mark(name, this.line, this.column, this.dataWindow, this.pointer); }
private NodeEvent nextNodeEvent(final Parser parser) throws ParserException { if (parser.checkEvent(Event.ID.Alias)) { final AliasEvent event = (AliasEvent) parser.getEvent(); final String anchor = event.getAnchor(); throw new ParserException("Encounter node alias '" + anchor + "' which is not supported when parsing a document head only, " + event.getStartMark().toString()); } else { final NodeEvent event = (NodeEvent) parser.getEvent(); final String anchor = event.getAnchor(); if (anchor != null) { throw new ParserException("Encountered node anchor '" + anchor + "' which is not supported when parsing a document head only, " + event.getStartMark().toString()); } return event; } }