use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileReturns.
protected CharSequence compileReturns(final AbstractRule it, final AntlrOptions options) {
CharSequence _switchResult = null;
boolean _matched = false;
if (it instanceof EnumRule) {
_matched = true;
_switchResult = "returns [Enumerator current=null]";
}
if (!_matched) {
if (it instanceof ParserRule) {
boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule) it)));
if (_isDatatypeRule) {
_matched = true;
_switchResult = "[AntlrDatatypeRuleToken current=new AntlrDatatypeRuleToken()]";
}
}
}
if (!_matched) {
if (it instanceof ParserRule) {
boolean _isEObjectFragmentRule = GrammarUtil.isEObjectFragmentRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule) it)));
if (_isEObjectFragmentRule) {
_matched = true;
StringConcatenation _builder = new StringConcatenation();
_builder.append("[");
String _currentType = this.getCurrentType();
_builder.append(_currentType);
_builder.append(" current=in_current]");
_switchResult = _builder;
}
}
}
if (!_matched) {
if (it instanceof ParserRule) {
_matched = true;
StringConcatenation _builder = new StringConcatenation();
_builder.append("[");
String _currentType = this.getCurrentType();
_builder.append(_currentType);
_builder.append(" current=null]");
_switchResult = _builder;
}
}
if (!_matched) {
throw new IllegalStateException(("Unexpected rule: " + it));
}
return _switchResult;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method createModelElement.
protected CharSequence createModelElement(final EObject grammarElement) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("createModelElement(grammarAccess.");
String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(GrammarUtil.containingParserRule(grammarElement));
_builder.append(_grammarElementAccess);
_builder.append(")");
return _builder;
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileRuleCatch.
@Override
protected String compileRuleCatch(final Grammar it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
_builder.append("@rulecatch {");
_builder.newLine();
_builder.append(" ");
_builder.append("catch (RecognitionException re) {");
_builder.newLine();
_builder.append(" ");
_builder.append("recover(input,re);");
_builder.newLine();
_builder.append(" ");
_builder.append("appendSkippedTokens();");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder.toString();
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileParserImports.
@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
_builder.append("import org.eclipse.xtext.*;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.*;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.impl.*;");
_builder.newLine();
_builder.append("import org.eclipse.emf.ecore.util.EcoreUtil;");
_builder.newLine();
_builder.append("import org.eclipse.emf.ecore.EObject;");
_builder.newLine();
{
boolean _isEmpty = GrammarUtil.allEnumRules(it).isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
_builder.append("import org.eclipse.emf.common.util.Enumerator;");
_builder.newLine();
}
}
_builder.append("import org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
_builder.newLine();
_builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
_builder.newLine();
{
if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter(Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
return EcoreUtil2.eAllContentsAsList(it_1);
}))), UnorderedGroup.class))) && options.isBacktrack())) {
_builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
_builder.newLine();
}
}
_builder.append("import org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken;");
_builder.newLine();
_builder.append("import ");
String _gaFQName = this._grammarAccess.gaFQName(it);
_builder.append(_gaFQName);
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
return _builder.toString();
}
use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.
the class AntlrGrammarGenerator method compileOptions.
@Override
protected String compileOptions(final Grammar it, final AntlrOptions options) {
StringConcatenation _builder = new StringConcatenation();
_builder.newLine();
_builder.append("options {");
_builder.newLine();
_builder.append("\t");
_builder.append("superClass=AbstractInternalAntlrParser;");
_builder.newLine();
{
if (((options.isBacktrack() || options.isMemoize()) || (options.getK() >= 0))) {
{
boolean _isBacktrack = options.isBacktrack();
if (_isBacktrack) {
_builder.append("\t");
_builder.append("backtrack=true;");
_builder.newLine();
}
}
{
boolean _isMemoize = options.isMemoize();
if (_isMemoize) {
_builder.append("\t");
_builder.append("memoize=true;");
_builder.newLine();
}
}
{
int _k = options.getK();
boolean _greaterEqualsThan = (_k >= 0);
if (_greaterEqualsThan) {
_builder.append("\t");
_builder.append("memoize=");
int _k_1 = options.getK();
_builder.append(_k_1, "\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
}
}
_builder.append("}");
_builder.newLine();
return _builder.toString();
}
Aggregations