Package gherkin.parser

Examples of gherkin.parser.Parser


            }
          }
        }

      };
      new Parser(formatter).parse(storyAsText, "", 0);
      return out.toString();
    }
View Full Code Here


        if (doReformat()) {
            try {
                String source = context.document().getText(0, context.document().getLength());
                StringWriter reformattedWriter = new StringWriter();
                PrettyFormatter formatter = new PrettyFormatter(reformattedWriter, true);
                Parser parser = new Parser(formatter, true);
                parser.parse(source, "UNKNOWN", 0); //parser.parse(input, file.getPath(), 0);
                writeSource(reformattedWriter.getBuffer().toString());
            } catch (Exception e) {
                showError(e);
            }
        }
View Full Code Here

        featureBuilder.append("\t|a|b|\n");
        featureBuilder.append("Then should formatt beautifully.\n");
        String feature = featureBuilder.toString();

        Formatter formatter = new PrettyFormatter(new CheckingAppendable(), false, false);
        new Parser(formatter).parse(feature, "", 0);
        formatter.close();
    }
View Full Code Here

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(baos);

        Formatter formatter = new PrettyFormatter(out, true, false);
        new Parser(formatter).parse(feature, "", 0);
        formatter.close();

        List<String> lines = extractLines(baos);

        return lines;
View Full Code Here

    private final Writer out;

    public Main(final Writer out) {
        this.out = out;
        final Formatter formatter = new PrettyFormatter(out, false, true);
        parser = new Parser(formatter);
    }
View Full Code Here

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintWriter out = new PrintWriter(output);
    Formatter formatter = new PrettyFormatter(out, true, false);

    Parser parser = new Parser(formatter);
    parser.parse(gherkin, "", 0);

    out.flush();

    String should_be = GherkinTestFixtures.formatted_feature;
    org.hamcrest.CoreMatchers.is(should_be);
View Full Code Here

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintWriter out = new PrintWriter(output);
    Formatter formatter = new PrettyFormatter(out, true, false);

    // parse
    new Parser(formatter).parse(contents, "", 0);

    out.flush();
    return output.toString();
  }
View Full Code Here

   * initialReconcile()
   */
  @Override
  public void initialReconcile() {
    final List<Position> ranges = new ArrayList<Position>();
    Parser p = new Parser(new Formatter() {

      private Stack<PositionedElement> stack = new Stack<PositionedElement>();

      @Override
      public void uri(String arg0) {
      }

      @Override
      public void syntaxError(String arg0, String arg1,
          List<String> arg2, String arg3, Integer arg4) {
      }

      @Override
      public void step(Step arg0) {
      }

      private boolean isStepContainer(BasicStatement stmt) {
        return stmt instanceof Scenario
            || stmt instanceof ScenarioOutline
            || stmt instanceof Background;
      }

      private boolean isExamples(BasicStatement stmt) {
        return stmt instanceof Examples;
      }

      @Override
      public void scenarioOutline(ScenarioOutline arg0) {
        try {
          handleStepContainer(arg0);
        } catch (BadLocationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }

      private void handleStepContainer(DescribedStatement stmt)
          throws BadLocationException {
        if (isExamples(stack.peek().getStatement())) {
          PositionedElement pos = stack.pop();
          pos.setEndLine(stmt.getLine() - 1);
          ranges.add(pos.toPosition());
        }
        if (isStepContainer(stack.peek().getStatement())) {
          PositionedElement pos = stack.pop();
          pos.setEndLine(stmt.getLine() - 1);
          ranges.add(pos.toPosition());
        }
        stack.push(new PositionedElement(document, stmt));
      }

      @Override
      public void scenario(Scenario arg0) {
        try {
          handleStepContainer(arg0);
        } catch (BadLocationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }

      @Override
      public void feature(Feature arg0) {
        stack.push(new PositionedElement(document, arg0));
      }

      @Override
      public void examples(Examples arg0) {
        stack.push(new PositionedElement(document, arg0));
      }

      @Override
      public void eof() {
        int lastline = document.getNumberOfLines();
        while (!stack.isEmpty()) {
          PositionedElement pos = stack.pop();
          try {
            pos.setEndLine(lastline);
            ranges.add(pos.toPosition());
          } catch (BadLocationException e) {
          }
        }
      }

      @Override
      public void done() {
      }

      @Override
      public void close() {
      }

      @Override
      public void background(Background arg0) {
        try {
          handleStepContainer(arg0);
        } catch (BadLocationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    });
    try {
      p.parse(document.get(), "", 0);
      Display.getDefault().asyncExec(new Runnable() {
        public void run() {
          editor.updateFoldingStructure(ranges);
        }

View Full Code Here

    IDocument doc = getDocumentProvider().getDocument(input);
    GherkinErrorMarker marker = new GherkinErrorMarker(
        ((IFileEditorInput) input).getFile(), doc);
    marker.removeExistingMarkers();

    Parser p = new Parser(marker, false);
    try {
      p.parse(doc.get(), "", 0);
    } catch (LexingError l) {
    }

  }
View Full Code Here

TOP

Related Classes of gherkin.parser.Parser

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.