Last active
August 29, 2015 14:14
-
-
Save fge/c6ed9c575cad15942eea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.parboiled1.grappa.samples; | |
import com.github.parboiled1.grappa.parsers.EventBusParser; | |
import org.parboiled.Rule; | |
import org.parboiled.support.Var; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class TestGrammar2 | |
extends EventBusParser<String> | |
{ | |
protected final Map<String, String> collectedValues | |
= new HashMap<String, String>(); | |
protected final Var<String> var = new Var<String>(); | |
Rule key() | |
{ | |
return sequence( | |
firstOf(ignoreCase("sno"), ignoreCase("sname")), | |
var.set(match().toLowerCase()), | |
!collectedValues.containsKey(var.get()) | |
); | |
} | |
Rule separator() | |
{ | |
return optional(anyOf(":-*_ ")); | |
} | |
Rule value() | |
{ | |
return sequence( | |
oneOrMore(testNot(wsp()), ANY), | |
collectedValues.put(var.get(), match()) == null | |
); | |
} | |
Rule oneLine() | |
{ | |
return join(sequence(key(), separator(), value())) | |
.using(oneOrMore(wsp())) | |
.min(2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment