Search in sources :

Example 1 with GrammarsEntityFactory

use of org.whole.lang.grammars.factories.GrammarsEntityFactory in project whole by wholeplatform.

the class GrammarsActionsHelpers method calculateDataType.

public static Template calculateDataType(Format format) {
    GrammarsEntityFactory gef = GrammarsEntityFactory.instance;
    Matcher matcher = formatPattern.matcher(format.getValue());
    while (matcher.find()) {
        String conversion = null;
        int groupCount = matcher.groupCount();
        while ((conversion = matcher.group(groupCount--)) == null) ;
        switch(conversion.charAt(0)) {
            case 'b':
            case 'B':
                return gef.createDataType(DataTypeEnum.BOOLEAN);
            case 'h':
            case 'H':
                return gef.createCustomDataType("java.lang.Object");
            case 's':
            case 'S':
                return gef.createDataType(DataTypeEnum.STRING);
            case 'c':
            case 'C':
                return gef.createDataType(DataTypeEnum.CHAR);
            case 'd':
            case 'o':
            case 'x':
            case 'X':
                return gef.createDataType(DataTypeEnum.INT);
            case 'e':
            case 'E':
            case 'f':
            case 'g':
            case 'G':
            case 'a':
            case 'A':
                return gef.createDataType(DataTypeEnum.FLOAT);
            case 't':
            case 'T':
                return gef.createDataType(DataTypeEnum.DATE);
        }
    }
    return gef.createDataType(DataTypeEnum.STRING);
}
Also used : Matcher(java.util.regex.Matcher) GrammarsEntityFactory(org.whole.lang.grammars.factories.GrammarsEntityFactory)

Example 2 with GrammarsEntityFactory

use of org.whole.lang.grammars.factories.GrammarsEntityFactory 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));
}
Also used : Production(org.whole.lang.grammars.model.Production) GrammarsEntityFactory(org.whole.lang.grammars.factories.GrammarsEntityFactory)

Aggregations

GrammarsEntityFactory (org.whole.lang.grammars.factories.GrammarsEntityFactory)2 Matcher (java.util.regex.Matcher)1 Production (org.whole.lang.grammars.model.Production)1