~ubuntu-branches/ubuntu/wily/parboiled/wily-proposed

« back to all changes in this revision

Viewing changes to examples-java/src/main/java/org/parboiled/examples/indenting/Main.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2014-11-10 21:10:42 UTC
  • Revision ID: package-import@ubuntu.com-20141110211042-wcmfz25icr5ituj5
Tags: upstream-1.1.6
ImportĀ upstreamĀ versionĀ 1.1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.parboiled.examples.indenting;
 
2
 
 
3
import static org.parboiled.support.ParseTreeUtils.printNodeTree;
 
4
 
 
5
import org.parboiled.Parboiled;
 
6
import org.parboiled.buffers.IndentDedentInputBuffer;
 
7
import org.parboiled.errors.ErrorUtils;
 
8
import org.parboiled.parserunners.ReportingParseRunner;
 
9
import org.parboiled.support.ParsingResult;
 
10
 
 
11
public class Main {
 
12
 
 
13
    public static void main(String[] args) {
 
14
        SimpleIndent parser = Parboiled.createParser(SimpleIndent.class);
 
15
        String input = "NodeA \n\tNodeB\n\tNodeC \n\t\tNodeD \nNodeE";
 
16
 
 
17
        ParsingResult<?> result = new ReportingParseRunner(parser.Parent())
 
18
                .run(new IndentDedentInputBuffer(input.toCharArray(), 2, ";", true, true));
 
19
 
 
20
        if (!result.parseErrors.isEmpty()) {
 
21
            System.out.println(ErrorUtils.printParseError(result.parseErrors
 
22
                    .get(0)));
 
23
        } else {
 
24
            System.out.println("NodeTree: " + printNodeTree(result) + '\n');
 
25
            Object value = result.parseTreeRoot.getValue();
 
26
            System.out.println(value.toString());
 
27
        }
 
28
 
 
29
    }
 
30
}
 
 
b'\\ No newline at end of file'