Package org.jrubyparser

Examples of org.jrubyparser.SourcePosition


   *            An id that will be used as the file name or <code>null</code> if the file name should be extracted
   *            from the exception
   * @return The created diagnostic
   */
  public static FileDiagnostic createSyntaxErrorDiagnostic(SyntaxException syntaxException, String id) {
    SourcePosition pos = syntaxException.getPosition();
    String msg = syntaxException.getMessage();
    if(msg == null)
      msg = "syntax error";
    FileDiagnostic fd = new FileDiagnostic(ERROR, PARSE_FAILURE, msg, new File(id == null
        ? pos.getFile()
        : id));
    fd.setLineNumber(pos.getStartLine() + 1);
    return fd;
  }
View Full Code Here


   *
   * @param n
   * @return
   */
  public static int posOnLine(Node n) {
    SourcePosition p = n.getPosition();
    String s = rootContent(n);
    if(s == null)
      return -1;
    for(int i = p.getStartOffset(); i > 0; i--)
      if(s.charAt(i) == '\n')
        return p.getStartOffset() - i - 1;
    return p.getStartOffset(); // it was on the firstline.
  }
View Full Code Here

   *
   * @param n
   * @return
   */
  public static String rootContent(Node n) {
    SourcePosition p = n.getPosition();
    File f = new File(p.getFile());
    try {
      return Files.toString(f, Charsets.UTF_8);
    }
    catch(IOException e) {
      return null;
View Full Code Here

public abstract class ModulefileParser {
  private static final String[] validProperties = new String[] {
      "name", "author", "description", "license", "project_page", "source", "summary", "version", "dependency" };

  private static Argument createArgument(Node n) {
    SourcePosition p = n.getPosition();
    String v = getString(n);
    return new Argument(p.getStartOffset(), p.getEndOffset() - p.getStartOffset(), v);
  }
View Full Code Here

    versionSeen = false;
    fullName = null;
    File file = null;
    for(Node node : RubyParserUtils.findNodes(root.getBody(), new NodeType[] { NodeType.FCALLNODE })) {
      FCallNode call = (FCallNode) node;
      SourcePosition pos = call.getPosition();
      if(file == null)
        file = new File(pos.getFile());

      String key = call.getName();
      List<Node> args = getStringArguments(call);
      int nargs = args.size();
      if(nargs > 3 || !isValidCall(key)) {
View Full Code Here

TOP

Related Classes of org.jrubyparser.SourcePosition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.