org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions Java Examples

The following examples show how to use org.eclipse.xtext.xtext.generator.parser.antlr.AntlrOptions. 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: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _assignmentEbnf((Alternatives)it, assignment, options, supportActions);
  } else if (it instanceof Group) {
    return _assignmentEbnf((Group)it, assignment, options, supportActions);
  } else if (it instanceof Action) {
    return _assignmentEbnf((Action)it, assignment, options, supportActions);
  } else if (it instanceof Assignment) {
    return _assignmentEbnf((Assignment)it, assignment, options, supportActions);
  } else if (it instanceof CrossReference) {
    return _assignmentEbnf((CrossReference)it, assignment, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _assignmentEbnf((RuleCall)it, assignment, options, supportActions);
  } else if (it != null) {
    return _assignmentEbnf(it, assignment, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, assignment, options, supportActions).toString());
  }
}
 
Example #2
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String _assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportsActions) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("(");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("{ before(grammarAccess.");
  String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(it));
  _builder.append(_grammarElementAccess, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  String _ebnf = this.ebnf(it, options, supportsActions);
  _builder.append(_ebnf, "\t");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("{ after(grammarAccess.");
  String _grammarElementAccess_1 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(it));
  _builder.append(_grammarElementAccess_1, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append(")");
  _builder.newLine();
  return _builder.toString();
}
 
Example #3
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected CharSequence compileEntryInit(final ParserRule it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    if ((it.isDefinesHiddenTokens() || this._grammarAccessExtensions.definesUnorderedGroups(it, options))) {
      _builder.append("@init {");
      _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("}");
    }
  }
  return _builder;
}
 
Example #4
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected CharSequence _compileInitHiddenTokens(final ParserRule it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    boolean _isDefinesHiddenTokens = it.isDefinesHiddenTokens();
    if (_isDefinesHiddenTokens) {
      _builder.append("HiddenTokens myHiddenTokenState = ((XtextTokenStream)input).setHiddenTokens(");
      {
        EList<AbstractRule> _hiddenTokens = it.getHiddenTokens();
        boolean _hasElements = false;
        for(final AbstractRule hidden : _hiddenTokens) {
          if (!_hasElements) {
            _hasElements = true;
          } else {
            _builder.appendImmediate(", ", "");
          }
          _builder.append("\"");
          String _ruleName = this._grammarAccessExtensions.ruleName(hidden);
          _builder.append(_ruleName);
          _builder.append("\"");
        }
      }
      _builder.append(");");
    }
  }
  return _builder;
}
 
Example #5
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _ebnf2((Alternatives)it, options, supportActions);
  } else if (it instanceof Group) {
    return _ebnf2((Group)it, options, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _ebnf2((UnorderedGroup)it, options, supportActions);
  } else if (it instanceof Action) {
    return _ebnf2((Action)it, options, supportActions);
  } else if (it instanceof Assignment) {
    return _ebnf2((Assignment)it, options, supportActions);
  } else if (it instanceof EnumLiteralDeclaration) {
    return _ebnf2((EnumLiteralDeclaration)it, options, supportActions);
  } else if (it instanceof Keyword) {
    return _ebnf2((Keyword)it, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _ebnf2((RuleCall)it, options, supportActions);
  } else if (it != null) {
    return _ebnf2(it, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options, supportActions).toString());
  }
}
 
Example #6
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected CharSequence compileRule(final Object it, final Grammar grammar, final AntlrOptions options) {
  if (it instanceof Alternatives) {
    return _compileRule((Alternatives)it, grammar, options);
  } else if (it instanceof Group) {
    return _compileRule((Group)it, grammar, options);
  } else if (it instanceof UnorderedGroup) {
    return _compileRule((UnorderedGroup)it, grammar, options);
  } else if (it instanceof Assignment) {
    return _compileRule((Assignment)it, grammar, options);
  } else if (it instanceof EnumRule) {
    return _compileRule((EnumRule)it, grammar, options);
  } else if (it instanceof ParserRule) {
    return _compileRule((ParserRule)it, grammar, options);
  } else if (it instanceof TerminalRule) {
    return _compileRule((TerminalRule)it, grammar, options);
  } else if (it instanceof String) {
    return _compileRule((String)it, grammar, options);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, grammar, options).toString());
  }
}
 
