Package it.halfone.parser

Examples of it.halfone.parser.Parser


        stepMap.put(tokens[i], new ArrayList<Step>(successorList));
      }
    }

    return new Parser(stepMap, tokens[0], tokens[symbolList.size() - 1]);
  }
View Full Code Here


    Assert.assertTrue(literal.compile().match(literalValue));
   
    literal.boost(5);
    Assert.assertTrue(literal.compile().match(literalValue));

    Parser parser = literal.then(literal).compile();
    Assert.assertTrue(parser.match(literalValue + literalValue));
    Assert.assertFalse(parser.match(""));
    Assert.assertFalse(parser.match(literalValue));
    Assert.assertFalse(parser.match(literalValue + literalValue + literalValue));
   
    parser = literal.or("").compile();
    Assert.assertTrue(parser.match(literalValue));
    Assert.assertTrue(parser.match(""));
    Assert.assertFalse(parser.match(literalValue + literalValue));
   
    parser = literal.atLeast(3).compile();
    Assert.assertTrue(parser.match(literalValue + literalValue + literalValue));
    Assert.assertTrue(parser.match(literalValue + literalValue + literalValue + literalValue));
    Assert.assertTrue(parser.match(literalValue + literalValue + literalValue + literalValue + literalValue + literalValue));
    Assert.assertFalse(parser.match(""));
    Assert.assertFalse(parser.match(literalValue));
    Assert.assertFalse(parser.match(literalValue + literalValue));
   
    parser = literal.mark("value").compile();
    Assert.assertTrue(parser.parseBest(literalValue).get("value").contains(literalValue));
   
    // Boost Test
    Regex anyStar = Regex.any().star().mark("any");
    Regex aStar = Regex.literal("a").star().boost(1).mark("a");
    parser = anyStar.then(aStar).compile();
    Assert.assertTrue(parser.parseBest("aaa").get("a").contains("aaa"));
   
  }
View Full Code Here

    Assert.assertTrue(literal.compile().match(literalValue));
   
    literal.boost(5);
    Assert.assertTrue(literal.compile().match(literalValue));

    Parser parser = literal.then(literal).compile();
    Assert.assertTrue(parser.match(literalValue + literalValue));
    Assert.assertFalse(parser.match(""));
    Assert.assertFalse(parser.match(literalValue));
    Assert.assertFalse(parser.match(literalValue + literalValue + literalValue));
   
    parser = literal.or("").compile();
    Assert.assertTrue(parser.match(literalValue));
    Assert.assertTrue(parser.match(""));
    Assert.assertFalse(parser.match(literalValue + literalValue));
   
    parser = literal.atLeast(3).compile();
    Assert.assertTrue(parser.match(literalValue + literalValue + literalValue));
    Assert.assertTrue(parser.match(literalValue + literalValue + literalValue + literalValue));
    Assert.assertTrue(parser.match(literalValue + literalValue + literalValue + literalValue + literalValue + literalValue));
    Assert.assertFalse(parser.match(""));
    Assert.assertFalse(parser.match(literalValue));
    Assert.assertFalse(parser.match(literalValue + literalValue));
   
    parser = literal.mark("value").compile();
    Assert.assertTrue(parser.parseBest(literalValue).get("value").contains(literalValue));
   
    //self test
    parser = self.compile();
    Assert.assertTrue(parser.match("a"));
    Assert.assertTrue(parser.match("(a)"));
    Assert.assertTrue(parser.match("((a))"));
   
    Assert.assertFalse(parser.match(""));
    Assert.assertFalse(parser.match("(a))"));
    Assert.assertFalse(parser.match("((a)"));
   
    //Best Parse Test
    System.out.println(parser.bestMatch("(a))"));
    Assert.assertTrue(parser.bestMatch("(a))").equals("(a)"));
   
    parser = Regex.literal("andrea").compile();
    Assert.assertTrue(parser.bestMatch("andrew").equals("andre"));
   
    // Boost Test
    Regex anyStar = Regex.any().star().mark("any");
    Regex aStar = Regex.literal("a").star().boost(1).mark("a");
    parser = anyStar.then(aStar).compile();
    Assert.assertTrue(parser.parseBest("aaa").get("a").contains("aaa"));
   
   
   
   
  }
View Full Code Here

TOP

Related Classes of it.halfone.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.