gt:       StringConcatenation _builder = new StringConcatenation();
context: /**
   * Copyright (c) 2015, 2016 itemis AG (http://www.itemis.eu) and others.
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Eclipse Public License v1.0
   * which accompanies this distribution, and is available at
   * http://www.eclipse.org/legal/epl-v10.html
   */
  package org.eclipse.xtext.xtext.generator.parser.antlr;
  
  import com.google.common.collect.Iterables;
  import com.google.inject.Inject;
  import com.google.inject.Singleton;
  import java.util.Arrays;
  import java.util.List;
  import org.eclipse.emf.ecore.EObject;
  import org.eclipse.xtend2.lib.StringConcatenation;
  import org.eclipse.xtext.AbstractElement;
  import org.eclipse.xtext.AbstractRule;
  import org.eclipse.xtext.Action;
  import org.eclipse.xtext.Assignment;
  import org.eclipse.xtext.CrossReference;
  import org.eclipse.xtext.EcoreUtil2;
  import org.eclipse.xtext.EnumLiteralDeclaration;
  import org.eclipse.xtext.EnumRule;
  import org.eclipse.xtext.Grammar;
  import org.eclipse.xtext.GrammarUtil;
  import org.eclipse.xtext.Keyword;
  import org.eclipse.xtext.ParserRule;
  import org.eclipse.xtext.RuleCall;
  import org.eclipse.xtext.TerminalRule;
  import org.eclipse.xtext.UnorderedGroup;
  import org.eclipse.xtext.xbase.lib.Extension;
  import org.eclipse.xtext.xbase.lib.Functions.Function1;
  import org.eclipse.xtext.xbase.lib.IterableExtensions;
  import org.eclipse.xtext.xbase.lib.ListExtensions;
  import org.eclipse.xtext.xbase.lib.StringExtensions;
  import org.eclipse.xtext.xtext.generator.parser.antlr.AbstractAntlrGrammarWithActionsGenerator;
  import org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil;
  import org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions;
  import org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming;
  
  @Singleton
  @SuppressWarnings("all")
  public class AntlrGrammarGenerator extends AbstractAntlrGrammarWithActionsGenerator {
    @Inject
    @Extension
    private GrammarNaming naming;
    
    @Override
    protected GrammarNaming getGrammarNaming() {
      return this.naming;
    }
    
    @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 ");
      String _name = this.getGrammarNaming().getInternalParserSuperClass(it).getName();
      _builder.append(_name);
      _builder.append(";");
      _builder.newLineIfNotEmpty();
      _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 _name_1 = this._grammarAccessExtensions.getGrammarAccess(it).getName();
      _builder.append(_name_1);
      _builder.append(";");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      return _builder.toString();
    }
    
    @Override
    protected String compileParserMembers(final Grammar it, final AntlrOptions options) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.newLine();
      _builder.append("@");
      {
        boolean _isCombinedGrammar = this.isCombinedGrammar();
        if (_isCombinedGrammar) {
          _builder.append("parser::");
        }
      }
      _builder.append("members {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      {
        boolean _isBacktrack = options.isBacktrack();
        if (_isBacktrack) {
          _builder.append("/*");
          _builder.newLine();
          _builder.append("  ");
          _builder.append("This grammar contains a lot of empty actions to work around a bug in ANTLR.");
          _builder.newLine();
          _builder.append("  ");
          _builder.append("Otherwise the ANTLR tool will create synpreds that cannot be compiled in some rare cases.");
          _builder.newLine();
          _builder.append("*/");
          _builder.newLine();
          _builder.newLine();
        }
      }
      _builder.append(" \t");
      _builder.append("private ");
      String _simpleName = this._grammarAccessExtensions.getGrammarAccess(it).getSimpleName();
      _builder.append(_simpleName, " \t");
      _builder.append(" grammarAccess;");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("    ");
      _builder.append("public ");
      String _simpleName_1 = this.naming.getInternalParserClass(it).getSimpleName();
      _builder.append(_simpleName_1, "    ");
      _builder.append("(TokenStream input, ");
      String _simpleName_2 = this._grammarAccessExtensions.getGrammarAccess(it).getSimpleName();
      _builder.append(_simpleName_2, "    ");
      _builder.append(" grammarAccess) {");
      _builder.newLineIfNotEmpty();
      _builder.append("        ");
      _builder.append("this(input);");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("this.grammarAccess = grammarAccess;");
      _builder.newLine();
      _builder.append("        ");
      _builder.append("registerRules(grammarAccess.getGrammar());");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("    ");
      _builder.append("@Override");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("protected String getFirstRuleName() {");
      _builder.newLine();
      _builder.append("    \t");
      _builder.append("return \"");
      String _name = AntlrGrammarGenUtil.<ParserRule>getOriginalElement(IterableExtensions.<ParserRule>head(GrammarUtil.allParserRules(it))).getName();
      _builder.append(_name, "    \t");
      _builder.append("\";");
      _builder.newLineIfNotEmpty();
      _builder.append("   \t");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("   \t");
      _builder.append("@Override");
      _builder.newLine();
      _builder.append("   \t");
      _builder.append("protected ");
      String _simpleName_3 = this._grammarAccessExtensions.getGrammarAccess(it).getSimpleName();
      _builder.append(_simpleName_3, "   \t");
      _builder.append(" getGrammarAccess() {");
      _builder.newLineIfNotEmpty();
      _builder.append("   \t\t");
      _builder.append("return grammarAccess;");
      _builder.newLine();
      _builder.append("   \t");
      _builder.append("}");
      _builder.newLine();
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      return _builder.toString();
    }
    
    @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();
    }
    
    @Override
    protected boolean shouldBeSkipped(final TerminalRule it, final Grammar grammar) {
      return false;
    }
    
    @Override
    protected CharSequence _compileRule(final ParserRule it, final Grammar grammar, final AntlrOptions options) {
      StringConcatenation _builder = new StringConcatenation();
      {
        boolean _isValidEntryRule = AntlrGrammarGenUtil.isValidEntryRule(it);
        if (_isValidEntryRule) {
          String _compileEntryRule = this.compileEntryRule(it, grammar, options);
          _builder.append(_compileEntryRule);
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      String _compileEBNF = this.compileEBNF(it, options);
      _builder.append(_compileEBNF);
      _builder.newLineIfNotEmpty();
      return _builder;
    }
    
    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(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(it));
      _builder.append(_entryRuleName);
      _builder.newLineIfNotEmpty();
      String _entryRuleName_1 = this._grammarAccessExtensions.entryRuleName(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(it));
      _builder.append(_entryRuleName_1);
      _builder.append(" returns ");
      String _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(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(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(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(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();
    }
    
    protected String compileEntryReturns(final ParserRule it, final AntlrOptions options) {
      boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(it));
      if (_isDatatypeRule) {
        return "[String current=null]";
      } else {
  