use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testPathByNameAndByIndexSteps.
@Test
public void testPathByNameAndByIndexSteps() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
IEntityIterator<NonTerminal> nti = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1"), g);
Assert.assertTrue(nti.hasNext());
Assert.assertSame(prologNt, nti.next());
nti.reset(g.getPhraseStructure());
Assert.assertFalse(nti.hasNext());
nti.reset(g);
Assert.assertTrue(nti.hasNext());
Assert.assertSame(prologNt, nti.next());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class ProductionInlinePart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
Production production = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(3);
list.add(production.getRule());
list.add(production.getName());
list.add(production.getTemplate());
return list;
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class GrammarsUtilsTest method buildGrammar.
public Grammar buildGrammar() {
GrammarsEntityFactory gf = GrammarsEntityFactory.instance;
Production data1 = createProduction(gf.createNonTerminal("MyDataNT1"), gf.createAs(createDataTerminal(gf.createRegExp(".*"), gf.createFormat("%s")), gf.createName("MyDataEntity1")));
Production data2 = createProduction(gf.createNonTerminal("MyDataNT2"), gf.createAs(gf.createConcatenate(createLiteralTerminal("BEFORE_DELIMITER"), createDataTerminal(gf.createRegExp(".*"), gf.createFormat("%s")), createLiteralTerminal("AFTER_DELIMITER")), gf.createName("MyDataEntity2")));
Production enum1 = createProduction(gf.createNonTerminal("MyEnumNT1"), gf.createAs(gf.createChoose(gf.createAs(createLiteralTerminal("L1"), gf.createName("V1")), createLiteralTerminal("V2"), gf.createAs(createLiteralTerminal("L3"), gf.createName("V3"))), gf.createName("MyEnumEntity1")));
Production composite1 = createProduction(gf.createNonTerminal("MyCompositeNT1"), gf.createAs(createRepeat(gf.createNonTerminal("MyComponentNT")), gf.createName("MyCompositeEntity1")));
Production composite2 = createProduction(gf.createNonTerminal("MyCompositeNT2"), gf.createAs(gf.createConcatenate(createLiteralTerminal("BEFORE_DELIMITER"), gf.createRepeat(gf.createSize(0), gf.createUnbounded(), // FIXME gf.createFormat(", "))),
createLiteralTerminal(","), gf.createNonTerminal("MyComponentNT")), createLiteralTerminal("AFTER_DELIMITER")), gf.createName("MyCompositeEntity2")));
Production simple1 = createProduction(gf.createNonTerminal("MySimpleNT1"), gf.createAs(gf.createConcatenate(gf.createAs(gf.createNonTerminal("MyEnumNT1"), gf.createName("feature1")), gf.createAs(gf.createNonTerminal("MyDataNT1"), gf.createName("feature2"))), gf.createName("MySimpleEntity1")));
Production simple2 = createProduction(gf.createNonTerminal("MySimpleNT2"), gf.createAs(gf.createConcatenate(createLiteralTerminal("BEFORE_DELIMITER"), gf.createAs(gf.createNonTerminal("MyEnumNT1"), gf.createName("feature1")), gf.createOptional(gf.createConcatenate(createLiteralTerminal("FEATURE_DELIMITER"), gf.createAs(gf.createNonTerminal("MyDataNT1"), gf.createName("feature2")))), createLiteralTerminal("AFTER_DELIMITER")), gf.createName("MySimpleEntity2")));
Production abstract1 = createProduction(gf.createNonTerminal("MyComponentNT"), gf.createAs(gf.createChoose(gf.createNonTerminal("MySimpleEntity1"), gf.createNonTerminal("MyDataNT1")), gf.createName("MyAbstractEntity1")));
Production abstract2 = createProduction(gf.createNonTerminal("MyComponentNT2"), gf.createAs(gf.createConcatenate(gf.createAs(gf.createNonTerminal("MyEnumNT1"), gf.createName("inheritedFeature1")), gf.createAs(gf.createNonTerminal("MyDataNT1"), gf.createName("inheritedFeature2")), gf.createChoose(gf.createNonTerminal("MySimpleEntity1"), gf.createNonTerminal("MySimpleEntity2"))), gf.createName("MyAbstractEntity2")));
return createGrammar(gf.createName("MyGrammar"), gf.createURI("MyLanguage"), gf.createProductions(), gf.createProductions(simple1, simple2, abstract1, abstract2, composite1, composite2, enum1, data1, data2));
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testSequenceIterator.
@SuppressWarnings("unchecked")
@Test
public void testSequenceIterator() {
Grammar g = new TestXmlGrammar().create();
Productions p1 = g.getPhraseStructure();
Productions p2 = g.getLexicalStructure();
List<Production> p3 = new ArrayList<Production>();
IEntityIterator<Production> i11 = IteratorFactory.<Production>childIterator();
i11.reset(p1);
for (Production p : i11) p3.add(p);
IEntityIterator<Production> i12 = IteratorFactory.<Production>childIterator();
i12.reset(p2);
for (Production p : i12) p3.add(p);
Iterator<Production> i = p3.iterator();
IEntityIterator<Production> i21 = IteratorFactory.<Production>childIterator();
i21.reset(p1);
IEntityIterator<Production> i22 = IteratorFactory.<Production>childIterator();
i22.reset(p2);
for (Production p : IteratorFactory.sequenceIterator(i21, i22)) assertSame(i.next(), p);
// FIXME remove <NonTerminal> from topDownIterators
IEntityIterator<NonTerminal> i1p1 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i1p1.reset(p1);
IEntityIterator<NonTerminal> i1p2 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i1p2.reset(p2);
IEntityIterator<NonTerminal> i1 = IteratorFactory.<NonTerminal>matcherIterator(IteratorFactory.sequenceIterator(i1p1, i1p2)).withPattern(GrammarsEntityDescriptorEnum.NonTerminal);
IEntityIterator<NonTerminal> i2p1 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i2p1.reset(p1);
IEntityIterator<NonTerminal> i2p2 = IteratorFactory.<NonTerminal>descendantOrSelfIterator();
i2p2.reset(p2);
IEntityIterator<NonTerminal> i2 = IteratorFactory.sequenceIterator(IteratorFactory.<NonTerminal>matcherIterator(i2p1).withPattern(GrammarsEntityDescriptorEnum.NonTerminal), IteratorFactory.matcherIterator(i2p2).withPattern(GrammarsEntityDescriptorEnum.NonTerminal));
for (NonTerminal nt : i1) assertSame(i2.next(), nt);
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testChildReverseIterator.
@Test
public void testChildReverseIterator() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
int index = productions.wSize();
IEntityIterator<Production> ci = IteratorFactory.<Production>childReverseIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(--index), p);
}
index = productions.wSize();
ci = IteratorFactory.<Production>childReverseScannerIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(--index), p);
}
index = productions.wSize();
ci = IteratorFactory.<Production>childReverseMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
assertSame(productions.wGet(--index), p);
}
}
Aggregations