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

The following examples show how to use org.eclipse.xtext.xtext.generator.parser.antlr.AntlrGrammarGenUtil. 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: 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 #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: 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 #4
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 #5
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String _crossrefEbnf(final Keyword it, final CrossReference ref, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("(");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("{ before(grammarAccess.");
  String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<Keyword>getOriginalElement(it));
  _builder.append(_grammarElementAccess, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  String __crossrefEbnf = super._crossrefEbnf(it, ref, supportActions);
  _builder.append(__crossrefEbnf, "\t");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("{ after(grammarAccess.");
  String _grammarElementAccess_1 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<Keyword>getOriginalElement(it));
  _builder.append(_grammarElementAccess_1, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append(")");
  _builder.newLine();
  return _builder.toString();
}
 
Example #6
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 #7
Source File: AbstractAntlrGrammarWithActionsGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String _dataTypeEbnf2(final Group it, final boolean supportActions) {
  String _xifexpression = null;
  Condition _guardCondition = it.getGuardCondition();
  boolean _tripleEquals = (_guardCondition == null);
  if (_tripleEquals) {
    _xifexpression = super._dataTypeEbnf2(it, supportActions);
  } else {
    String _guardConditionToAntlr = AntlrGrammarGenUtil.guardConditionToAntlr(it);
    String _plus = (_guardConditionToAntlr + "(");
    String __dataTypeEbnf2 = super._dataTypeEbnf2(it, supportActions);
    String _plus_1 = (_plus + __dataTypeEbnf2);
    _xifexpression = (_plus_1 + ")");
  }
  return _xifexpression;
}
 
Example #8
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String _crossrefEbnf(final RuleCall it, final CrossReference ref, final boolean supportActions) {
  String _xblockexpression = null;
  {
    final AbstractRule rule = it.getRule();
    if ((rule instanceof ParserRule)) {
      ParserRule _originalElement = AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule)rule));
      boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(((AbstractRule) _originalElement));
      boolean _not = (!_isDatatypeRule);
      if (_not) {
        throw new IllegalStateException("crossrefEbnf is not supported for ParserRule that is not a datatype rule");
      }
    }
    _xblockexpression = this.crossrefEbnf(rule, it, ref, supportActions);
  }
  return _xblockexpression;
}
 
Example #9
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 #10
Source File: PredicatedElementTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void assertPredicate(final String expectation, final String grammar) {
  try {
    EObject _model = this.getModel(grammar);
    final Grammar parsed = ((Grammar) _model);
    final AbstractElement body = IterableExtensions.<AbstractRule>head(parsed.getRules()).getAlternatives();
    final AbstractElement predicate = AntlrGrammarGenUtil.getPredicatedElement(body);
    Assert.assertEquals(expectation, this.toXtext(predicate));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #11
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.14
 */
protected StringConcatenationClient initNameMappings(final List<AbstractElement> partition) {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      {
        for(final AbstractElement element : partition) {
          _builder.append("builder.put(grammarAccess.");
          String _grammarElementAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element));
          _builder.append(_grammarElementAccess);
          _builder.append(", \"");
          String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element)));
          _builder.append(_contentAssistRuleName);
          _builder.append("__");
          String _gaElementIdentifier = XtextAntlrGeneratorFragment2.this.grammarUtil.gaElementIdentifier(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element));
          _builder.append(_gaElementIdentifier);
          {
            if ((element instanceof Group)) {
              _builder.append("__0");
            }
          }
          _builder.append("\");");
          _builder.newLineIfNotEmpty();
        }
      }
    }
  };
  return _client;
}
 
Example #12
Source File: UnicodeKeywordHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates lexer rule for given keyword in order to handle JavaScript's unicode masks. E.g.:
 *
 * <pre>
 * If :
 * 	( 'i' | '\\' 'u' '0''0''6''9' )
 * 	( 'f' | '\\' 'u' '0''0''6''6' );
 * </pre>
 *
 * @param keyword
 *            the keyword as string, e.g. 'if'
 * @return the lexer body, e.g.
 *
 *         <pre>
 * ( 'i' | '\\' 'u' '0''0''6''9' ) ( 'f' | '\\' 'u' '0''0''6''6' )
 *         </pre>
 */
public static String toUnicodeKeyword(String keyword) {
	if (keyword.equals("async ")) {
		keyword = "async";
	}
	if (isIdentifier(keyword)) {
		StringBuilder result = new StringBuilder(keyword.length() * 30);
		for (char c : keyword.toCharArray()) {
			result.append("\n\t( '");
			result.append(c);
			result.append("' | '\\\\' 'u' ");
			String unicodeEscape = Strings.padStart(Integer.toHexString(c), 4, '0');
			for (char u : unicodeEscape.toCharArray()) {
				if ('0' <= u && u <= '9') {
					result.append("'");
					result.append(u);
					result.append("'");
				} else {
					result.append("( '");
					result.append(u);
					result.append("' | '");
					result.append(Character.toUpperCase(u));
					result.append("' )");
				}
			}
			result.append(" )");
		}
		return result.toString();
	}
	return "'" + AntlrGrammarGenUtil.toAntlrString(keyword) + "'";
}
 
