Search in sources :

Example 1 with IdentityEventHandler

use of org.whole.lang.events.IdentityEventHandler 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

IdentityEventHandler (org.whole.lang.events.IdentityEventHandler)1 Literal (org.whole.lang.grammars.model.Literal)1 LiteralTerminal (org.whole.lang.grammars.model.LiteralTerminal)1 RegExp (org.whole.lang.grammars.model.RegExp)1 IEntity (org.whole.lang.model.IEntity)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1