Fixed parser weirdness. More readable parser finished.
For whatever reason, writing the parser in Groovy was causing weird errors to occur when the parser or parse runner was created. Using a plain Java source file fixed this.
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								src/test/TestParser.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/test/TestParser.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										27
									
								
								src/test/TestParser.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/test/TestParser.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
import org.parboiled.BaseParser;
 | 
			
		||||
import org.parboiled.Parboiled;
 | 
			
		||||
import org.parboiled.Rule;
 | 
			
		||||
import org.parboiled.annotations.BuildParseTree;
 | 
			
		||||
import org.parboiled.parserunners.ReportingParseRunner;
 | 
			
		||||
import org.parboiled.support.ParsingResult;
 | 
			
		||||
import static org.parboiled.support.ParseTreeUtils.printNodeTree;
 | 
			
		||||
 | 
			
		||||
@BuildParseTree
 | 
			
		||||
public class TestParser extends BaseParser<Object> {
 | 
			
		||||
 | 
			
		||||
    public Rule S() {
 | 
			
		||||
        return OneOrMore(
 | 
			
		||||
            Sequence(A(), OneOrMore(B()), C())); }
 | 
			
		||||
 | 
			
		||||
    Rule A() { return Ch('a'); }
 | 
			
		||||
    Rule B() { return Ch('b'); }
 | 
			
		||||
    Rule C() { return Ch('c'); }
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        TestParser parser = Parboiled.createParser(TestParser.class);
 | 
			
		||||
        ReportingParseRunner parseRunner = new ReportingParseRunner(parser.S());
 | 
			
		||||
 | 
			
		||||
        ParsingResult result = parseRunner.run("abbbbcabc");
 | 
			
		||||
        System.out.println(result.matched ?  printNodeTree(result) + "\n" : "No Match");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user