本文整理汇总了Java中org.eclipse.xtext.Grammar类的典型用法代码示例。如果您正苦于以下问题:Java Grammar类的具体用法?Java Grammar怎么用?Java Grammar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Grammar类属于org.eclipse.xtext包,在下文中一共展示了Grammar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAmbiguousSyntax
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
/**
* Specialized to yield an {@link AbstractElementAlias} that has sorted alternatives where the occurrence in the
* grammar defines the order of the output.
*/
@Override
public AbstractElementAlias getAmbiguousSyntax() {
if (ambiguousSyntax != null)
return ambiguousSyntax;
Nfa<ISynState> nfa = getAmbiguousNfa();
NfaToProduction prod = new NfaToProduction();
// TODO remove with Xtext 2.13 if the patch makes it into the framework
// FIX is here: We want to use a stable order
Grammar grammar = getGrammar(nfa);
GrammarElementDeclarationOrder order = GrammarElementDeclarationOrder.get(grammar);
ambiguousSyntax = prod.nfaToGrammar(nfa, new GetGrammarElement(), order, new GrammarAliasFactory());
// end fix
return ambiguousSyntax;
}
示例2: getGrammar
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
/**
* Extracts the grammar from this transition or the NFA if this transition does not point to an
* {@link AbstractElement}.
*/
private Grammar getGrammar(Nfa<ISynState> nfa) {
AbstractElement grammarElement = getGrammarElement();
if (grammarElement == null) {
grammarElement = nfa.getStart().getGrammarElement();
if (grammarElement == null) {
grammarElement = nfa.getStop().getGrammarElement();
if (grammarElement == null) {
Iterator<ISynState> iter = nfa.getStart().getFollowers().iterator();
while (grammarElement == null && iter.hasNext()) {
grammarElement = iter.next().getGrammarElement();
}
}
}
}
Grammar grammar = GrammarUtil.getGrammar(grammarElement);
return grammar;
}
示例3: collectAbstractElements
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@Override
public void collectAbstractElements(Grammar grammar, EStructuralFeature feature,
IFollowElementAcceptor followElementAcceptor) {
for (Grammar superGrammar : grammar.getUsedGrammars()) {
collectAbstractElements(superGrammar, feature, followElementAcceptor);
}
EClass declarator = feature.getEContainingClass();
for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
for (Assignment assignment : GrammarUtil.containedAssignments(rule)) {
if (assignment.getFeature().equals(feature.getName())) {
EClassifier classifier = GrammarUtil.findCurrentType(assignment);
EClassifier compType = EcoreUtil2.getCompatibleType(declarator, classifier);
if (compType == declarator) {
followElementAcceptor.accept(assignment);
}
}
}
}
}
示例4: registerRules
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void registerRules(Grammar grammar) {
if (ALL_RULES_FIELD != null) {
try {
Map<String, AbstractRule> localAllRules = (Map<String, AbstractRule>) ALL_RULES_FIELD.get(this);
if (allRules == null) {
super.registerRules(grammar);
allRules = localAllRules;
} else {
localAllRules.putAll(allRules);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
super.registerRules(grammar);
}
}
示例5: internalFindGrammar
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
protected Grammar internalFindGrammar(GrammarProvider grammarProvider) {
Grammar grammar = grammarProvider.getGrammar(this);
while (grammar != null) {
if ("org.eclipse.cmf.occi.core.xtext.OCCI".equals(grammar.getName())) {
return grammar;
}
List<Grammar> grammars = grammar.getUsedGrammars();
if (!grammars.isEmpty()) {
grammar = grammars.iterator().next();
} else {
return null;
}
}
return grammar;
}
示例6: testFindCurrentType_02
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@Test
public void testFindCurrentType_02() throws Exception {
this.with(XtextStandaloneSetup.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar myLang with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate g \'http://1\'");
_builder.newLine();
_builder.append("Rule:");
_builder.newLine();
_builder.append("\t");
_builder.append("Fragment;");
_builder.newLine();
_builder.append("fragment Fragment: name=ID {SubRule.named=current};");
_builder.newLine();
String model = _builder.toString();
final XtextResource r = this.getResourceFromString(model);
EObject _get = r.getContents().get(0);
final Grammar grammar = ((Grammar) _get);
final AbstractRule rule = IterableExtensions.<AbstractRule>head(grammar.getRules());
final AbstractElement fragmentCall = rule.getAlternatives();
final EClassifier currentType = GrammarUtil.findCurrentType(fragmentCall);
Assert.assertEquals("SubRule", currentType.getName());
}
示例7: getFragmentSegment
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@Override
public CharSequence getFragmentSegment(final EObject object) {
EClass eClass = object.eClass();
EPackage ePackage = eClass.getEPackage();
if (ePackage == XtextPackage.eINSTANCE) {
int classifierID = eClass.getClassifierID();
switch (classifierID) {
case XtextPackage.GRAMMAR:
return getFragmentSegment((Grammar) object);
case XtextPackage.ENUM_RULE:
case XtextPackage.PARSER_RULE:
case XtextPackage.TERMINAL_RULE:
return getFragmentSegment((AbstractRule) object);
case XtextPackage.KEYWORD:
if (((Keyword) object).getValue().equals("selectCardinality")) {
return getFragmentSegment((AbstractElement) object);
} else {
return getFragmentSegment((Keyword) object);
}
default:
return super.getFragmentSegment(object);
}
}
return super.getFragmentSegment(object);
}
示例8: testRuleCall_01
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@Test
public void testRuleCall_01() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar org.foo with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate metamodel \'foo.sample\'");
_builder.newLine();
_builder.append("First returns Object: (Third|Second) cardinality=(\'+\'|\'*\')?;");
_builder.newLine();
_builder.append("Second returns Object: \'(\' First \')\';");
_builder.newLine();
_builder.append("Third returns Object: name=ID;");
_builder.newLine();
String grammarAsString = _builder.toString();
final Grammar grammar = this.getGrammar(grammarAsString);
AbstractRule _findRuleForName = GrammarUtil.findRuleForName(grammar, "First");
final ParserRule rule = ((ParserRule) _findRuleForName);
this.validateRule(rule);
Assert.assertEquals(this.warnings.toString(), 2, this.warnings.size());
}
示例9: getGenModelPath
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@Override
protected String getGenModelPath(final Grammar grammar) {
String _xifexpression = null;
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(this.genModel);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_xifexpression = this.genModel;
} else {
String _javaModelDirectory = this.getJavaModelDirectory();
String _plus = (_javaModelDirectory + "/");
String _replace = grammar.getName().substring(0, grammar.getName().lastIndexOf(".")).replace(".", "/");
String _plus_1 = (_plus + _replace);
String _plus_2 = (_plus_1 + "/");
String _modelName = this.getModelName(grammar);
String _plus_3 = (_plus_2 + _modelName);
_xifexpression = (_plus_3 + ".genmodel");
}
return _xifexpression;
}
示例10: testQualifiedRuleCall_02
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@Test
public void testQualifiedRuleCall_02() throws Exception {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar test with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.append("generate test \'http://test\'");
_builder.newLine();
_builder.append("Rule: name=ID;");
_builder.newLine();
_builder.append("terminal STRING: super;");
_builder.newLine();
final String grammarAsString = _builder.toString();
final XtextResource resource = this.getResourceFromString(grammarAsString);
EObject _get = resource.getContents().get(0);
Grammar grammar = ((Grammar) _get);
AbstractRule _get_1 = grammar.getRules().get(1);
final TerminalRule string = ((TerminalRule) _get_1);
AbstractElement _alternatives = string.getAlternatives();
final RuleCall callToSuper = ((RuleCall) _alternatives);
Assert.assertEquals(GrammarUtil.findRuleForName(IterableExtensions.<Grammar>head(grammar.getUsedGrammars()), "STRING"), callToSuper.getRule());
}
示例11: assertNoLeakedGrammarElements
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
private void assertNoLeakedGrammarElements(final Grammar grammar, final Pda<ISerState, RuleCall> pda) {
final Function1<ISerState, AbstractElement> _function = (ISerState it) -> {
return it.getGrammarElement();
};
Iterable<AbstractElement> _filterNull = IterableExtensions.<AbstractElement>filterNull(IterableExtensions.<ISerState, AbstractElement>map(new NfaUtil().<ISerState>collect(pda), _function));
for (final AbstractElement ele : _filterNull) {
{
final Grammar actual = GrammarUtil.getGrammar(ele);
if ((actual != grammar)) {
String _objPath = EmfFormatter.objPath(ele);
String _plus = ("Element " + _objPath);
String _plus_1 = (_plus + " leaked!");
Assert.fail(_plus_1);
}
}
}
}
示例12: findFirstWithSameConflicts
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
public static AbstractElement findFirstWithSameConflicts(final AbstractElement element, final Grammar grammar) {
final List<String> conflicting = getConflictingKeywords(element, grammar);
AbstractElement result = element;
Iterator<AbstractElement> iterator = Iterators.filter(
Iterators.filter(EcoreUtil.getAllContents(grammar, true), AbstractElement.class),
new Predicate<AbstractElement>() {
@Override
public boolean apply(AbstractElement param) {
final List<String> otherConflicting = getConflictingKeywords(param, grammar);
return otherConflicting != null && otherConflicting.equals(conflicting);
}
});
if (iterator.hasNext())
result = iterator.next();
return result;
}
示例13: getSaveAndReconcileGenModel
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
protected GenModel getSaveAndReconcileGenModel(final Grammar grammar, final List<EPackage> packs, final ResourceSet rs) {
final GenModel genModel = this.getGenModel(rs, grammar);
genModel.initialize(packs);
EList<GenPackage> _genPackages = genModel.getGenPackages();
for (final GenPackage genPackage : _genPackages) {
{
genPackage.setBasePackage(this.getBasePackage(grammar));
if (this.suppressLoadInitialization) {
genPackage.setLoadInitialization(false);
}
if (((!this.getLanguage().getFileExtensions().isEmpty()) && packs.contains(genPackage.getEcorePackage()))) {
genPackage.setFileExtensions(IterableExtensions.join(this.getLanguage().getFileExtensions(), ","));
}
}
}
final Set<EPackage> referencedEPackages = this.getReferencedEPackages(packs);
final List<GenPackage> usedGenPackages = this.getGenPackagesForPackages(genModel, referencedEPackages);
this.reconcileMissingGenPackagesInUsedModels(usedGenPackages);
genModel.getUsedGenPackages().addAll(usedGenPackages);
this.saveResource(genModel.eResource());
new GenModelHelper().registerGenModel(genModel);
return genModel;
}
示例14: setUp
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
with(XtextStandaloneSetup.class);
modelAsString = "\n" +
"grammar org.eclipse.xtext.parsetree.impl.LineTestLanguage with org.eclipse.xtext.common.Terminals\n" +
"\n" +
"generate testLanguage \"http://www.eclipse.org/2009/tmf/xtext/ParsetreeUtilTest\"\n" +
" \n" +
"Model:\n" +
" name=ID\n" +
";\n" +
"\n" +
"\n";
grammar = (Grammar) getModel(modelAsString);
grammarNode = NodeModelUtils.getNode(grammar);
metamodelNode = NodeModelUtils.getNode(grammar.getMetamodelDeclarations().get(0));
parentMetamodelNode = metamodelNode.getParent();
}
示例15: generatePluginXmlRt
import org.eclipse.xtext.Grammar; //导入依赖的package包/类
private void generatePluginXmlRt(List<LanguageConfig> configs, XpandExecutionContext ctx) {
String filePath = fileExists(ctx, "plugin.xml", PLUGIN_RT) ? "plugin.xml_gen" : "plugin.xml";
deleteFile(ctx, filePath, PLUGIN_RT);
ctx.getOutput().openFile(filePath, PLUGIN_RT);
ctx.getOutput().getOutlet(PLUGIN_RT).addVetoStrategy(new EmptyPluginXmlVeto());
try {
XpandFacade facade = XpandFacade.create(ctx);
List<Grammar> grammars = getGrammars(configs);
facade.evaluate("org::eclipse::xtext::generator::Plugin::pre", grammars);
for (LanguageConfig conf : languageConfigs) {
conf.addToPluginXmlRt(conf, ctx);
if (isUiMergedIntoRt()) {
conf.addToPluginXmlUi(conf, ctx);
}
}
facade.evaluate("org::eclipse::xtext::generator::Plugin::post", grammars);
} finally {
ctx.getOutput().closeFile();
}
}