Package net.sf.laja.parser.engine2

Examples of net.sf.laja.parser.engine2.Recorder


      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

  }
 
  @Override
  public boolean parse(int level, Source source, boolean parentNot, boolean caseSensitive, boolean receive) {
    level++;
    Recorder recorder = source.getRecorder();
    int bookmark = source.getBookmark();
    int recIndex = recorder.getIndex();

    for (Iterator i = list.iterator(); i.hasNext();) {
      source.setBookmark(bookmark);

      ElementOutputList.ElementOutput elementOutput = (ElementOutputList.ElementOutput)i.next();
      Element element = elementOutput.getElement();
      Output output = elementOutput.getOutput();
     
      boolean elementNot = elementOutput.isNot();

      if (this.caseSensitive != null) {
        caseSensitive = this.caseSensitive.booleanValue();
      }
      if (elementOutput.isCaseSensitive() != null) {
        caseSensitive = elementOutput.isCaseSensitive().booleanValue();
      }

      boolean match = false;
      if (output.receive()) {
        if (receive) {
          match = recorder.playMatch(element, source.getBookmark());
          source.setBookmark(recorder.playBookmark());
        } else {
          output.init(source);
          int mindex = recorder.reserveMatchIndex(level, element, source.getBookmark(), parentNot, elementNot);
          int bindex = recorder.reserveBookmarkIndex();
          match = element.parse(level, source, not|parentNot|elementNot, caseSensitive, false);
          match = match != elementNot;
          recorder.set(level, source, element, bookmark, source.getBookmark(), source.getBestIndex(), mindex, bindex, match, parentNot, elementNot);
          output.set(source, bookmark);
        }
      } else {
        if (receive) {
          match = recorder.playMatch(element, source.getBookmark());
        } else {
          int index = recorder.reserveMatchIndex(level, element, source.getBookmark(), parentNot, elementNot);
          match = element.parse(level, source, not|parentNot|elementNot, caseSensitive, false);
          match = (match != elementNot);
          recorder.set(level, source, element, bookmark, source.getBookmark(), source.getBestIndex(), index, match, parentNot, elementNot);
        }
      }

      if (match) {
        if (receive && !elementNot && !not) {
          source.setBookmark(bookmark);
          output.init(source);
          element.parse(level, source, not|parentNot|elementNot, caseSensitive, receive);
          output.set(source, bookmark);
        }
                output = list.getOutput();
                if (output != null && receive) {
                    output.init(source);
                    output.set(source, bookmark);
                }
               
                return !not;
      }
    }
    if (not) {
      source.setBookmark(bookmark);
      source.skipCharacter();

      Output output = list.getOutput();
      if (output != null && receive) {
        output.init(source);
        output.set(source, bookmark);
      }
    } else {
      recorder.setIndex(recIndex);
    }

    return not;
  }
View Full Code Here

    boolean firstMatch;

    int bookmark;
    int firstBookmark;

    Recorder recorder = source.getRecorder();
    firstBookmark = bookmark = source.getBookmark();
   
    if (maxRepeats > 0) {
      if (receive) {
        match = firstMatch = recorder.playMatch(elementList, source.getBookmark());
      } else {
        int index = recorder.reserveMatchIndex(level, elementList, source.getBookmark(), parentNot, false);
        match = elementList.parse(level, source, not|parentNot, caseSensitive, false);
        match = firstMatch = (match && source.getBookmark() != bookmark);
        recorder.set(level, source, elementList, bookmark, source.getBookmark(), source.getBestIndex(), index, match, parentNot, false);
      }
    } else {
      match = firstMatch = true;
    }
   
    int repeats = 0;
   
    if (!not) {
      while (match) {
        if (receive) {
          source.setBookmark(bookmark);
          elementList.parse(level, source, not|parentNot, caseSensitive, true);
        }
        if (++repeats >= maxRepeats) {
          break;
        }
        if (source.reachedEnd()) {
          bookmark = source.getBookmark();
          break;
        }
        bookmark = source.getBookmark();

        if (receive) {
          match = recorder.playMatch(elementList, source.getBookmark());
        } else {
          int index = recorder.reserveMatchIndex(level, elementList, source.getBookmark(), parentNot, false);
          int sourceIndex = source.getBestIndex();
          match = elementList.parse(level, source, not|parentNot, caseSensitive, false);
          match = (match && source.getBookmark() != bookmark);
          recorder.set(level, source, elementList, bookmark, source.getBookmark(), sourceIndex, index, match, parentNot, false);
        }
      }
    }

    if (!match) {
View Full Code Here

TOP

Related Classes of net.sf.laja.parser.engine2.Recorder

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.