Search in sources :

Example 26 with EnumRule

use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.

the class AntlrGrammarGenerator method _ebnf2.

@Override
protected String _ebnf2(final RuleCall it, final AntlrOptions options, final boolean supportActions) {
    String _xifexpression = null;
    if ((!supportActions)) {
        _xifexpression = super._ebnf2(it, options, supportActions);
    } else {
        String _switchResult = null;
        AbstractRule _rule = it.getRule();
        final AbstractRule rule = _rule;
        boolean _matched = false;
        if (rule instanceof EnumRule) {
            boolean _isAssigned = GrammarUtil.isAssigned(it);
            if (_isAssigned) {
                _matched = true;
            }
        }
        if (!_matched) {
            if (rule instanceof ParserRule) {
                boolean _isAssigned = GrammarUtil.isAssigned(it);
                if (_isAssigned) {
                    _matched = true;
                }
            }
        }
        if (_matched) {
            _switchResult = super._ebnf2(it, options, supportActions);
        }
        if (!_matched) {
            if (rule instanceof EnumRule) {
                _matched = true;
            }
            if (!_matched) {
                if (rule instanceof ParserRule) {
                    boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule) rule)));
                    if (_isDatatypeRule) {
                        _matched = true;
                    }
                }
            }
            if (_matched) {
                StringConcatenation _builder = new StringConcatenation();
                {
                    boolean _isBacktrack = options.isBacktrack();
                    if (_isBacktrack) {
                        _builder.append("{");
                        _builder.newLine();
                        _builder.append("\t");
                        _builder.append("/* */");
                        _builder.newLine();
                        _builder.append("}");
                        _builder.newLine();
                    }
                }
                _builder.append("{");
                _builder.newLine();
                _builder.append("\t");
                CharSequence _newCompositeNode = this.newCompositeNode(it);
                _builder.append(_newCompositeNode, "\t");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
                String __ebnf2 = super._ebnf2(it, options, supportActions);
                _builder.append(__ebnf2);
                _builder.newLineIfNotEmpty();
                _builder.append("{");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("afterParserOrEnumRuleCall();");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
                _switchResult = _builder.toString();
            }
        }
        if (!_matched) {
            if (rule instanceof ParserRule) {
                _matched = true;
                StringConcatenation _builder_1 = new StringConcatenation();
                {
                    boolean _isBacktrack_1 = options.isBacktrack();
                    if (_isBacktrack_1) {
                        _builder_1.append("{");
                        _builder_1.newLine();
                        _builder_1.append("\t");
                        _builder_1.append("/* */");
                        _builder_1.newLine();
                        _builder_1.append("}");
                        _builder_1.newLine();
                    }
                }
                _builder_1.append("{");
                _builder_1.newLine();
                {
                    boolean _isEObjectFragmentRuleCall = GrammarUtil.isEObjectFragmentRuleCall(it);
                    if (_isEObjectFragmentRuleCall) {
                        _builder_1.append("\t");
                        _builder_1.append("if ($current==null) {");
                        _builder_1.newLine();
                        _builder_1.append("\t");
                        _builder_1.append("\t");
                        _builder_1.append("$current = ");
                        CharSequence _createModelElement = this.createModelElement(it);
                        _builder_1.append(_createModelElement, "\t\t");
                        _builder_1.append(";");
                        _builder_1.newLineIfNotEmpty();
                        _builder_1.append("\t");
                        _builder_1.append("}");
                        _builder_1.newLine();
                    }
                }
                _builder_1.append("\t");
                CharSequence _newCompositeNode_1 = this.newCompositeNode(it);
                _builder_1.append(_newCompositeNode_1, "\t");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("}");
                _builder_1.newLine();
                String _localVar = this._grammarAccessExtensions.localVar(it);
                _builder_1.append(_localVar);
                _builder_1.append("=");
                String __ebnf2_1 = super._ebnf2(it, options, supportActions);
                _builder_1.append(__ebnf2_1);
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("{");
                _builder_1.newLine();
                _builder_1.append("\t");
                _builder_1.append("$current = $");
                String _localVar_1 = this._grammarAccessExtensions.localVar(it);
                _builder_1.append(_localVar_1, "\t");
                _builder_1.append(".current;");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("\t");
                _builder_1.append("afterParserOrEnumRuleCall();");
                _builder_1.newLine();
                _builder_1.append("}");
                _builder_1.newLine();
                _switchResult = _builder_1.toString();
            }
        }
        if (!_matched) {
            if (rule instanceof TerminalRule) {
                _matched = true;
                StringConcatenation _builder_1 = new StringConcatenation();
                String _localVar = this._grammarAccessExtensions.localVar(it);
                _builder_1.append(_localVar);
                _builder_1.append("=");
                String __ebnf2_1 = super._ebnf2(it, options, supportActions);
                _builder_1.append(__ebnf2_1);
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("{");
                _builder_1.newLine();
                _builder_1.append("\t");
                CharSequence _newLeafNode = this.newLeafNode(it, this._grammarAccessExtensions.localVar(it));
                _builder_1.append(_newLeafNode, "\t");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("}");
                _builder_1.newLine();
                _switchResult = _builder_1.toString();
            }
        }
        if (!_matched) {
            _switchResult = super._ebnf2(it, options, supportActions);
        }
        _xifexpression = _switchResult;
    }
    return _xifexpression;
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 27 with EnumRule

