Search in sources :

Example 1 with LiteralTerminal

use of org.whole.lang.grammars.model.LiteralTerminal in project whole by wholeplatform.

the class LiteralTerminalPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    LiteralTerminal entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(2);
    list.add(entity.getPattern());
    list.add(entity.getLiteral());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) LiteralTerminal(org.whole.lang.grammars.model.LiteralTerminal) ArrayList(java.util.ArrayList)

Example 2 with LiteralTerminal

use of org.whole.lang.grammars.model.LiteralTerminal in project whole by wholeplatform.

the class GrammarBasedUnparserVisitor method visit.

@Override
public void visit(Grammar entity) {
    LiteralTerminal lt = entity.getDelimiter();
    if (EntityUtils.isNotResolver(lt))
        delimiter = lt.getLiteral().getValue();
    space = EntityUtils.safeStringValue(entity.getSpaceLiteral(), space);
    indent = EntityUtils.safeStringValue(entity.getIndentLiteral(), indent);
    newLine = EntityUtils.safeStringValue(entity.getNewLineLiteral(), newLine);
    normalize(entity);
    if (!appendModelEntityAsFragment())
        nameProductionMap.get(model.wGetEntityDescriptor().getName()).accept(this);
    if (delimited)
        appendDelimiter();
}
Also used : LiteralTerminal(org.whole.lang.grammars.model.LiteralTerminal)

Example 3 with LiteralTerminal

use of org.whole.lang.grammars.model.LiteralTerminal in project whole by wholeplatform.

the class LiteralTerminalParserPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    LiteralTerminal entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(1);
    list.add(entity.getPattern());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) LiteralTerminal(org.whole.lang.grammars.model.LiteralTerminal) ArrayList(java.util.ArrayList)

Example 4 with LiteralTerminal

use of org.whole.lang.grammars.model.LiteralTerminal in project whole by wholeplatform.

the class LiteralTerminalUnparserPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    LiteralTerminal entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(1);
    list.add(entity.getLiteral());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) LiteralTerminal(org.whole.lang.grammars.model.LiteralTerminal) ArrayList(java.util.ArrayList)

Example 5 with LiteralTerminal

use of org.whole.lang.grammars.model.LiteralTerminal in project whole by wholeplatform.

the class GrammarsDefaultEntityRegistryConfiguration method apply.

public void apply(IEntityRegistry er) {
    super.apply(er);
    GrammarsEntityFactory ef = GrammarsEntityFactory.instance(er);
    RegExp regex;
    Literal literal;
    IdentityEventHandler deriveLiteralPattern = new IdentityEventHandler() {

        private static final long serialVersionUID = 1L;

        private String derivedPattern;

        @Override
        public void notifyChanged(IEntity source, FeatureDescriptor featureDesc, String oldValue, String newValue) {
            IEntity parent = source.wGetParent();
            if (parent instanceof LiteralTerminal) {
                LiteralTerminal literalTerminal = (LiteralTerminal) parent;
                Literal literal = literalTerminal.getLiteral();
                if (literal == source) {
                    derivedPattern = StringUtils.quoteRegex(newValue);
                    literalTerminal.getPattern().wSetValue(derivedPattern);
                } else if (newValue != derivedPattern) {
                    source.wRemoveChangeEventHandler(this);
                    literal.wRemoveChangeEventHandler(this);
                }
            }
        }
    };
    er.put(ef.createEmpty(ef.createLiteral("")));
    er.put(ef.createChoose(2));
    er.put(ef.createConcatenate(2));
    er.put(ef.createLiteralTerminal(regex = ef.createRegExp("pattern"), ef.createCategory(CategoryEnum.DELIMITER), literal = ef.createLiteral("literal")));
    regex.wAddChangeEventHandler(deriveLiteralPattern);
    literal.wAddChangeEventHandler(deriveLiteralPattern);
    er.put(ef.createDataTerminal(ef.createRegExp(".*"), ef.createCategory(CategoryEnum.LITERAL), ef.createFormat("%s")));
    er.put(ef.createAs(ef.createNonTerminal("nt"), ef.createName("name")));
    er.put(ef.createByLines(1));
    er.put(ef.createBySize(10));
    er.put(ef.createRepeat(ef.createSize(0), ef.createUnbounded(), ef.buildLiteralTerminal().set(GrammarsFeatureDescriptorEnum.literal, ",").getResult(), createResolver(GrammarsEntityDescriptorEnum.Rule)));
    er.put(ef.createBySize(5));
    er.put(ef.createGrammar(ef.createName("GrammarName"), createResolver(GrammarsEntityDescriptorEnum.TargetLanguage), createResolver(GrammarsEntityDescriptorEnum.NonTerminal), ef.createLiteralTerminal(ef.createRegExp("\\p{javaWhitespace}*"), ef.createCategory(CategoryEnum.SEPARATOR), ef.createLiteral("")), ef.createProductions(0), ef.createProductions(ef.create(GrammarsEntityDescriptorEnum.Production, ef.createNonTerminal("StartSymbol"), createResolver(GrammarsEntityDescriptorEnum.Rule))), // ef.createNamespace("org.whole.examples.grammarname"),
    createResolver(GrammarsEntityDescriptorEnum.URI), createResolver(GrammarsEntityDescriptorEnum.Namespace), createResolver(GrammarsEntityDescriptorEnum.Version), createResolver(GrammarsEntityDescriptorEnum.Literal), createResolver(GrammarsEntityDescriptorEnum.Literal), createResolver(GrammarsEntityDescriptorEnum.Literal)));
}
Also used : IdentityEventHandler(org.whole.lang.events.IdentityEventHandler) RegExp(org.whole.lang.grammars.model.RegExp) IEntity(org.whole.lang.model.IEntity) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) Literal(org.whole.lang.grammars.model.Literal) LiteralTerminal(org.whole.lang.grammars.model.LiteralTerminal)

Aggregations

LiteralTerminal (org.whole.lang.grammars.model.LiteralTerminal)5 IEntity (org.whole.lang.model.IEntity)4 ArrayList (java.util.ArrayList)3 IdentityEventHandler (org.whole.lang.events.IdentityEventHandler)1 Literal (org.whole.lang.grammars.model.Literal)1 RegExp (org.whole.lang.grammars.model.RegExp)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1