Java Code Examples for org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions#isBacktrack()

The following examples show how to use org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions#isBacktrack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@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();
}
 
Example 2
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@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();
}
 
Example 3
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String _ebnf2(final Action it, final AntlrOptions options, final boolean supportActions) {
  String _xifexpression = null;
  if (supportActions) {
    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");
    _builder.append("$current = forceCreateModelElement");
    {
      String _feature = it.getFeature();
      boolean _tripleNotEquals = (_feature != null);
      if (_tripleNotEquals) {
        _builder.append("And");
        String _firstUpper = StringExtensions.toFirstUpper(this._grammarAccessExtensions.setOrAdd(it));
        _builder.append(_firstUpper, "\t");
      }
    }
    _builder.append("(");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("grammarAccess.");
    String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<Action>getOriginalElement(it));
    _builder.append(_grammarElementAccess, "\t\t");
    _builder.append(",");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("$current);");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _xifexpression = _builder.toString();
  } else {
    _xifexpression = super._ebnf2(it, options, supportActions);
  }
  return _xifexpression;
}
 
Example 4
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String _assignmentEbnf(final CrossReference it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
  String _xifexpression = null;
  if (supportActions) {
    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");
    _builder.append("if ($current==null) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$current = ");
    CharSequence _createModelElement = this.createModelElement(assignment);
    _builder.append(_createModelElement, "\t\t");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    String __assignmentEbnf = super._assignmentEbnf(it, assignment, options, supportActions);
    _builder.append(__assignmentEbnf);
    _xifexpression = _builder.toString();
  } else {
    _xifexpression = super._assignmentEbnf(it, assignment, options, supportActions);
  }
  return _xifexpression;
}
 
Example 5
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected boolean isParserBackTracking(final Grammar it, final AntlrOptions options) {
  return options.isBacktrack();
}
 
Example 6
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public boolean definesUnorderedGroups(final ParserRule it, final AntlrOptions options) {
  return (options.isBacktrack() && (!EcoreUtil2.<UnorderedGroup>typeSelect(EcoreUtil2.eAllContentsAsList(it), UnorderedGroup.class).isEmpty()));
}