use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.

the class AntlrGrammarGenerator method crossrefEbnf.

@Override
protected String crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) {
    String _xifexpression = null;
    if (supportActions) {
        String _switchResult = null;
        boolean _matched = false;
        if (it instanceof EnumRule) {
            _matched = true;
        }
        if (!_matched) {
            if (it instanceof ParserRule) {
                _matched = true;
            }
        }
        if (_matched) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t");
            CharSequence _newCompositeNode = this.newCompositeNode(ref);
            _builder.append(_newCompositeNode, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("}");
            _builder.newLine();
            String _ruleName = this._grammarAccessExtensions.ruleName(it);
            _builder.append(_ruleName);
            String _argumentList = AntlrGrammarGenUtil.getArgumentList(call, this.isPassCurrentIntoFragment(), (!supportActions));
            _builder.append(_argumentList);
            _builder.newLineIfNotEmpty();
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("afterParserOrEnumRuleCall();");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
            _switchResult = _builder.toString();
        }
        if (!_matched) {
            if (it instanceof TerminalRule) {
                _matched = true;
                StringConcatenation _builder_1 = new StringConcatenation();
                String _localVar = this._grammarAccessExtensions.localVar(GrammarUtil.containingAssignment(ref));
                _builder_1.append(_localVar);
                _builder_1.append("=");
                String _ruleName_1 = this._grammarAccessExtensions.ruleName(it);
                _builder_1.append(_ruleName_1);
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("{");
                _builder_1.newLine();
                _builder_1.append("\t");
                CharSequence _newLeafNode = this.newLeafNode(ref, this._grammarAccessExtensions.localVar(GrammarUtil.containingAssignment(ref)));
                _builder_1.append(_newLeafNode, "\t");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("}");
                _builder_1.newLine();
                _switchResult = _builder_1.toString();
            }
        }
        if (!_matched) {
            throw new IllegalStateException(("crossrefEbnf is not supported for " + it));
        }
        _xifexpression = _switchResult;
    } else {
        _xifexpression = super.crossrefEbnf(it, call, ref, supportActions);
    }
    return _xifexpression;
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TerminalRule(org.eclipse.xtext.TerminalRule)

Example 28 with EnumRule

use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.

the class AntlrGrammarGenerator method _assignmentEbnf.

@Override
protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
    String _xifexpression = null;
    if (supportActions) {
        String _switchResult = null;
        AbstractRule _rule = it.getRule();
        boolean _matched = false;
        if (_rule instanceof EnumRule) {
            _matched = true;
        }
        if (!_matched) {
            if (_rule instanceof ParserRule) {
                _matched = true;
            }
        }
        if (_matched) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t");
            CharSequence _newCompositeNode = this.newCompositeNode(it);
            _builder.append(_newCompositeNode, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("}");
            _builder.newLine();
            String _localVar = this._grammarAccessExtensions.localVar(assignment, it);
            _builder.append(_localVar);
            _builder.append("=");
            String __assignmentEbnf = super._assignmentEbnf(it, assignment, options, supportActions);
            _builder.append(__assignmentEbnf);
            _builder.newLineIfNotEmpty();
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("if ($current==null) {");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("$current = ");
            CharSequence _createModelElementForParent = this.createModelElementForParent(assignment);
            _builder.append(_createModelElementForParent, "\t\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            String _setOrAdd = this._grammarAccessExtensions.setOrAdd(assignment);
            _builder.append(_setOrAdd, "\t");
            _builder.append("(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("$current,");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\"");
            String _feature = assignment.getFeature();
            _builder.append(_feature, "\t\t");
            _builder.append("\",");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            {
                boolean _isBooleanAssignment = GrammarUtil.isBooleanAssignment(assignment);
                if (_isBooleanAssignment) {
                    _builder.append("true");
                } else {
                    String _localVar_1 = this._grammarAccessExtensions.localVar(assignment, it);
                    _builder.append(_localVar_1, "\t\t");
                }
            }
            _builder.append(",");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            CharSequence _stringLiteral = this._grammarAccessExtensions.toStringLiteral(it);
            _builder.append(_stringLiteral, "\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("afterParserOrEnumRuleCall();");
            _builder.newLine();
            _builder.append("}");
            _builder.newLine();
            _switchResult = _builder.toString();
        }
        if (!_matched) {
            if (_rule instanceof TerminalRule) {
                _matched = true;
                StringConcatenation _builder_1 = new StringConcatenation();
                String _localVar_2 = this._grammarAccessExtensions.localVar(assignment, it);
                _builder_1.append(_localVar_2);
                _builder_1.append("=");
                String __assignmentEbnf_1 = super._assignmentEbnf(it, assignment, options, supportActions);
                _builder_1.append(__assignmentEbnf_1);
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("{");
                _builder_1.newLine();
                _builder_1.append("\t");
                CharSequence _newLeafNode = this.newLeafNode(it, this._grammarAccessExtensions.localVar(assignment, it));
                _builder_1.append(_newLeafNode, "\t");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("}");
                _builder_1.newLine();
                _builder_1.append("{");
                _builder_1.newLine();
                _builder_1.append("\t");
                _builder_1.append("if ($current==null) {");
                _builder_1.newLine();
                _builder_1.append("\t\t");
                _builder_1.append("$current = ");
                CharSequence _createModelElement = this.createModelElement(assignment);
                _builder_1.append(_createModelElement, "\t\t");
                _builder_1.append(";");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("\t");
                _builder_1.append("}");
                _builder_1.newLine();
                _builder_1.append("\t");
                String _setOrAdd_1 = this._grammarAccessExtensions.setOrAdd(assignment);
                _builder_1.append(_setOrAdd_1, "\t");
                _builder_1.append("WithLastConsumed(");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("\t\t");
                _builder_1.append("$current,");
                _builder_1.newLine();
                _builder_1.append("\t\t");
                _builder_1.append("\"");
                String _feature_1 = assignment.getFeature();
                _builder_1.append(_feature_1, "\t\t");
                _builder_1.append("\",");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("\t\t");
                {
                    boolean _isBooleanAssignment_1 = GrammarUtil.isBooleanAssignment(assignment);
                    if (_isBooleanAssignment_1) {
                        _builder_1.append("true");
                    } else {
                        String _localVar_3 = this._grammarAccessExtensions.localVar(assignment, it);
                        _builder_1.append(_localVar_3, "\t\t");
                    }
                }
                _builder_1.append(",");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("\t\t");
                CharSequence _stringLiteral_1 = this._grammarAccessExtensions.toStringLiteral(it);
                _builder_1.append(_stringLiteral_1, "\t\t");
                _builder_1.append(");");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("}");
                _builder_1.newLine();
                _switchResult = _builder_1.toString();
            }
        }
        if (!_matched) {
            throw new IllegalStateException(("assignmentEbnf is not supported for " + it));
        }
        _xifexpression = _switchResult;
    } else {
        _xifexpression = super._assignmentEbnf(it, assignment, options, supportActions);
    }
    return _xifexpression;
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule)

Example 29 with EnumRule

use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.

the class AntlrGrammarGenerator method _dataTypeEbnf2.

@Override
protected String _dataTypeEbnf2(final RuleCall it, final boolean supportActions) {
    String _xifexpression = null;
    if (supportActions) {
        String _switchResult = null;
        AbstractRule _rule = it.getRule();
        boolean _matched = false;
        if (_rule instanceof EnumRule) {
            boolean _isAssigned = GrammarUtil.isAssigned(it);
            if (_isAssigned) {
                _matched = true;
            }
        }
        if (!_matched) {
            if (_rule instanceof ParserRule) {
                boolean _isAssigned = GrammarUtil.isAssigned(it);
                if (_isAssigned) {
                    _matched = true;
                }
            }
        }
        if (_matched) {
            _switchResult = super._dataTypeEbnf2(it, supportActions);
        }
        if (!_matched) {
            if (_rule instanceof EnumRule) {
                _matched = true;
            }
            if (!_matched) {
                if (_rule instanceof ParserRule) {
                    _matched = true;
                }
            }
            if (_matched) {
                StringConcatenation _builder = new StringConcatenation();
                _builder.append("{");
                _builder.newLine();
                _builder.append("\t");
                CharSequence _newCompositeNode = this.newCompositeNode(it);
                _builder.append(_newCompositeNode, "\t");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
                String _localVar = this._grammarAccessExtensions.localVar(it);
                _builder.append(_localVar);
                _builder.append("=");
                String __dataTypeEbnf2 = super._dataTypeEbnf2(it, supportActions);
                _builder.append(__dataTypeEbnf2);
                String _argumentList = AntlrGrammarGenUtil.getArgumentList(it, this.isPassCurrentIntoFragment(), (!supportActions));
                _builder.append(_argumentList);
                _builder.newLineIfNotEmpty();
                _builder.append("{");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("$current.merge(");
                String _localVar_1 = this._grammarAccessExtensions.localVar(it);
                _builder.append(_localVar_1, "\t");
                _builder.append(");");
                _builder.newLineIfNotEmpty();
                _builder.append("}");
                _builder.newLine();
                _builder.append("{");
                _builder.newLine();
                _builder.append("\t");
                _builder.append("afterParserOrEnumRuleCall();");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
                _switchResult = _builder.toString();
            }
        }
        if (!_matched) {
            if (_rule instanceof TerminalRule) {
                _matched = true;
                StringConcatenation _builder_1 = new StringConcatenation();
                String _localVar_2 = this._grammarAccessExtensions.localVar(it);
                _builder_1.append(_localVar_2);
                _builder_1.append("=");
                String __dataTypeEbnf2_1 = super._dataTypeEbnf2(it, supportActions);
                _builder_1.append(__dataTypeEbnf2_1);
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("{");
                _builder_1.newLine();
                _builder_1.append("\t");
                _builder_1.append("$current.merge(");
                String _localVar_3 = this._grammarAccessExtensions.localVar(it);
                _builder_1.append(_localVar_3, "\t");
                _builder_1.append(");");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("}");
                _builder_1.newLine();
                _builder_1.append("{");
                _builder_1.newLine();
                _builder_1.append("\t");
                CharSequence _newLeafNode = this.newLeafNode(it, this._grammarAccessExtensions.localVar(it));
                _builder_1.append(_newLeafNode, "\t");
                _builder_1.newLineIfNotEmpty();
                _builder_1.append("}");
                _builder_1.newLine();
                _switchResult = _builder_1.toString();
            }
        }
        if (!_matched) {
            _switchResult = super._dataTypeEbnf2(it, supportActions);
        }
        _xifexpression = _switchResult;
    } else {
        _xifexpression = super._dataTypeEbnf2(it, supportActions);
    }
    return _xifexpression;
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) TerminalRule(org.eclipse.xtext.TerminalRule) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

EnumRule (org.eclipse.xtext.EnumRule)29 ParserRule (org.eclipse.xtext.ParserRule)21 TerminalRule (org.eclipse.xtext.TerminalRule)17 AbstractRule (org.eclipse.xtext.AbstractRule)14 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)9 RuleCall (org.eclipse.xtext.RuleCall)9 EnumLiteralDeclaration (org.eclipse.xtext.EnumLiteralDeclaration)8 EEnum (org.eclipse.emf.ecore.EEnum)5 EPackage (org.eclipse.emf.ecore.EPackage)5 Grammar (org.eclipse.xtext.Grammar)5 List (java.util.List)4 EObject (org.eclipse.emf.ecore.EObject)4 Action (org.eclipse.xtext.Action)4 Assignment (org.eclipse.xtext.Assignment)4 Keyword (org.eclipse.xtext.Keyword)4 TypeRef (org.eclipse.xtext.TypeRef)4 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)3 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)3 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)3 CrossReference (org.eclipse.xtext.CrossReference)3