Example #13
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String _assignmentEbnf(final Alternatives 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.<Alternatives>getOriginalElement(it));
  _builder.append(_grammarElementAccess, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("(");
  String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
  _builder.append(_contentAssistRuleName, "\t");
  _builder.append("__");
  String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<Alternatives>getOriginalElement(it));
  _builder.append(_gaElementIdentifier, "\t");
  _builder.append(")");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("{ after(grammarAccess.");
  String _grammarElementAccess_1 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<Alternatives>getOriginalElement(it));
  _builder.append(_grammarElementAccess_1, "\t");
  _builder.append("); }");
  _builder.newLineIfNotEmpty();
  _builder.append(")");
  _builder.newLine();
  return _builder.toString();
}
 
Example #14
Source File: FirstSetComputationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertFirstSet(String expectation, AbstractRule rule) {
	RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
	ruleCall.setRule(rule);
	List<AbstractElement> firstSet = AntlrGrammarGenUtil.getFirstSet(ruleCall);
	StringBuilder actual = new StringBuilder();
	GrammarElementTitleSwitch stringifier = new GrammarElementTitleSwitch();
	for(int i = 0; i < firstSet.size(); i++) {
		if (i != 0)
			actual.append(", ");
		actual.append(stringifier.apply(firstSet.get(i)));
	}
	assertEquals(expectation, actual.toString());
}
 
Example #15
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public CharSequence toStringLiteral(final AbstractElement it) {
  CharSequence _switchResult = null;
  boolean _matched = false;
  if (it instanceof RuleCall) {
    AbstractRule _rule = ((RuleCall)it).getRule();
    boolean _tripleNotEquals = (_rule != null);
    if (_tripleNotEquals) {
      _matched=true;
      _switchResult = AntlrGrammarGenUtil.getQualifiedNameAsString(((RuleCall)it));
    }
  }
  if (!_matched) {
    if (it instanceof Keyword) {
      _matched=true;
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("\"");
      String _stringInAntlrAction = AntlrGrammarGenUtil.toStringInAntlrAction(((Keyword)it).getValue());
      _builder.append(_stringInAntlrAction);
      _builder.append("\"");
      _switchResult = _builder;
    }
  }
  if (!_matched) {
    _switchResult = "null";
  }
  return _switchResult;
}
 
Example #16
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String _crossrefEbnf(final AbstractRule it, final RuleCall call, final CrossReference ref, final boolean supportActions) {
  boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it));
  if (_isDatatypeRule) {
    return this._grammarAccessExtensions.ruleName(it);
  }
  String _name = it.getName();
  String _plus = (_name + " is not a datatype rule");
  throw new IllegalArgumentException(_plus);
}
 
Example #17
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String _ebnf2(final Alternatives it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
  _builder.append(_contentAssistRuleName);
  _builder.append("__");
  String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<Alternatives>getOriginalElement(it));
  _builder.append(_gaElementIdentifier);
  return _builder.toString();
}
 
Example #18
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String _ebnf2(final Assignment it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
  _builder.append(_contentAssistRuleName);
  _builder.append("__");
  String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<Assignment>getOriginalElement(it));
  _builder.append(_gaElementIdentifier);
  return _builder.toString();
}
 
Example #19
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String _ebnf2(final Group it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
  _builder.append(_contentAssistRuleName);
  _builder.append("__");
  String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<Group>getOriginalElement(it));
  _builder.append(_gaElementIdentifier);
  _builder.append("__0");
  return _builder.toString();
}
 
Example #20
Source File: AntlrContentAssistGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected String _ebnf2(final UnorderedGroup it, final AntlrOptions options, final boolean supportActions) {
  StringConcatenation _builder = new StringConcatenation();
  String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
  _builder.append(_contentAssistRuleName);
  _builder.append("__");
  String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
  _builder.append(_gaElementIdentifier);
  return _builder.toString();
}
 
Example #21
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String _localVar(final RuleCall it) {
  String _name = AntlrGrammarGenUtil.<AbstractRule>getOriginalElement(it.getRule()).getName();
  String _plus = ("this_" + _name);
  String _plus_1 = (_plus + "_");
  int _indexOf = this.contentsAsList(GrammarUtil.containingParserRule(it)).indexOf(it);
  return (_plus_1 + Integer.valueOf(_indexOf));
}
 
