use of org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming in project xtext-core by eclipse.
the class XtextAntlrGeneratorFragment2 method generateProductionTokenSource.
public JavaFileAccess generateProductionTokenSource() {
JavaFileAccess _xblockexpression = null;
{
@Extension final GrammarNaming naming = this.productionNaming;
final JavaFileAccess file = this.fileFactory.createJavaFile(naming.getTokenSourceClass(this.getGrammar()));
final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("BEGIN", "INDENT", "OPEN")).contains(it.getName().toUpperCase()));
};
final Iterable<TerminalRule> open = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function);
final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
return Boolean.valueOf(Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("END", "DEDENT", "CLOSE")).contains(it.getName().toUpperCase()));
};
final Iterable<TerminalRule> close = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(this.getGrammar()), _function_1);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(AbstractIndentationTokenSource.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("(");
_builder.append(TokenSource.class, "\t");
_builder.append(" delegate) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(delegate);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected boolean shouldSplitTokenImpl(");
_builder.append(Token.class, "\t");
_builder.append(" token) {");
_builder.newLineIfNotEmpty();
{
final Function1<TerminalRule, TerminalRule> _function = (TerminalRule it) -> {
return AntlrGrammarGenUtil.<TerminalRule>getOriginalElement(it);
};
final Function1<TerminalRule, Boolean> _function_1 = (TerminalRule it) -> {
String _upperCase = it.getName().toUpperCase();
return Boolean.valueOf(Objects.equal(_upperCase, "WS"));
};
boolean _exists = IterableExtensions.<TerminalRule>exists(ListExtensions.<TerminalRule, TerminalRule>map(GrammarUtil.allTerminalRules(XtextAntlrGeneratorFragment2.this.getGrammar()), _function), _function_1);
if (_exists) {
_builder.append("\t\t");
_builder.append("// TODO Review assumption");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return token.getType() == ");
TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass, "\t\t");
_builder.append(".RULE_WS;");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t\t");
_builder.append("// TODO Implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw new UnsupportedOperationException(\"Implement me\");");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected int getBeginTokenType() {");
_builder.newLine();
{
int _size = IterableExtensions.size(open);
boolean _equals = (_size == 1);
if (_equals) {
_builder.append("\t\t");
_builder.append("// TODO Review assumption");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ");
TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass_1, "\t\t");
_builder.append(".");
String _ruleName = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(open));
_builder.append(_ruleName, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t\t");
_builder.append("// TODO Implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw new UnsupportedOperationException(\"Implement me\");");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected int getEndTokenType() {");
_builder.newLine();
{
int _size_1 = IterableExtensions.size(close);
boolean _equals_1 = (_size_1 == 1);
if (_equals_1) {
_builder.append("\t\t");
_builder.append("// TODO Review assumption");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return ");
TypeReference _internalParserClass_2 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass_2, "\t\t");
_builder.append(".");
String _ruleName_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.ruleName(IterableExtensions.<TerminalRule>head(close));
_builder.append(_ruleName_1, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
} else {
_builder.append("\t\t");
_builder.append("// TODO Implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("throw new UnsupportedOperationException(\"Implement me\");");
_builder.newLine();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
_xblockexpression = file;
}
return _xblockexpression;
}
use of org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming in project xtext-core by eclipse.
the class XtextAntlrGeneratorFragment2 method addRuntimeBindingsAndImports.
protected void addRuntimeBindingsAndImports() {
@Extension final GrammarNaming naming = this.productionNaming;
ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
boolean _tripleNotEquals = (_manifest != null);
if (_tripleNotEquals) {
ManifestAccess _manifest_1 = this.getProjectConfig().getRuntime().getManifest();
final Procedure1<ManifestAccess> _function = (ManifestAccess it) -> {
Set<String> _exportedPackages = it.getExportedPackages();
String _packageName = naming.getLexerClass(this.getGrammar()).getPackageName();
String _packageName_1 = naming.getParserClass(this.getGrammar()).getPackageName();
String _packageName_2 = naming.getInternalParserClass(this.getGrammar()).getPackageName();
Iterables.<String>addAll(_exportedPackages, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_packageName, _packageName_1, _packageName_2)));
Set<String> _requiredBundles = it.getRequiredBundles();
_requiredBundles.add("org.antlr.runtime");
};
ObjectExtensions.<ManifestAccess>operator_doubleArrow(_manifest_1, _function);
}
GuiceModuleAccess.BindingFactory _addTypeToType = new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IParser.class), naming.getParserClass(this.getGrammar())).addTypeToType(TypeReference.typeRef(ITokenToStringConverter.class), TypeReference.typeRef(AntlrTokenToStringConverter.class)).addTypeToType(TypeReference.typeRef(IAntlrTokenFileProvider.class), naming.getAntlrTokenFileProviderClass(this.getGrammar())).addTypeToType(naming.getLexerSuperClass(this.getGrammar()), naming.getLexerClass(this.getGrammar())).addTypeToType(TypeReference.typeRef(ITokenDefProvider.class), TypeReference.typeRef(AntlrTokenDefProvider.class));
TypeReference _lexerClass = naming.getLexerClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append(LexerProvider.class);
_builder.append(".create(");
TypeReference _lexerClass = naming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_lexerClass);
_builder.append(".class)");
}
};
GuiceModuleAccess.BindingFactory _addTypeToProviderInstance = _addTypeToType.addTypeToProviderInstance(_lexerClass, _client);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bind(");
_builder.append(Lexer.class);
_builder.append(".class)");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(".annotatedWith(");
_builder.append(Names.class, "\t");
_builder.append(".named(");
_builder.append(LexerBindings.class, "\t");
_builder.append(".RUNTIME))");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(".to(");
TypeReference _lexerClass = naming.getLexerClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_lexerClass, "\t");
_builder.append(".class);");
_builder.newLineIfNotEmpty();
}
};
final GuiceModuleAccess.BindingFactory rtBindings = _addTypeToProviderInstance.addConfiguredBinding("RuntimeLexer", _client_1);
boolean _containsUnorderedGroup = this.containsUnorderedGroup(this.getGrammar());
if (_containsUnorderedGroup) {
rtBindings.addTypeToType(TypeReference.typeRef(IUnorderedGroupHelper.class), TypeReference.typeRef(UnorderedGroupHelper.class));
}
boolean _isIgnoreCase = this.getOptions().isIgnoreCase();
if (_isIgnoreCase) {
rtBindings.addTypeToType(TypeReference.typeRef(ITokenSerializer.IKeywordSerializer.class), TypeReference.typeRef(IgnoreCaseKeywordSerializer.class)).addTypeToType(TypeReference.typeRef(IKeywordSerializer.class), TypeReference.typeRef(org.eclipse.xtext.serializer.tokens.IgnoreCaseKeywordSerializer.class)).addTypeToType(TypeReference.typeRef(AbstractIDValueConverter.class), TypeReference.typeRef(IgnoreCaseIDValueConverter.class));
}
rtBindings.contributeTo(this.getLanguage().getRuntimeGenModule());
}
use of org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming in project xtext-core by eclipse.
the class XtextAntlrGeneratorFragment2 method generateProductionParser.
public JavaFileAccess generateProductionParser() {
GeneratedJavaFileAccess _xblockexpression = null;
{
@Extension final GrammarNaming naming = this.productionNaming;
final GeneratedJavaFileAccess file = this.fileFactory.createGeneratedJavaFile(naming.getParserClass(this.getGrammar()));
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = naming.getParserClass(XtextAntlrGeneratorFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(AbstractAntlrParser.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("private ");
TypeReference _grammarAccess = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t");
_builder.append(" grammarAccess;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void setInitialHiddenTokens(");
_builder.append(XtextTokenStream.class, "\t");
_builder.append(" tokenStream) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("tokenStream.setInitialHiddenTokens(");
{
List<String> _initialHiddenTokens = XtextAntlrGeneratorFragment2.this.grammarUtil.initialHiddenTokens(XtextAntlrGeneratorFragment2.this.getGrammar());
boolean _hasElements = false;
for (final String hidden : _initialHiddenTokens) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "\t\t");
}
_builder.append("\"");
_builder.append(hidden, "\t\t");
_builder.append("\"");
}
}
_builder.append(");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
{
boolean _hasSyntheticTerminalRule = XtextAntlrGeneratorFragment2.this.hasSyntheticTerminalRule();
if (_hasSyntheticTerminalRule) {
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
_builder.append(TokenSource.class, "\t");
_builder.append(" createLexer(");
_builder.append(CharStream.class, "\t");
_builder.append(" stream) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return new ");
TypeReference _tokenSourceClass = naming.getTokenSourceClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_tokenSourceClass, "\t\t");
_builder.append("(super.createLexer(stream));");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Indentation aware languages do not support partial parsing since the lexer is inherently stateful.");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Override and return {@code true} if your terminal splitting is stateless.");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected boolean isReparseSupported() {");
_builder.newLine();
_builder.append("\t");
_builder.append("\t");
_builder.append("return false;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
TypeReference _internalParserClass = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass, "\t");
_builder.append(" createParser(");
_builder.append(XtextTokenStream.class, "\t");
_builder.append(" stream) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return new ");
TypeReference _internalParserClass_1 = naming.getInternalParserClass(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_internalParserClass_1, "\t\t");
_builder.append("(stream, getGrammarAccess());");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override ");
_builder.newLine();
_builder.append("\t");
_builder.append("protected String getDefaultRuleName() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return \"");
String _name = AntlrGrammarGenUtil.<ParserRule>getOriginalElement(IterableExtensions.<ParserRule>head(GrammarUtil.allParserRules(XtextAntlrGeneratorFragment2.this.getGrammar()))).getName();
_builder.append(_name, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
TypeReference _grammarAccess_1 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess_1, "\t");
_builder.append(" getGrammarAccess() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return this.grammarAccess;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("public void setGrammarAccess(");
TypeReference _grammarAccess_2 = XtextAntlrGeneratorFragment2.this.grammarUtil.getGrammarAccess(XtextAntlrGeneratorFragment2.this.getGrammar());
_builder.append(_grammarAccess_2, "\t");
_builder.append(" grammarAccess) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("this.grammarAccess = grammarAccess;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
_xblockexpression = file;
}
return _xblockexpression;
}
use of org.eclipse.xtext.xtext.generator.parser.antlr.GrammarNaming in project xtext-core by eclipse.
the class XtextAntlrGeneratorFragment2 method generateProductionGrammar.
protected void generateProductionGrammar() {
@Extension final GrammarNaming naming = this.productionNaming;
final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getRuntime().getSrcGen();
this.productionGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
this.runAntlr(naming.getParserGrammar(this.getGrammar()), naming.getLexerGrammar(this.getGrammar()), fsa);
this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, naming.getInternalParserClass(this.getGrammar()));
this.splitParserAndLexerIfEnabled(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
this.normalizeTokens(fsa, naming.getLexerGrammar(this.getGrammar()).getTokensFileName());
this.suppressWarnings(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
this.normalizeLineDelimiters(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
}
Aggregations