org.eclipse.xtext.xtext.RuleNames Java Examples
The following examples show how to use
org.eclipse.xtext.xtext.RuleNames.
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: GrammarPDAProvider.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public SerializationContextMap<Pda<ISerState, RuleCall>> getGrammarPDAs(Grammar grammar) { RuleNames names = RuleNames.getRuleNames(grammar, true); RuleFilter filter = new RuleFilter(); filter.setDiscardTerminalRules(true); filter.setDiscardUnreachableRules(false); filter.setDiscardRuleTypeRef(false); Grammar flattened = new FlattenedGrammarAccess(names, filter).getFlattenedGrammar(); Builder<Pda<ISerState, RuleCall>> result = SerializationContextMap.<Pda<ISerState, RuleCall>>builder(); for (ParserRule rule : GrammarUtil.allParserRules(flattened)) { RuleWithParameterValues withParams = RuleWithParameterValues.findInEmfObject(rule); AbstractRule original = withParams.getOriginal(); if (original instanceof ParserRule && isValidRule((ParserRule) original)) { ISerializationContext context = createContext((ParserRule) original, withParams.getParamValues()); try { Pda<ISerState, RuleCall> pda = createPDA(grammar, rule); result.put(context, pda); } catch (Exception e) { LOG.error("Error creating PDA for context '" + context + "': " + e.getMessage(), e); } } } return result.create(); }
Example #2
Source File: AbstractAntlrGrammarGenerator.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public void generate(final Grammar it, final AntlrOptions options, final IXtextGeneratorFileSystemAccess fsa) { this.keywordHelper = KeywordHelper.getHelper(it); this.originalGrammar = it; final RuleFilter filter = new RuleFilter(); filter.setDiscardUnreachableRules(options.isSkipUnusedRules()); final RuleNames ruleNames = RuleNames.getRuleNames(it, true); final Grammar flattened = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar(); boolean _isCombinedGrammar = this.isCombinedGrammar(); new CombinedGrammarMarker(_isCombinedGrammar).attachToEmfObject(flattened); fsa.generateFile(this.getGrammarNaming().getParserGrammar(it).getGrammarFileName(), this.compileParser(flattened, options)); boolean _isCombinedGrammar_1 = this.isCombinedGrammar(); boolean _not = (!_isCombinedGrammar_1); if (_not) { fsa.generateFile(this.getGrammarNaming().getLexerGrammar(it).getGrammarFileName(), this.compileLexer(flattened, options)); } }
Example #3
Source File: AbstractAntlrGeneratorFragment.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void generate(Grammar grammar, XpandExecutionContext ctx) { checkGrammar(grammar); RuleFilter filter = new RuleFilter(); filter.setDiscardUnreachableRules(getOptions().isSkipUnusedRules()); RuleNames ruleNames = RuleNames.getRuleNames(grammar, true); Grammar flattened = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar(); super.generate(flattened, ctx); }
Example #4
Source File: GrammarAccessFragment.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public void generate(Grammar grammar, XpandExecutionContext ctx) { RuleNames.ensureAdapterInstalled(grammar); super.generate(grammar, ctx); final ResourceSaveIndicator isSaving = new ResourceSaveIndicator(); // create a defensive clone Grammar copy = deepCopy(grammar, isSaving); ResourceSet set = copy.eResource().getResourceSet(); // save grammar model String path; if (xmlVersion == null) { path = GrammarUtil.getClasspathRelativePathToBinGrammar(copy); } else { log.warn("'xmlVersion' has been specified for this " + GrammarAccessFragment.class.getSimpleName() + ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback."); path = GrammarUtil.getClasspathRelativePathToXmi(copy); } URI uri = URI.createURI(ctx.getOutput().getOutlet(Generator.SRC_GEN).getPath() + "/" + path); Resource resource = set.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE); addAllGrammarsToResource(resource, copy, new HashSet<Grammar>()); isSaving.set(Boolean.TRUE); Map<String, Object> saveOptions = Maps.newHashMap(); if (resource instanceof XMLResource) { ((XMLResource) resource).setXMLVersion(getXmlVersion()); } else if (resource instanceof BinaryResourceImpl){ saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1); saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.TRUE); } try { resource.save(saveOptions); } catch (IOException e) { log.error(e.getMessage(), e); } finally { isSaving.set(Boolean.FALSE); } }
Example #5
Source File: GrammarFlatteningTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public Grammar getModel(final String model, final boolean dropUnreachable) throws Exception { EObject _model = super.getModel(model); Grammar grammar = ((Grammar) _model); RuleNames ruleNames = RuleNames.getRuleNames(grammar, false); RuleFilter filter = new RuleFilter(); filter.setDiscardUnreachableRules(dropUnreachable); Grammar result = new FlattenedGrammarAccess(ruleNames, filter).getFlattenedGrammar(); XtextResource resource = this.<XtextResource>get(XtextResource.class); resource.getContents().add(result); resource.setURI(URI.createURI("synthetic://flattened.xtext")); return result; }
Example #6
Source File: AntlrGrammarGenUtil.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Returns the effective rule name for the generated Antlr grammar. * Inherited rules may be prefixed by {@code super[0..9]*}. Otherwise the * prefix {@code rule or RULE_} is used. * @since 2.9 */ public static String getRuleName(AbstractRule rule) { RuleWithParameterValues parameterValues = RuleWithParameterValues.findInEmfObject(rule); if (parameterValues != null) { return rule.getName(); } RuleNames ruleNames = RuleNames.getRuleNames(rule); return ruleNames.getAntlrRuleName(rule); }
Example #7
Source File: GrammarAccessExtensions.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
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 #8
Source File: BaseContentAssistParser.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.14 */ protected RuleNames getRuleNames() { return ruleNames; }
Example #9
Source File: PropertyNameAwareElementFactory.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Inject private void readRuleNames(N4JSGrammarAccess grammarAccess, RuleNames ruleNames) { stringRuleName = ruleNames.getQualifiedName(grammarAccess.getSTRINGRule()); identifierRuleName = ruleNames.getQualifiedName(grammarAccess.getIdentifierNameRule()); numberRuleName = ruleNames.getQualifiedName(grammarAccess.getNumericLiteralAsStringRule()); }
Example #10
Source File: XtextGeneratorLanguage.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Pure public RuleNames getRuleNames() { return this.ruleNames; }
Example #11
Source File: XtextGeneratorLanguage.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void initialize(final Grammar grammar) { this.grammar = grammar; this.ruleNames = RuleNames.getRuleNames(grammar, true); }
Example #12
Source File: GrammarAccessExtensions.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * Creates an identifier for a Rule which is a valid Java identifier and unique within * the Rule's grammar and its super grammars. */ public String gaRuleIdentifier(final AbstractRule rule) { final String plainName = RuleNames.getRuleNames(rule).getUniqueRuleName(rule); return this.toJavaIdentifier(plainName, true); }
Example #13
Source File: LanguageModule.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public void configureRuleNames(Binder binder) { binder.bind(RuleNames.class).toProvider(() -> language.getRuleNames()); }
Example #14
Source File: AntlrGrammarGenUtil.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.9 */ public static String getQualifiedNameAsString(RuleCall ruleCall) { AbstractRule rule = getOriginalElement(ruleCall).getRule(); String result = RuleNames.getRuleNames(rule).getQualifiedName(rule); return '"' + result + '"'; }
Example #15
Source File: Context2NameFunction.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
public String getContextName(Grammar grammar, ParserRule ctx) { if (grammar == null) { return ctx.getName(); } return RuleNames.getRuleNames(grammar, false).getUniqueRuleName(ctx); }
Example #16
Source File: DefaultHiddenTokenHelper.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Inject private void setGrammar(RuleNames names) { wsRule = Iterables.getFirst(names.getRulesBySimpleName("WS"), null); }
Example #17
Source File: GrammarAccessUtil.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
/** * @since 2.9 */ public static String getUniqueRuleName(AbstractRule rule) { String plainName = RuleNames.getRuleNames(rule).getUniqueRuleName(rule); return toJavaIdentifier(plainName, true); }
Example #18
Source File: RequiredRuleNameComputer.java From xtext-core with Eclipse Public License 2.0 | 2 votes |
/** * @noreference This method is not intended to be referenced by clients. * @nooverride This method is not intended to be re-implemented or extended by clients. */ protected RuleNames getRuleNames() { return ruleNames; }
Example #19
Source File: GrammarAccess.java From xtext-extras with Eclipse Public License 2.0 | 2 votes |
/** * Creates an identifier for a Rule which is a valid Java identifier and * unique within the Rule's grammar. * * @param rule the Rule * @return the identifier */ public String gaRuleIdentifyer(AbstractRule rule) { String plainName = RuleNames.getRuleNames(rule).getUniqueRuleName(rule); return toJavaIdentifier(plainName, true); }