Example #22
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 #23
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 #24
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String ebnfPredicate(final AbstractElement it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  {
    if ((this._grammarAccessExtensions.predicated(it) || it.isFirstSetPredicated())) {
      _builder.append("(");
      {
        boolean _predicated = this._grammarAccessExtensions.predicated(it);
        if (_predicated) {
          String _ebnf2 = this.ebnf2(this._grammarAccessExtensions.predicatedElement(it), options, false);
          _builder.append(_ebnf2);
        } else {
          {
            List<AbstractElement> _firstSet = AntlrGrammarGenUtil.getFirstSet(it);
            boolean _hasElements = false;
            for(final AbstractElement e : _firstSet) {
              if (!_hasElements) {
                _hasElements = true;
              } else {
                _builder.appendImmediate(" | ", "");
              }
              String _ebnf2_1 = this.ebnf2(e, options, false);
              _builder.append(_ebnf2_1);
            }
          }
        }
      }
      _builder.append(")=>");
    }
  }
  _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 dataTypeEbnfPredicate(final AbstractElement it) {
  StringConcatenation _builder = new StringConcatenation();
  {
    if ((this._grammarAccessExtensions.predicated(it) || it.isFirstSetPredicated())) {
      _builder.append("(");
      {
        boolean _predicated = this._grammarAccessExtensions.predicated(it);
        if (_predicated) {
          String _dataTypeEbnf2 = this.dataTypeEbnf2(this._grammarAccessExtensions.predicatedElement(it), false);
          _builder.append(_dataTypeEbnf2);
        } else {
          {
            List<AbstractElement> _firstSet = AntlrGrammarGenUtil.getFirstSet(it);
            boolean _hasElements = false;
            for(final AbstractElement e : _firstSet) {
              if (!_hasElements) {
                _hasElements = true;
              } else {
                _builder.appendImmediate(" | ", "");
              }
              String _dataTypeEbnf2_1 = this.dataTypeEbnf2(e, false);
              _builder.append(_dataTypeEbnf2_1);
            }
          }
        }
      }
      _builder.append(")=>");
    }
  }
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example #26
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String ebnf(final Keyword it) {
  String _xifexpression = null;
  boolean _isCombinedGrammar = this.isCombinedGrammar();
  if (_isCombinedGrammar) {
    String _antlrString = AntlrGrammarGenUtil.toAntlrString(it.getValue());
    String _plus = ("\'" + _antlrString);
    _xifexpression = (_plus + "\'");
  } else {
    _xifexpression = this.keywordHelper.getRuleName(it.getValue());
  }
  return _xifexpression;
}
 
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 EnumLiteralDeclaration it, final AntlrOptions options, final boolean supportActions) {
  String _xifexpression = null;
  boolean _isCombinedGrammar = this.isCombinedGrammar();
  if (_isCombinedGrammar) {
    String _antlrString = AntlrGrammarGenUtil.toAntlrString(it.getLiteral().getValue());
    String _plus = ("\'" + _antlrString);
    _xifexpression = (_plus + "\'");
  } else {
    _xifexpression = this.keywordHelper.getRuleName(it.getLiteral().getValue());
  }
  return _xifexpression;
}
 
Example #28
Source File: GrammarAccessExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public String ruleName(final AbstractRule rule) {
  final RuleNames ruleNames = RuleNames.tryGetRuleNames(rule);
  String _elvis = null;
  String _antlrRuleName = null;
  if (ruleNames!=null) {
    _antlrRuleName=ruleNames.getAntlrRuleName(rule);
  }
  if (_antlrRuleName != null) {
    _elvis = _antlrRuleName;
  } else {
    String _ruleName = AntlrGrammarGenUtil.getRuleName(rule);
    _elvis = _ruleName;
  }
  return _elvis;
}
 
Example #29
Source File: AbstractAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void cleanupParserTokensFile(final AntlrGrammar lexerGrammar, final AntlrGrammar parserGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) {
  try {
    final MutableTokenDefProvider provider = this.createLexerTokensProvider(lexerGrammar, helper, fsa);
    Set<Map.Entry<Integer, String>> _entrySet = provider.getTokenDefMap().entrySet();
    for (final Map.Entry<Integer, String> entry : _entrySet) {
      {
        final String value = entry.getValue();
        boolean _isKeywordRule = helper.isKeywordRule(value);
        if (_isKeywordRule) {
          final String keywordAsAntlrString = AntlrGrammarGenUtil.toAntlrString(helper.getKeywordValue(value));
          entry.setValue((("\'" + keywordAsAntlrString) + "\'"));
        } else {
          boolean _startsWith = value.startsWith("\'");
          if (_startsWith) {
            String _antlrString = AntlrGrammarGenUtil.toAntlrString(value);
            String _plus = ("\'" + _antlrString);
            String _plus_1 = (_plus + "\'");
            entry.setValue(_plus_1);
          }
        }
      }
    }
    final CharArrayWriter writer = new CharArrayWriter();
    PrintWriter _printWriter = new PrintWriter(writer);
    provider.writeTokenFile(_printWriter);
    String _tokensFileName = parserGrammar.getTokensFileName();
    char[] _charArray = writer.toCharArray();
    String _string = new String(_charArray);
    fsa.generateFile(_tokensFileName, _string);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #30
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CharSequence newCompositeNode(final EObject it) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("newCompositeNode(grammarAccess.");
  String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<EObject>getOriginalElement(it));
  _builder.append(_grammarElementAccess);
  _builder.append(");");
  return _builder;
}