Example #7
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportsActions) {
  if (it instanceof Alternatives) {
    return _assignmentEbnf((Alternatives)it, assignment, options, supportsActions);
  } else if (it instanceof Group) {
    return _assignmentEbnf((Group)it, assignment, options, supportsActions);
  } else if (it instanceof Action) {
    return _assignmentEbnf((Action)it, assignment, options, supportsActions);
  } else if (it instanceof Assignment) {
    return _assignmentEbnf((Assignment)it, assignment, options, supportsActions);
  } else if (it instanceof CrossReference) {
    return _assignmentEbnf((CrossReference)it, assignment, options, supportsActions);
  } else if (it instanceof RuleCall) {
    return _assignmentEbnf((RuleCall)it, assignment, options, supportsActions);
  } else if (it != null) {
    return _assignmentEbnf(it, assignment, options, supportsActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, assignment, options, supportsActions).toString());
  }
}
 
Example #8
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String _ebnf2(final Alternatives it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  {
    EList<AbstractElement> _elements = it.getElements();
    boolean _hasElements = false;
    for(final AbstractElement element : _elements) {
      if (!_hasElements) {
        _hasElements = true;
      } else {
        _builder.appendImmediate("\n    |", "");
      }
      String _ebnf = this.ebnf(element, options, supportActions);
      _builder.append(_ebnf);
    }
  }
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example #9
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _ebnf2((Alternatives)it, options, supportActions);
  } else if (it instanceof Group) {
    return _ebnf2((Group)it, options, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _ebnf2((UnorderedGroup)it, options, supportActions);
  } else if (it instanceof Action) {
    return _ebnf2((Action)it, options, supportActions);
  } else if (it instanceof Assignment) {
    return _ebnf2((Assignment)it, options, supportActions);
  } else if (it instanceof EnumLiteralDeclaration) {
    return _ebnf2((EnumLiteralDeclaration)it, options, supportActions);
  } else if (it instanceof Keyword) {
    return _ebnf2((Keyword)it, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _ebnf2((RuleCall)it, options, supportActions);
  } else if (it != null) {
    return _ebnf2(it, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options, supportActions).toString());
  }
}
 
Example #10
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected CharSequence compileEntryFinally(final ParserRule it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    if ((it.isDefinesHiddenTokens() || this._grammarAccessExtensions.definesUnorderedGroups(it, options))) {
      _builder.append("finally {");
      _builder.newLine();
      _builder.append("\t");
      CharSequence _compileRestoreHiddenTokens = this.compileRestoreHiddenTokens(it, options);
      _builder.append(_compileRestoreHiddenTokens, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _compileRestoreUnorderedGroups = this.compileRestoreUnorderedGroups(it, options);
      _builder.append(_compileRestoreUnorderedGroups, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("}");
    }
  }
  return _builder;
}
 
Example #11
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String assignmentEbnf(final AbstractElement it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _assignmentEbnf((Alternatives)it, assignment, options, supportActions);
  } else if (it instanceof Group) {
    return _assignmentEbnf((Group)it, assignment, options, supportActions);
  } else if (it instanceof Action) {
    return _assignmentEbnf((Action)it, assignment, options, supportActions);
  } else if (it instanceof Assignment) {
    return _assignmentEbnf((Assignment)it, assignment, options, supportActions);
  } else if (it instanceof CrossReference) {
    return _assignmentEbnf((CrossReference)it, assignment, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _assignmentEbnf((RuleCall)it, assignment, options, supportActions);
  } else if (it != null) {
    return _assignmentEbnf(it, assignment, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, assignment, options, supportActions).toString());
  }
}
 
