use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testTopDownIteratorAdd.
@Test
public void testTopDownIteratorAdd() {
Grammar g = new TestXmlGrammar().create();
Production production = (Production) g.getPhraseStructure().wGet(3);
Choose choose = (Choose) production.getRule();
int size = choose.wSize();
int count = 0;
Rule rAdded1 = null;
Rule rAdded2 = null;
IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfIterator();
i.reset(production);
i.next();
i.next();
while (i.hasNext()) {
IEntity r = i.next();
assertNotSame(rAdded1, r);
assertNotSame(rAdded2, r);
if (count == 0)
assertSame(choose, r);
else if (count == 1)
i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
else if (count == 10) {
i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
i.add(rAdded2 = GrammarsEntityFactory.instance.createProduction());
}
count++;
}
assertEquals(size + 3, choose.wSize());
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class IteratorFactoryTest method testPrecedingSiblingIterator.
@Test
public void testPrecedingSiblingIterator() {
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
int index = 0;
IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
ci.reset(productions);
while (ci.hasNext()) {
Production p = ci.next();
IEntityIterator<Production> fi = IteratorFactory.<Production>precedingSiblingIterator();
fi.reset(p);
int findex = index++;
for (Production fp : fi) assertSame(productions.wGet(--findex), fp);
}
for (int i = g.wSize() - 1; i >= 0; i--) {
IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>precedingSiblingIterator();
fi.reset(g.wGet(i));
for (int j = i - 1; j >= 0; j--) assertSame(g.wGet(j), fi.next());
}
for (int i = productions.wSize() - 1; i >= 0; i--) {
IEntityIterator<Production> fi = IteratorFactory.<Production>precedingSiblingIterator();
fi.reset(productions.wGet(i));
for (int j = i - 1; j >= 0; j--) assertSame(productions.wGet(j), fi.next());
}
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class Grammars2ModelsVisitor method visit.
@Override
public void visit(Productions entity) {
ModelsEntityFactory mf = ModelsEntityFactory.instance;
ScannerIterator<Production> i = IteratorFactory.<Production>childScannerIterator();
i.reset(entity);
for (Production p : i) {
String eName = getMappedEntityName(p);
ModelDeclaration mDecl = CommonsEntityAdapterFactory.createResolver(ModelsEntityDescriptorEnum.ModelDeclaration);
productionMap.put(p.getName().getValue(), p);
declarationMap.put(eName, mDecl);
modelDeclarations.wAdd(mDecl);
mDecl.setModifiers(mf.createEntityModifiers());
mDecl.setName(mf.createSimpleName(eName));
mDecl.setTypes(mf.createTypes());
}
super.visit(entity);
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class GenericPredictiveParser method wParseStartSymbol.
public void wParseStartSymbol() {
Production production = getProduction(grammar.getStartSymbol());
if (production == null)
throw createParseError("mising start symbol production");
assert !isLexicon(production);
wParse(production);
}
use of org.whole.lang.grammars.model.Production in project whole by wholeplatform.
the class GrammarsPartFactoryVisitor method visit.
@Override
public void visit(NonTerminal entity) {
Object parentEntity = context.getModel();
if (parentEntity instanceof Production && entity == ((Production) parentEntity).getName())
part = new DeclarationTextualEntityPart();
else if (parentEntity instanceof Repeat && entity == ((Repeat) parentEntity).getSeparator())
part = new ContentTextualEntityPart();
else
part = new NonTerminalPart();
}
Aggregations