Search in sources :

Example 21 with StringConcatenation

use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.

the class AntlrGrammarGenerator method compileReturns.

protected CharSequence compileReturns(final AbstractRule it, final AntlrOptions options) {
    CharSequence _switchResult = null;
    boolean _matched = false;
    if (it instanceof EnumRule) {
        _matched = true;
        _switchResult = "returns [Enumerator current=null]";
    }
    if (!_matched) {
        if (it instanceof ParserRule) {
            boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule) it)));
            if (_isDatatypeRule) {
                _matched = true;
                _switchResult = "[AntlrDatatypeRuleToken current=new AntlrDatatypeRuleToken()]";
            }
        }
    }
    if (!_matched) {
        if (it instanceof ParserRule) {
            boolean _isEObjectFragmentRule = GrammarUtil.isEObjectFragmentRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule) it)));
            if (_isEObjectFragmentRule) {
                _matched = true;
                StringConcatenation _builder = new StringConcatenation();
                _builder.append("[");
                String _currentType = this.getCurrentType();
                _builder.append(_currentType);
                _builder.append(" current=in_current]");
                _switchResult = _builder;
            }
        }
    }
    if (!_matched) {
        if (it instanceof ParserRule) {
            _matched = true;
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("[");
            String _currentType = this.getCurrentType();
            _builder.append(_currentType);
            _builder.append(" current=null]");
            _switchResult = _builder;
        }
    }
    if (!_matched) {
        throw new IllegalStateException(("Unexpected rule: " + it));
    }
    return _switchResult;
}
Also used : EnumRule(org.eclipse.xtext.EnumRule) ParserRule(org.eclipse.xtext.ParserRule) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 22 with StringConcatenation

use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.

the class AntlrGrammarGenerator method createModelElement.

protected CharSequence createModelElement(final EObject grammarElement) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("createModelElement(grammarAccess.");
    String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(GrammarUtil.containingParserRule(grammarElement));
    _builder.append(_grammarElementAccess);
    _builder.append(")");
    return _builder;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 23 with StringConcatenation

use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.

the class AntlrGrammarGenerator method compileRuleCatch.

@Override
protected String compileRuleCatch(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("@rulecatch {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("catch (RecognitionException re) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("recover(input,re);");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("appendSkippedTokens();");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder.toString();
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 24 with StringConcatenation

use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.

the class AntlrGrammarGenerator method compileParserImports.

@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.*;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.*;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.impl.*;");
    _builder.newLine();
    _builder.append("import org.eclipse.emf.ecore.util.EcoreUtil;");
    _builder.newLine();
    _builder.append("import org.eclipse.emf.ecore.EObject;");
    _builder.newLine();
    {
        boolean _isEmpty = GrammarUtil.allEnumRules(it).isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            _builder.append("import org.eclipse.emf.common.util.Enumerator;");
            _builder.newLine();
        }
    }
    _builder.append("import org.eclipse.xtext.parser.antlr.AbstractInternalAntlrParser;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
    _builder.newLine();
    {
        if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter(Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
            return EcoreUtil2.eAllContentsAsList(it_1);
        }))), UnorderedGroup.class))) && options.isBacktrack())) {
            _builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
            _builder.newLine();
        }
    }
    _builder.append("import org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken;");
    _builder.newLine();
    _builder.append("import ");
    String _gaFQName = this._grammarAccess.gaFQName(it);
    _builder.append(_gaFQName);
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    return _builder.toString();
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List)

Example 25 with StringConcatenation

use of org.eclipse.xtend2.lib.StringConcatenation in project xtext-eclipse by eclipse.

the class AntlrGrammarGenerator method compileOptions.

@Override
protected String compileOptions(final Grammar it, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.newLine();
    _builder.append("options {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("superClass=AbstractInternalAntlrParser;");
    _builder.newLine();
    {
        if (((options.isBacktrack() || options.isMemoize()) || (options.getK() >= 0))) {
            {
                boolean _isBacktrack = options.isBacktrack();
                if (_isBacktrack) {
                    _builder.append("\t");
                    _builder.append("backtrack=true;");
                    _builder.newLine();
                }
            }
            {
                boolean _isMemoize = options.isMemoize();
                if (_isMemoize) {
                    _builder.append("\t");
                    _builder.append("memoize=true;");
                    _builder.newLine();
                }
            }
            {
                int _k = options.getK();
                boolean _greaterEqualsThan = (_k >= 0);
                if (_greaterEqualsThan) {
                    _builder.append("\t");
                    _builder.append("memoize=");
                    int _k_1 = options.getK();
                    _builder.append(_k_1, "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder.toString();
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5377 Test (org.junit.Test)4633 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)384 ContentAssistProcessorTestBuilder (org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder)202 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)135 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)132 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)131 IFile (org.eclipse.core.resources.IFile)123 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)117 AbstractXtendCompilerTest (org.eclipse.xtend.core.tests.compiler.AbstractXtendCompilerTest)103 MutableClassDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableClassDeclaration)101 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)99 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)89 XExpression (org.eclipse.xtext.xbase.XExpression)82 CompilationTestHelper (org.eclipse.xtext.xbase.testing.CompilationTestHelper)80 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)76 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)73 EList (org.eclipse.emf.common.util.EList)67 List (java.util.List)66 Ignore (org.junit.Ignore)60