Example #12
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String ebnf(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  {
    boolean _mustBeParenthesized = this.mustBeParenthesized(it);
    if (_mustBeParenthesized) {
      _builder.append("(");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      String _ebnfPredicate = this.ebnfPredicate(it, options);
      _builder.append(_ebnfPredicate, "\t");
      String _ebnf2 = this.ebnf2(it, options, supportActions);
      _builder.append(_ebnf2, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append(")");
    } else {
      String _ebnf2_1 = this.ebnf2(it, options, supportActions);
      _builder.append(_ebnf2_1);
    }
  }
  String _cardinality = it.getCardinality();
  _builder.append(_cardinality);
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example #13
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #14
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String _ebnf2(final Group it, final AntlrOptions options, final boolean supportActions) {
  String _xifexpression = null;
  Condition _guardCondition = it.getGuardCondition();
  boolean _tripleEquals = (_guardCondition == null);
  if (_tripleEquals) {
    _xifexpression = super._ebnf2(it, options, supportActions);
  } else {
    String _guardConditionToAntlr = AntlrGrammarGenUtil.guardConditionToAntlr(it);
    String _plus = (_guardConditionToAntlr + "(");
    String __ebnf2 = super._ebnf2(it, options, supportActions);
    String _plus_1 = (_plus + __ebnf2);
    _xifexpression = (_plus_1 + ")");
  }
  return _xifexpression;
}
 
Example #15
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected CharSequence compileLexerOptions(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    boolean _isBacktrackLexer = options.isBacktrackLexer();
    if (_isBacktrackLexer) {
      _builder.newLine();
      _builder.append("options {");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("backtrack=true;");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("memoize=true;");
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
    }
  }
  return _builder;
}
 
Example #16
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _ebnf2((Alternatives)it, options, supportActions);
  } else if (it instanceof Group) {
    return _ebnf2((Group)it, options, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _ebnf2((UnorderedGroup)it, options, supportActions);
  } else if (it instanceof Action) {
    return _ebnf2((Action)it, options, supportActions);
  } else if (it instanceof Assignment) {
    return _ebnf2((Assignment)it, options, supportActions);
  } else if (it instanceof EnumLiteralDeclaration) {
    return _ebnf2((EnumLiteralDeclaration)it, options, supportActions);
  } else if (it instanceof Keyword) {
    return _ebnf2((Keyword)it, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _ebnf2((RuleCall)it, options, supportActions);
  } else if (it != null) {
    return _ebnf2(it, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options, supportActions).toString());
  }
}
 
Example #17
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportActions) {
  String _switchResult = null;
  AbstractRule _rule = it.getRule();
  final AbstractRule rule = _rule;
  boolean _matched = false;
  if (rule instanceof EnumRule) {
    _matched=true;
  }
  if (!_matched) {
    if (rule instanceof ParserRule) {
      _matched=true;
    }
  }
  if (!_matched) {
    if (rule instanceof TerminalRule) {
      _matched=true;
    }
  }
  if (_matched) {
    _switchResult = this._grammarAccessExtensions.ruleName(rule);
  }
  if (!_matched) {
    throw new IllegalStateException(("assignmentEbnf is not supported for " + rule));
  }
  return _switchResult;
}
 
Example #18
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String _assignmentEbnf(final RuleCall it, final Assignment assignment, final AntlrOptions options, final boolean supportsActions) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("(");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("{ before(grammarAccess.");
  String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<RuleCall>getOriginalElement(it));
  _builder.append(_grammarElementAccess, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  String _ruleName = this._grammarAccessExtensions.ruleName(it.getRule());
  _builder.append(_ruleName, "\t");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("{ after(grammarAccess.");
  String _grammarElementAccess_1 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<RuleCall>getOriginalElement(it));
  _builder.append(_grammarElementAccess_1, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append(")");
  _builder.newLine();
  return _builder.toString();
}
 
Example #19
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected CharSequence compileParserHeader(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("header {");
  _builder.newLineIfNotEmpty();
  _builder.append("package ");
  String _packageName = this.getGrammarNaming().getParserGrammar(it).getPackageName();
  _builder.append(_packageName);
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  String _compileParserImports = this.compileParserImports(it, options);
  _builder.append(_compileParserImports);
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  _builder.newLine();
  return _builder;
}
 
