use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileInit.
@Override
protected String compileInit(final AbstractRule it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
{
if ((it instanceof ParserRule)) {
boolean _isPassCurrentIntoFragment = this.isPassCurrentIntoFragment();
boolean _not = (!_isPassCurrentIntoFragment);
String _parameterList = AntlrGrammarGenUtil.getParameterList(((ParserRule) it), Boolean.valueOf(_not), this.getCurrentType());
_builder.append(_parameterList);
}
}
_builder.append(" returns ");
CharSequence _compileReturns = this.compileReturns(it, options);
_builder.append(_compileReturns);
_builder.newLineIfNotEmpty();
_builder.append("@init {");
_builder.newLine();
_builder.append("\t");
_builder.append("enterRule();");
_builder.newLine();
_builder.append("\t");
CharSequence _compileInitHiddenTokens = this.compileInitHiddenTokens(it, options);
_builder.append(_compileInitHiddenTokens, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
CharSequence _compileInitUnorderedGroups = this.compileInitUnorderedGroups(it, options);
_builder.append(_compileInitUnorderedGroups, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
_builder.append("@after {");
_builder.newLine();
_builder.append("\t");
_builder.append("leaveRule();");
_builder.newLine();
_builder.append("}");
return _builder.toString();
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileEntryRule.
protected String compileEntryRule(final ParserRule it, final Grammar grammar, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("// Entry rule ");
String _entryRuleName = this._grammarAccessExtensions.entryRuleName(it);
_builder.append(_entryRuleName);
_builder.newLineIfNotEmpty();
String _entryRuleName_1 = this._grammarAccessExtensions.entryRuleName(it);
_builder.append(_entryRuleName_1);
_builder.append(" returns ");
CharSequence _compileEntryReturns = this.compileEntryReturns(it, options);
_builder.append(_compileEntryReturns);
CharSequence _compileEntryInit = this.compileEntryInit(it, options);
_builder.append(_compileEntryInit);
_builder.append(":");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("{ ");
CharSequence _newCompositeNode = this.newCompositeNode(it);
_builder.append(_newCompositeNode, "\t");
_builder.append(" }");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("iv_");
String _ruleName = this._grammarAccessExtensions.ruleName(it);
_builder.append(_ruleName, "\t");
_builder.append("=");
String _ruleName_1 = this._grammarAccessExtensions.ruleName(it);
_builder.append(_ruleName_1, "\t");
String _defaultArgumentList = AntlrGrammarGenUtil.getDefaultArgumentList(it);
_builder.append(_defaultArgumentList, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("{ $current=$iv_");
String _ruleName_2 = this._grammarAccessExtensions.ruleName(it);
_builder.append(_ruleName_2, "\t");
_builder.append(".current");
{
boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(it);
if (_isDatatypeRule) {
_builder.append(".getText()");
}
}
_builder.append("; }");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("EOF;");
_builder.newLine();
CharSequence _compileEntryFinally = this.compileEntryFinally(it, options);
_builder.append(_compileEntryFinally);
_builder.newLineIfNotEmpty();
return _builder.toString();
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse 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();
{
boolean _isEObjectFragmentRuleCall = GrammarUtil.isEObjectFragmentRuleCall(it);
if (_isEObjectFragmentRuleCall) {
_builder.append("\t");
_builder.append("if ($current==null) {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("$current = ");
CharSequence _createModelElement = this.createModelElement(it);
_builder.append(_createModelElement, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_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();
_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;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse 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;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileEntryReturns.
protected CharSequence compileEntryReturns(final ParserRule it, final AntlrOptions options) {
CharSequence _xifexpression = null;
boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(it);
if (_isDatatypeRule) {
_xifexpression = "[String current=null]";
} else {
StringConcatenation _builder = new StringConcatenation();
_builder.append("[");
String _currentType = this.getCurrentType();
_builder.append(_currentType);
_builder.append(" current=null]");
_xifexpression = _builder;
}
return _xifexpression;
}
Aggregations