Beispiel #1
0
 @Test
 public void negativeForwardAssertion1() {
   String[] rules = {
     "ROOT = 'a' ! /\\B/", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.matches("a").match());
 }
Beispiel #2
0
 @Test
 public void literal() {
   String[] rules = {
     "ROOT = 'a'", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.matches("a").match());
 }
Beispiel #3
0
 @Test
 public void forwardAssertion2() {
   String[] rules = {
     "ROOT = 'a' ~+ /\\b/", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.matches("a").match());
 }
Beispiel #4
0
 @Test
 public void tag() {
   String[] rules = {
     "ROOT = [{foo} 'a']", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.matches("a").match().first("foo"));
 }
Beispiel #5
0
 @Test
 public void backreference() {
   String[] rules = {
     "ROOT = 'a' 'b' 1", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.matches("aba").match());
 }
Beispiel #6
0
 @Test
 public void alternation() {
   String[] rules = {
     "ROOT = 'a' | 'b'", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.matches("b").match());
 }
Beispiel #7
0
 @Test
 public void regex() {
   String[] rules = {
     "ROOT = /a/i", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.matches("A").match());
 }
Beispiel #8
0
 @Test
 public void negativeBackwardAssertion() {
   String[] rules = {
     "ROOT = !- 'b' 'a'", //
   };
   Grammar g = new Grammar(new Grammar(rules).describe());
   assertNotNull(g.find("a").match());
 }
Beispiel #9
0
 @Test
 public void cycle() {
   String[] rules = {
     "ROOT = 'a' | <ROOT> 'b'", //
   };
   Grammar g = new Grammar(rules);
   assertNotNull(g.matches("ab").match());
   String s = g.describe();
   g = new Grammar(s);
   assertNotNull(g.matches("ab").match());
 }
Beispiel #10
0
 @Test
 public void basicTest() throws GrammarException, IOException {
   String[] rules = {
     //
     "<ROOT> = <a> <s> <b>", //
     "<a> = 'a'", //
     "<b> = 'b'", //
     "<s> = /\\s++/", //
   };
   Grammar g = new Grammar(rules);
   String s = "a\nb";
   Matcher m = g.find(s);
   assertNotNull("found joe", m.match());
 }