use of org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions in project xtext-core by eclipse.
the class DebugGraphGenerator method generateDebugGraphs.
public Iterable<Pair<String, String>> generateDebugGraphs() {
final ArrayList<Pair<String, String>> result = CollectionLiterals.<Pair<String, String>>newArrayList();
@Extension final NamedSerializationContextProvider names = new NamedSerializationContextProvider(this.grammar);
final String dir_context = this.directory("context");
final String dir_context_type = this.directory("context_type");
final String dir_syntactic_sequencer = this.directory("syntactic_sequencer");
final String dir_semantic_sequencer = this.directory("semantic_sequencer");
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextPDAProvider.getContextPDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e : _namedContexts) {
{
String _name = e.getName();
String _plus = (dir_context + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e.getName();
String _plus_2 = (dir_context + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Pda<ISerState, RuleCall>>> _namedContexts_1 = names.<Pda<ISerState, RuleCall>>getNamedContexts(this.contextTypePDAProvider.getContextTypePDAs(this.grammar));
for (final NamedSerializationContexts<Pda<ISerState, RuleCall>> e_1 : _namedContexts_1) {
{
String _name = e_1.getName();
String _plus = (dir_context_type + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.pdaToDot, e_1.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_1.getName();
String _plus_2 = (dir_context_type + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_1.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState>> _namedContexts_2 = names.<ISyntacticSequencerPDAProvider.ISynAbsorberState>getNamedContexts(this.syntacticSequencerPDAProvider.getSyntacticSequencerPDAs(this.grammar));
for (final NamedSerializationContexts<ISyntacticSequencerPDAProvider.ISynAbsorberState> e_2 : _namedContexts_2) {
{
String _name = e_2.getName();
String _plus = (dir_syntactic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.syntacticSequencerPDA2Dot, e_2.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_2.getName();
String _plus_2 = (dir_syntactic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_2.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
List<NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>>> _namedContexts_3 = names.<Nfa<ISemanticSequencerNfaProvider.ISemState>>getNamedContexts(this.semanticSequencerNFAProvider.getSemanticSequencerNFAs(this.grammar));
for (final NamedSerializationContexts<Nfa<ISemanticSequencerNfaProvider.ISemState>> e_3 : _namedContexts_3) {
{
String _name = e_3.getName();
String _plus = (dir_semantic_sequencer + _name);
String _plus_1 = (_plus + ".dot");
String _drawSafe = this.drawSafe(this.nfaToDot, e_3.getValue());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _drawSafe);
result.add(_mappedTo);
String _name_1 = e_3.getName();
String _plus_2 = (dir_semantic_sequencer + _name_1);
String _plus_3 = (_plus_2 + ".txt");
String _join = IterableExtensions.join(e_3.getContexts(), "\n");
Pair<String, String> _mappedTo_1 = Pair.<String, String>of(_plus_3, _join);
result.add(_mappedTo_1);
}
}
try {
int i = 0;
final HashMap<ISyntacticSequencerPDAProvider.ISynTransition, String> trans2id = CollectionLiterals.<ISyntacticSequencerPDAProvider.ISynTransition, String>newHashMap();
Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.syntacticSequencerUtil.getAllAmbiguousTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) {
{
final String name = ("ambiguity_" + Integer.valueOf(i));
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + name);
String _plus_1 = (_plus + ".dot");
String _draw = this.nfaToDot.draw(transition.getAmbiguousNfa());
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus_1, _draw);
result.add(_mappedTo);
trans2id.put(transition, name);
i = (i + 1);
}
}
final StringBuffer ambiguities = new StringBuffer();
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = this.syntacticSequencerUtil.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("id: ");
String _identifier = group.getIdentifier();
_builder.append(_identifier);
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("Ambiguous syntax:�:");
_builder.newLine();
_builder.append(" ");
String _replace = group.getElementAlias().toString().replace("\n", "\n ");
_builder.append(_replace, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("This ambiguous syntax occurs at:");
_builder.newLine();
{
List<ISyntacticSequencerPDAProvider.ISynTransition> _transitions = group.getTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition trans : _transitions) {
_builder.append("\t");
String _get = trans2id.get(trans);
_builder.append(_get, "\t");
_builder.append(":");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(" ");
String _replace_1 = group.ambiguityInsideTransition(trans).replace("\n", "\n ");
_builder.append(_replace_1, "\t ");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.newLine();
ambiguities.append(_builder);
}
String _directory = this.directory("syntactic_sequencer");
String _plus = (_directory + "ambiguities.txt");
String _string = ambiguities.toString();
Pair<String, String> _mappedTo = Pair.<String, String>of(_plus, _string);
result.add(_mappedTo);
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e_4 = (Exception) _t;
e_4.printStackTrace();
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
use of org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions in project xtext-core by eclipse.
the class SerializerFragment2 method generateAbstractSyntacticSequencer.
protected void generateAbstractSyntacticSequencer() {
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getAbstractSyntacticSequencerClass(this.getGrammar());
} else {
_xifexpression = this.getSyntacticSequencerClass(this.getGrammar());
}
final TypeReference clazz = _xifexpression;
final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(clazz);
javaFile.setResourceSet(this.getLanguage().getResourceSet());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = SerializerFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = clazz.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(AbstractSyntacticSequencer.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
TypeReference _grammarAccess = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t");
_builder.append(" grammarAccess;");
_builder.newLineIfNotEmpty();
{
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
_builder.append("\t");
_builder.append("protected ");
TypeReference _typeReference = new TypeReference("org.eclipse.xtext.serializer.analysis", "GrammarAlias.AbstractElementAlias");
_builder.append(_typeReference, "\t");
_builder.append(" match_");
String _identifier = group.getIdentifier();
_builder.append(_identifier, "\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("protected void init(");
_builder.append(IGrammarAccess.class, "\t");
_builder.append(" access) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("grammarAccess = (");
TypeReference _grammarAccess_1 = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
_builder.append(_grammarAccess_1, "\t\t");
_builder.append(") access;");
_builder.newLineIfNotEmpty();
{
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_1 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group_1 : _allAmbiguousTransitionsBySyntax_1) {
_builder.append("\t\t");
_builder.append("match_");
String _identifier_1 = group_1.getIdentifier();
_builder.append(_identifier_1, "\t\t");
_builder.append(" = ");
StringConcatenationClient _elementAliasToConstructor = SerializerFragment2.this._syntacticSequencerExtensions.elementAliasToConstructor(group_1.getElementAlias());
_builder.append(_elementAliasToConstructor, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _genGetUnassignedRuleCallTokens = SerializerFragment2.this.genGetUnassignedRuleCallTokens();
_builder.append(_genGetUnassignedRuleCallTokens, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
{
List<AbstractRule> _unassignedCalledTokenRules = SerializerFragment2.this.unassignedCalledTokenRules();
boolean _hasElements = false;
for (final AbstractRule rule : _unassignedCalledTokenRules) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("\n", "\t");
}
_builder.append("\t");
StringConcatenationClient _genGetUnassignedRuleCallToken = SerializerFragment2.this.genGetUnassignedRuleCallToken(rule);
_builder.append(_genGetUnassignedRuleCallToken, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _genEmitUnassignedTokens = SerializerFragment2.this.genEmitUnassignedTokens();
_builder.append(_genEmitUnassignedTokens, "\t");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_2 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group_2 : _allAmbiguousTransitionsBySyntax_2) {
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Ambiguous syntax:");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* ");
String _replace = group_2.getElementAlias().toString().replace("\n", "\n * ");
_builder.append(_replace, "\t ");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(" ");
_builder.append("*");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* This ambiguous syntax occurs at:");
_builder.newLine();
{
final Function1<ISyntacticSequencerPDAProvider.ISynTransition, String> _function = (ISyntacticSequencerPDAProvider.ISynTransition it) -> {
return group_2.ambiguityInsideTransition(it).trim();
};
List<String> _sort = IterableExtensions.<String>sort(IterableExtensions.<String>toSet(ListExtensions.<ISyntacticSequencerPDAProvider.ISynTransition, String>map(group_2.getTransitions(), _function)));
for (final String trans : _sort) {
_builder.append("\t");
_builder.append(" ");
_builder.append("* ");
String _replace_1 = trans.toString().replace("\n", "\n* ");
_builder.append(_replace_1, "\t ");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void emit_");
String _identifier_2 = group_2.getIdentifier();
_builder.append(_identifier_2, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" semanticObject, ");
_builder.append(ISyntacticSequencerPDAProvider.ISynNavigable.class, "\t");
_builder.append(" transition, ");
_builder.append(List.class, "\t");
_builder.append("<");
_builder.append(INode.class, "\t");
_builder.append("> nodes) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("acceptNodes(transition, nodes);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
javaFile.setContent(_client);
List<IClassAnnotation> _annotations = javaFile.getAnnotations();
SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
_annotations.add(_suppressWarningsAnnotation);
javaFile.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
use of org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions in project xtext-core by eclipse.
the class SerializerFragment2 method genEmitUnassignedTokens.
private StringConcatenationClient genEmitUnassignedTokens() {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("@Override");
_builder.newLine();
_builder.append("protected void emitUnassignedTokens(");
_builder.append(EObject.class);
_builder.append(" semanticObject, ");
_builder.append(ISyntacticSequencerPDAProvider.ISynTransition.class);
_builder.append(" transition, ");
_builder.append(INode.class);
_builder.append(" fromNode, ");
_builder.append(INode.class);
_builder.append(" toNode) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("if (transition.getAmbiguousSyntaxes().isEmpty()) return;");
_builder.newLine();
_builder.append("\t");
_builder.append(List.class, "\t");
_builder.append("<");
_builder.append(INode.class, "\t");
_builder.append("> transitionNodes = collectNodes(fromNode, toNode);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("for (");
_builder.append(GrammarAlias.AbstractElementAlias.class, "\t");
_builder.append(" syntax : transition.getAmbiguousSyntaxes()) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append(List.class, "\t\t");
_builder.append("<");
_builder.append(INode.class, "\t\t");
_builder.append("> syntaxNodes = getNodesFor(transitionNodes, syntax);");
_builder.newLineIfNotEmpty();
{
Iterable<Pair<Integer, EqualAmbiguousTransitions>> _indexed = IterableExtensions.<EqualAmbiguousTransitions>indexed(SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax());
for (final Pair<Integer, EqualAmbiguousTransitions> group : _indexed) {
_builder.append("\t\t");
{
Integer _key = group.getKey();
boolean _greaterThan = ((_key).intValue() > 0);
if (_greaterThan) {
_builder.append("else ");
}
}
_builder.append("if (match_");
String _identifier = group.getValue().getIdentifier();
_builder.append(_identifier, "\t\t");
_builder.append(".equals(syntax))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
_builder.append("emit_");
String _identifier_1 = group.getValue().getIdentifier();
_builder.append(_identifier_1, "\t\t\t");
_builder.append("(semanticObject, getLastNavigableState(), syntaxNodes);");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
{
boolean _isEmpty = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
_builder.append("else ");
}
}
_builder.append("acceptNodes(getLastNavigableState(), syntaxNodes);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return _client;
}
use of org.eclipse.xtext.xtext.generator.serializer.EqualAmbiguousTransitions in project xtext-core by eclipse.
the class SyntacticSequencerExtensions method getAllAmbiguousTransitionsBySyntax.
public List<EqualAmbiguousTransitions> getAllAmbiguousTransitionsBySyntax() {
if ((this.ambiguousTransitions != null)) {
return this.ambiguousTransitions;
}
final Map<GrammarAlias.AbstractElementAlias, EqualAmbiguousTransitions> result = CollectionLiterals.<GrammarAlias.AbstractElementAlias, EqualAmbiguousTransitions>newHashMap();
Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.getAllAmbiguousTransitions();
for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) {
List<GrammarAlias.AbstractElementAlias> _ambiguousSyntaxes = transition.getAmbiguousSyntaxes();
for (final GrammarAlias.AbstractElementAlias syntax : _ambiguousSyntaxes) {
{
EqualAmbiguousTransitions list = result.get(syntax);
if ((list == null)) {
String _elementAliasToIdentifier = this.elementAliasToIdentifier(syntax);
EqualAmbiguousTransitions _equalAmbiguousTransitions = new EqualAmbiguousTransitions(_elementAliasToIdentifier, syntax);
list = _equalAmbiguousTransitions;
result.put(syntax, list);
}
list.getTransitions().add(transition);
}
}
}
this.ambiguousTransitions = CollectionLiterals.<EqualAmbiguousTransitions>newArrayList(((EqualAmbiguousTransitions[]) Conversions.unwrapArray(result.values(), EqualAmbiguousTransitions.class)));
ListExtensions.<EqualAmbiguousTransitions>sortInplace(this.ambiguousTransitions);
return this.ambiguousTransitions;
}
Aggregations