Package net.sf.laja.parser.engine2.DefaultSyntaxError

Examples of net.sf.laja.parser.engine2.DefaultSyntaxError.Rowinfo


    this.bookmark = source.getBestIndex();
    DefaultSyntaxErrorFactoryFactory factoryFactory = new DefaultSyntaxErrorFactoryFactory(bookmark);
    DefaultSyntaxErrorParser parser = new DefaultSyntaxErrorParser(factoryFactory);
    source.reset();
    parser.parse(source);
    Rowinfo rowinfo = factoryFactory.getMatchedRow();


    writer.write("Syntax error in ").write(source.getType());
    if (source.getName() != null) {
      writer.write(" \"").write(source.getName()).write("\"");
    }

    if (rowinfo == null) {
      return;
    }
   
    int row = rowinfo.getRow() == 0 ? 1 : rowinfo.getRow();
   
    writer.write(", row ").write(row)
      .write(", column ").write(rowinfo.getColumn())
      .write(" (character index: ").write(bookmark).write(")")
      .writeln(":").writeln(rowinfo.getLine());

    String line = rowinfo.getLine();
    int idx = rowinfo.getColumn() - 1;
    for (int i = 0; i < idx; i++) {
      if (line.substring(i, i + 1).equals("\t")) {
        writer.write("\t");
      } else {
        writer.write(" ");
View Full Code Here


      element = getGrammar2();
      match = element.parse(0, source, false, true, true);
      if (!match) {
        throw new IllegalStateException("The parsing result was true in phase 1, but false in phase 2.");
      }
      return new ParsingResult(true, source, syntaxErrorHandler);
    } else if (sourceRecorderLogWriter != null) {
      source.reset();
      source.getRecorder().setLogging(sourceRecorderLogWriter, bestIndex);
      element.parse(0, source, false, true, false);
    }

    return new ParsingResult(false, source, element, syntaxErrorHandler);
  }
View Full Code Here

        return new ExpressionFactory();
      }
    });
   
    try {
      ParsingResult result = parser.parseFile(inputFile);
     
      if (result.success()) {
        Expression exp = ((ExpressionFactory)parser.getFactory()).getExp();
        System.out.println("Result=" + exp.calculate());
      } else {
        System.out.println(result.toString());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

            element = getGrammar2();
            match = element.parse(0, source, false, true, true);
            if (!match) {
                throw new IllegalStateException("The parsing result was true in phase 1, but false in phase 2.");
            }
            return new ParsingResult(true, source, syntaxErrorHandler);
        } else if (sourceRecorderLogWriter != null) {
            source.reset();
            source.getRecorder().setLogging(sourceRecorderLogWriter, bestIndex);
            element.parse(0, source, false, true, false);
        }

        return new ParsingResult(false, source, element, syntaxErrorHandler);
    }
View Full Code Here

            element = getGrammar2();
            match = element.parse(0, source, false, true, true);
            if (!match) {
                throw new IllegalStateException("The parsing result was true in phase 1, but false in phase 2.");
            }
            return new ParsingResult(true, source, syntaxErrorHandler);
        } else if (sourceRecorderLogWriter != null) {
            source.reset();
            source.getRecorder().setLogging(sourceRecorderLogWriter, bestIndex);
            element.parse(0, source, false, true, false);
        }

        return new ParsingResult(false, source, element, syntaxErrorHandler);
    }
View Full Code Here

      public IGrammarFactory getFactory(int phase) {
        return new ParserFactory(writer);
      }}
    );
 
    ParsingResult result = parser.parseFile(grammarFile);

    if (result.success()) {
      Grammar grammar = ((ParserFactory)parser.getFactory()).getGrammar();
      return grammar.getGeneratorResult(parsingSettings);
    }
    throw new ParserException("Could not generate grammar: " + result);
  }
View Full Code Here

            element = getGrammar2();
            match = element.parse(0, source, false, true, true);
            if (!match) {
                throw new IllegalStateException("The parsing result was true in phase 1, but false in phase 2.");
            }
            return new ParsingResult(true, source, syntaxErrorHandler);
        } else if (sourceRecorderLogWriter != null) {
            source.reset();
            source.getRecorder().setLogging(sourceRecorderLogWriter, bestIndex);
            element.parse(0, source, false, true, false);
        }

        return new ParsingResult(false, source, element, syntaxErrorHandler);
    }
View Full Code Here

            element = getGrammar2();
            match = element.parse(0, source, false, true, true);
            if (!match) {
                throw new IllegalStateException("The parsing result was true in phase 1, but false in phase 2.");
            }
            return new ParsingResult(true, source, syntaxErrorHandler);
        } else if (sourceRecorderLogWriter != null) {
            source.reset();
            source.getRecorder().setLogging(sourceRecorderLogWriter, bestIndex);
            element.parse(0, source, false, true, false);
        }

        return new ParsingResult(false, source, element, syntaxErrorHandler);
    }
View Full Code Here

   *
   * @param context
   * @return
   */
  private static GeneratorResult execute(String grammarFile, final boolean forwardRef) {
    final Writer writer = new PrintWriter();
   
    // TODO: Fix this!
    ParsingSettings parsingSettings = new ParsingSettings() {
      @Override
      public boolean isForwardRef() {
        return forwardRef;
      }
    };
    grammarFile = Util.replaceSlash(grammarFile);
   
    writer.writeln("  Reading grammar \"" + grammarFile + "\"");
   
    GrammarParser parser = new GrammarParser(new IGrammarFactoryFactory() {
      public IGrammarFactory getFactory(int phase) {
        return new ParserFactory(writer);
      }}
View Full Code Here

   *
   * @param context
   * @return
   */
  private static GeneratorResult execute(String grammarFile, final boolean forwardRef) {
    final Writer writer = new PrintWriter();
   
    // TODO: Fix this!
    ParsingSettings parsingSettings = new ParsingSettings() {
      @Override
      public boolean isForwardRef() {
        return forwardRef;
      }
    };
    grammarFile = Util.replaceSlash(grammarFile);
   
    writer.writeln("  Reading grammar \"" + grammarFile + "\"");
   
    GrammarParser parser = new GrammarParser(new IGrammarFactoryFactory() {
      public IGrammarFactory getFactory(int phase) {
        return new ParserFactory(writer);
      }}
View Full Code Here

TOP

Related Classes of net.sf.laja.parser.engine2.DefaultSyntaxError.Rowinfo

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.