当前位置: 首页>>代码示例>>Java>>正文


Java GrammarUtil类代码示例

本文整理汇总了Java中org.eclipse.xtext.GrammarUtil的典型用法代码示例。如果您正苦于以下问题:Java GrammarUtil类的具体用法?Java GrammarUtil怎么用?Java GrammarUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GrammarUtil类属于org.eclipse.xtext包,在下文中一共展示了GrammarUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGrammar

import org.eclipse.xtext.GrammarUtil; //导入依赖的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;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:22,代码来源:StableOrderSyntacticSequencerPDAProvider.java

示例2: UnicodeGrammarAccess

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
@Inject
public UnicodeGrammarAccess(GrammarProvider grammarProvider) {
	this.grammar = internalFindGrammar(grammarProvider);
	this.tHEX_DIGIT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.HEX_DIGIT");
	this.tDECIMAL_INTEGER_LITERAL_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.DECIMAL_INTEGER_LITERAL_FRAGMENT");
	this.tDECIMAL_DIGIT_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.DECIMAL_DIGIT_FRAGMENT");
	this.tZWJ = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.ZWJ");
	this.tZWNJ = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.ZWNJ");
	this.tBOM = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.BOM");
	this.tWHITESPACE_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.WHITESPACE_FRAGMENT");
	this.tLINE_TERMINATOR_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.LINE_TERMINATOR_FRAGMENT");
	this.tLINE_TERMINATOR_SEQUENCE_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.LINE_TERMINATOR_SEQUENCE_FRAGMENT");
	this.tSL_COMMENT_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.SL_COMMENT_FRAGMENT");
	this.tML_COMMENT_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.ML_COMMENT_FRAGMENT");
	this.tUNICODE_COMBINING_MARK_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.UNICODE_COMBINING_MARK_FRAGMENT");
	this.tUNICODE_DIGIT_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.UNICODE_DIGIT_FRAGMENT");
	this.tUNICODE_CONNECTOR_PUNCTUATION_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.UNICODE_CONNECTOR_PUNCTUATION_FRAGMENT");
	this.tUNICODE_LETTER_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.UNICODE_LETTER_FRAGMENT");
	this.tUNICODE_SPACE_SEPARATOR_FRAGMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.UNICODE_SPACE_SEPARATOR_FRAGMENT");
	this.tANY_OTHER = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.eclipse.n4js.common.unicode.Unicode.ANY_OTHER");
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:22,代码来源:UnicodeGrammarAccess.java

示例3: collectAbstractElements

import org.eclipse.xtext.GrammarUtil; //导入依赖的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);
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:PatchedFollowElementComputer.java

示例4: rewriteTypeReferences

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
private static void rewriteTypeReferences(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					EClassifier classifier = calledRule.getType().getClassifier();
					if (classifier instanceof EClass
							&& TypeRefsPackage.Literals.TYPE_REF.isSuperTypeOf((EClass) classifier)) {
						builder.put(assignment, TYPE_REF_TOKEN);
					}
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:TokenTypeRewriter.java

示例5: rewriteIdentifiers

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
private static void rewriteIdentifiers(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	ImmutableSet<AbstractRule> identifierRules = ImmutableSet.of(
			ga.getBindingIdentifierRule(),
			ga.getIdentifierNameRule(),
			ga.getIDENTIFIERRule());
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				int type = InternalN4JSParser.RULE_IDENTIFIER;
				if (terminal instanceof CrossReference) {
					terminal = ((CrossReference) terminal).getTerminal();
					type = IDENTIFIER_REF_TOKEN;
				}
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					if (identifierRules.contains(calledRule)) {
						builder.put(assignment, type);
					}
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:27,代码来源:TokenTypeRewriter.java

示例6: rewriteNumberLiterals

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
private static void rewriteNumberLiterals(N4JSGrammarAccess ga,
		ImmutableMap.Builder<AbstractElement, Integer> builder) {
	for (ParserRule rule : GrammarUtil.allParserRules(ga.getGrammar())) {
		for (EObject obj : EcoreUtil2.eAllContents(rule.getAlternatives())) {
			if (obj instanceof Assignment) {
				Assignment assignment = (Assignment) obj;
				AbstractElement terminal = assignment.getTerminal();
				if (terminal instanceof RuleCall) {
					AbstractRule calledRule = ((RuleCall) terminal).getRule();
					EClassifier classifier = calledRule.getType().getClassifier();
					if (classifier == EcorePackage.Literals.EBIG_DECIMAL) {
						builder.put(assignment, NUMBER_LITERAL_TOKEN);
					}
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:19,代码来源:TokenTypeRewriter.java

示例7: DSLPoliciesGrammarAccess

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
@Inject
public DSLPoliciesGrammarAccess(GrammarProvider grammarProvider,
		XbaseGrammarAccess gaXbase,
		XtypeGrammarAccess gaXtype) {
	this.grammar = internalFindGrammar(grammarProvider);
	this.gaXbase = gaXbase;
	this.gaXtype = gaXtype;
	this.pModel = new ModelElements();
	this.tSEV = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "gw4e.eclipse.dsl.DSLPolicies.SEV");
	this.tFORMAT_COMMENT = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "gw4e.eclipse.dsl.DSLPolicies.FORMAT_COMMENT");
	this.tNEWLINE = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "gw4e.eclipse.dsl.DSLPolicies.NEWLINE");
	this.pComment = new CommentElements();
	this.pGraphPolicies = new GraphPoliciesElements();
	this.pModelName = new ModelNameElements();
	this.pSeverity = new SeverityElements();
	this.pPolicies = new PoliciesElements();
	this.pPathGeneratorStopCondition = new PathGeneratorStopConditionElements();
	this.pAlgorithmType = new AlgorithmTypeElements();
	this.pIntegerStopCondition = new IntegerStopConditionElements();
	this.pPercentageCondition = new PercentageConditionElements();
	this.pStringCondition = new StringConditionElements();
	this.pPercent = new PercentElements();
	this.pGraphElement = new GraphElementElements();
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:25,代码来源:DSLPoliciesGrammarAccess.java

示例8: RestauranteGrammarAccess

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
@Inject
public RestauranteGrammarAccess(GrammarProvider grammarProvider,
		TerminalsGrammarAccess gaTerminals) {
	this.grammar = internalFindGrammar(grammarProvider);
	this.gaTerminals = gaTerminals;
	this.pRestaurante = new RestauranteElements();
	this.pIngrediente = new IngredienteElements();
	this.pProducto = new ProductoElements();
	this.pPrincipal = new PrincipalElements();
	this.pComplemento = new ComplementoElements();
	this.pBebida = new BebidaElements();
	this.pBebidaFria = new BebidaFriaElements();
	this.pBebidaCaliente = new BebidaCalienteElements();
	this.pPostre = new PostreElements();
	this.pNutricional = new NutricionalElements();
	this.pMenu = new MenuElements();
	this.pProductoY = new ProductoYElements();
	this.pProductoO = new ProductoOElements();
	this.pFloat = new FloatElements();
	this.eSalsaRecomendada = new SalsaRecomendadaElements();
	this.eTamanioMenu = new TamanioMenuElements();
	this.eDistribuidor = new DistribuidorElements();
	this.tFECHA = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.xtext.dsl.restaurante.Restaurante.FECHA");
	this.tURL = (TerminalRule) GrammarUtil.findRuleForName(getGrammar(), "org.xtext.dsl.restaurante.Restaurante.URL");
}
 
开发者ID:vicegd,项目名称:org.xtext.dsl.restaurante,代码行数:26,代码来源:RestauranteGrammarAccess.java

示例9: highlightSpecialIdentifiers

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
@Override
protected void highlightSpecialIdentifiers(final IHighlightedPositionAcceptor acceptor, final ICompositeNode root) {
  TerminalRule idRule = grammarAccess.getIDRule();

  for (ILeafNode leaf : root.getLeafNodes()) {
    if (commentProvider.isJavaDocComment(leaf)) {
      // not really a special identifier, but we don't want to iterate over the leaf nodes twice, do we?
      acceptor.addPosition(leaf.getOffset(), leaf.getLength(), CheckHighlightingConfiguration.JAVADOC_ID);
    } else if (!leaf.isHidden()) {
      if (leaf.getGrammarElement() instanceof Keyword) {
        // Check if it is a keyword used as an identifier.
        ParserRule rule = GrammarUtil.containingParserRule(leaf.getGrammarElement());
        if (FEATURE_CALL_ID_RULE_NAME.equals(rule.getName())) {
          acceptor.addPosition(leaf.getOffset(), leaf.getLength(), DefaultHighlightingConfiguration.DEFAULT_ID);
        }
      } else {
        highlightSpecialIdentifiers(leaf, acceptor, idRule);
      }
    }
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:22,代码来源:CheckHighlightingCalculator.java

示例10: resolveCrossReferencedElement

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
@Override
protected EObject resolveCrossReferencedElement(INode node) {
	EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node);
	if (referenceOwner != null) {
		EReference crossReference = GrammarUtil.getReference((CrossReference) node.getGrammarElement(),
				referenceOwner.eClass());
		if (!crossReference.isMany()) {
			EObject resultOrProxy = (EObject) referenceOwner.eGet(crossReference);
			if (resultOrProxy != null && resultOrProxy.eIsProxy() && crossReference == XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR) {
				if (referenceOwner instanceof XConstructorCall) {
					JvmIdentifiableElement linkedType = batchTypeResolver.resolveTypes(referenceOwner).getLinkedFeature((XConstructorCall)referenceOwner);
					if (linkedType != null)
						return linkedType;
				}
			} 
			return resultOrProxy;
		} else {
			return super.resolveCrossReferencedElement(node);
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:23,代码来源:BrokenConstructorCallAwareEObjectAtOffsetHelper.java

示例11: isValid

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
@Override
public boolean isValid(EObject semanticObject, CrossReference crossref, EObject target, INode node, Acceptor errors) {
	if ((target == null || target.eIsProxy()) && node != null) {
		CrossReference crossrefFromNode = GrammarUtil.containingCrossReference(node.getGrammarElement());
		return crossref == crossrefFromNode;
	}
	
	final EReference ref = GrammarUtil.getReference(crossref, semanticObject.eClass());
	final IScope scope = scopeProvider.getScope(semanticObject, ref);
	if (scope == null) {
		if (errors != null)
			errors.accept(diagnostics.getNoScopeFoundDiagnostic(semanticObject, crossref, target));
		return false;
	}
	
	if (target != null && target.eIsProxy()) {
		target = handleProxy(target, semanticObject, ref);
	}
	
	return getCrossReferenceNameFromScope(semanticObject, crossref, target, scope, errors) != null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:22,代码来源:CrossReferenceSerializer.java

示例12: checkDatatypeRules

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
private boolean checkDatatypeRules() {
	boolean result = true;
	for (AbstractRule rule : grammar.getRules()) {
		try {
			if (rule instanceof ParserRule && GrammarUtil.isDatatypeRule((ParserRule) rule) && !DatatypeRuleUtil.isValidDatatypeRule((ParserRule) rule)) {
				throw new TransformationException(TransformationErrorCode.InvalidDatatypeRule,
						"Datatype rules may only use other datatype rules, lexer rules and keywords.", rule);
			}
		}
		catch (TransformationException e) {
			reportError(e);
			result = false;
		}
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:Xtext2EcoreTransformer.java

示例13: collectAbstractElements

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
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);
				}
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:FollowElementComputer.java

示例14: adjustRuleName

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
protected String adjustRuleName(String ruleName, Param param) {
	AbstractElement elementToParse = param.elementToParse;
	Set<Parameter> context = getAssignedParameters(elementToParse, param.paramStack);
	if (!context.isEmpty()) {
		ParserRule containingRule = GrammarUtil.containingParserRule(elementToParse);
		String antlrRuleName = ruleNames.getAntlrRuleName(containingRule);
		int len = antlrRuleName.length();
		if (antlrRuleName.startsWith("rule")) {
			len += 2; // rule__XYZ instead of ruleXYZ
		}
		int config = getParameterConfig(context);
		String result = ruleNames.getAntlrRuleName(containingRule, config) + ruleName.substring(len);
		return result;
	}
	return ruleName;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:RequiredRuleNameComputer.java

示例15: testAssignedAction_02

import org.eclipse.xtext.GrammarUtil; //导入依赖的package包/类
@Test
public void testAssignedAction_02() 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 : Second ({First.second=current} name=ID)*;");
  _builder.newLine();
  _builder.append("Second: 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.assertTrue(this.warnings.toString(), this.warnings.isEmpty());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:OverriddenValueInspectorTest.java


注:本文中的org.eclipse.xtext.GrammarUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。