Example #20
Source File: XtendAntlrGrammarGeneratorHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public String compileTokens(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.newLine();
  _builder.append("tokens {");
  _builder.newLine();
  {
    LinkedHashSet<String> _tokens = this.getTokens(it);
    for(final String token : _tokens) {
      _builder.append("\t");
      _builder.append("KW_");
      String _javaIdentifier = this._grammarAccessExtensions.toJavaIdentifier(token, true);
      _builder.append(_javaIdentifier, "\t");
      _builder.append(" = \'");
      String _antlrString = AntlrGrammarGenUtil.toAntlrString(token);
      _builder.append(_antlrString, "\t");
      _builder.append("\' ;");
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.append("}");
  _builder.newLine();
  return _builder.toString();
}
 
Example #21
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String _assignmentEbnf(final CrossReference it, final Assignment assignment, final AntlrOptions options, final boolean supportsActions) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("(");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("{ before(grammarAccess.");
  String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<CrossReference>getOriginalElement(it));
  _builder.append(_grammarElementAccess, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  String _crossrefEbnf = this.crossrefEbnf(it.getTerminal(), it, supportsActions);
  _builder.append(_crossrefEbnf, "\t");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("{ after(grammarAccess.");
  String _grammarElementAccess_1 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<CrossReference>getOriginalElement(it));
  _builder.append(_grammarElementAccess_1, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append(")");
  _builder.newLine();
  return _builder.toString();
}
 
Example #22
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence compileTokens(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    boolean _isBacktrackLexer = options.isBacktrackLexer();
    if (_isBacktrackLexer) {
      _builder.append("tokens {");
      _builder.newLine();
      {
        Set<String> _allKeywords = this.keywordHelper.getAllKeywords();
        for(final String kw : _allKeywords) {
          _builder.append("\t");
          String _ruleName = this.keywordHelper.getRuleName(kw);
          _builder.append(_ruleName, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      {
        List<TerminalRule> _allTerminalRules = GrammarUtil.allTerminalRules(it);
        for(final TerminalRule rule : _allTerminalRules) {
          _builder.append("\t");
          String _ruleName_1 = this._grammarAccessExtensions.ruleName(rule);
          _builder.append(_ruleName_1, "\t");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("}");
      _builder.newLine();
    }
  }
  return _builder;
}
 
Example #23
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence compileLexerImports(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.newLine();
  _builder.append("// Hack: Use our own Lexer superclass by means of import. ");
  _builder.newLine();
  _builder.append("// Currently there is no other way to specify the superclass for the lexer.");
  _builder.newLine();
  _builder.append("import ");
  TypeReference _lexerSuperClass = this.getGrammarNaming().getLexerSuperClass(it);
  _builder.append(_lexerSuperClass);
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  return _builder;
}
 
Example #24
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String compileEBNF(final AbstractRule it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("// Rule ");
  String _name = AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it).getName();
  _builder.append(_name);
  _builder.newLineIfNotEmpty();
  String _ruleName = this._grammarAccessExtensions.ruleName(it);
  _builder.append(_ruleName);
  String _compileInit = this.compileInit(it, options);
  _builder.append(_compileInit);
  _builder.append(":");
  _builder.newLineIfNotEmpty();
  {
    if (((it instanceof ParserRule) && GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it)))) {
      _builder.append("\t");
      String _dataTypeEbnf = this.dataTypeEbnf(it.getAlternatives(), true);
      _builder.append(_dataTypeEbnf, "\t");
      _builder.newLineIfNotEmpty();
    } else {
      _builder.append("\t");
      String _ebnf = this.ebnf(it.getAlternatives(), options, true);
      _builder.append(_ebnf, "\t");
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.append(";");
  _builder.newLine();
  String _compileFinally = this.compileFinally(it, options);
  _builder.append(_compileFinally);
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example #25
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String toAntlrKeywordRule(final String keyword, final AntlrOptions options) {
  boolean _isIgnoreCase = options.isIgnoreCase();
  if (_isIgnoreCase) {
    return AntlrGrammarGenUtil.toAntlrStringIgnoreCase(keyword);
  } else {
    String _antlrString = AntlrGrammarGenUtil.toAntlrString(keyword);
    String _plus = ("\'" + _antlrString);
    return (_plus + "\'");
  }
}
 
Example #26
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence compileInitUnorderedGroups(final AbstractRule it, final AntlrOptions options) {
  if (it instanceof ParserRule) {
    return _compileInitUnorderedGroups((ParserRule)it, options);
  } else if (it != null) {
    return _compileInitUnorderedGroups(it, options);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options).toString());
  }
}
 
Example #27
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String _ebnf2(final Group it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  {
    EList<AbstractElement> _elements = it.getElements();
    for(final AbstractElement element : _elements) {
      String _ebnf = this.ebnf(element, options, supportActions);
      _builder.append(_ebnf);
    }
  }
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example #28
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected CharSequence compileRules(final Grammar g, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    List<ParserRule> _allParserRules = GrammarUtil.allParserRules(g);
    List<EnumRule> _allEnumRules = GrammarUtil.allEnumRules(g);
    Iterable<AbstractRule> _plus = Iterables.<AbstractRule>concat(_allParserRules, _allEnumRules);
    Collection<? extends AbstractElement> _allAlternatives = GrammarUtil.getAllAlternatives(g);
    Iterable<EObject> _plus_1 = Iterables.<EObject>concat(_plus, _allAlternatives);
    Collection<? extends AbstractElement> _allGroups = GrammarUtil.getAllGroups(g);
    Iterable<EObject> _plus_2 = Iterables.<EObject>concat(_plus_1, _allGroups);
    Collection<? extends AbstractElement> _allUnorderedGroups = GrammarUtil.getAllUnorderedGroups(g);
    Iterable<EObject> _plus_3 = Iterables.<EObject>concat(_plus_2, _allUnorderedGroups);
    Collection<? extends AbstractElement> _allAssignments = GrammarUtil.getAllAssignments(g);
    final Function1<EObject, Boolean> _function = (EObject it) -> {
      return Boolean.valueOf(this._grammarAccessExtensions.isCalled(GrammarUtil.containingRule(it), g));
    };
    Iterable<EObject> _filter = IterableExtensions.<EObject>filter(Iterables.<EObject>concat(_plus_3, _allAssignments), _function);
    for(final EObject rule : _filter) {
      _builder.newLine();
      CharSequence _compileRule = this.compileRule(rule, g, options);
      _builder.append(_compileRule);
      _builder.newLineIfNotEmpty();
    }
  }
  {
    boolean _isCombinedGrammar = this.isCombinedGrammar();
    if (_isCombinedGrammar) {
      CharSequence _compileTerminalRules = this.compileTerminalRules(g, options);
      _builder.append(_compileTerminalRules);
      _builder.newLineIfNotEmpty();
    }
  }
  return _builder;
}
 
Example #29
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence compileRestoreHiddenTokens(final AbstractRule it, final AntlrOptions options) {
  if (it instanceof ParserRule) {
    return _compileRestoreHiddenTokens((ParserRule)it, options);
  } else if (it != null) {
    return _compileRestoreHiddenTokens(it, options);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options).toString());
  }
}
 
Example #30
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence compileRule(final Object it, final Grammar grammar, final AntlrOptions options) {
  if (it instanceof EnumRule) {
    return _compileRule((EnumRule)it, grammar, options);
  } else if (it instanceof ParserRule) {
    return _compileRule((ParserRule)it, grammar, options);
  } else if (it instanceof TerminalRule) {
    return _compileRule((TerminalRule)it, grammar, options);
  } else if (it instanceof String) {
    return _compileRule((String)it, grammar, options);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, grammar, options).toString());
  }
}