Search in sources :

Example 1 with MutableTokenDefProvider

use of org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider in project xtext-core by eclipse.

the class AbstractAntlrGeneratorFragment2 method cleanupParserTokensFile.

protected void cleanupParserTokensFile(final AntlrGrammar lexerGrammar, final AntlrGrammar parserGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) {
    try {
        final MutableTokenDefProvider provider = this.createLexerTokensProvider(lexerGrammar, helper, fsa);
        Set<Map.Entry<Integer, String>> _entrySet = provider.getTokenDefMap().entrySet();
        for (final Map.Entry<Integer, String> entry : _entrySet) {
            {
                final String value = entry.getValue();
                boolean _isKeywordRule = helper.isKeywordRule(value);
                if (_isKeywordRule) {
                    final String keywordAsAntlrString = AntlrGrammarGenUtil.toAntlrString(helper.getKeywordValue(value));
                    entry.setValue((("\'" + keywordAsAntlrString) + "\'"));
                } else {
                    boolean _startsWith = value.startsWith("\'");
                    if (_startsWith) {
                        String _antlrString = AntlrGrammarGenUtil.toAntlrString(value);
                        String _plus = ("\'" + _antlrString);
                        String _plus_1 = (_plus + "\'");
                        entry.setValue(_plus_1);
                    }
                }
            }
        }
        final CharArrayWriter writer = new CharArrayWriter();
        PrintWriter _printWriter = new PrintWriter(writer);
        provider.writeTokenFile(_printWriter);
        String _tokensFileName = parserGrammar.getTokensFileName();
        char[] _charArray = writer.toCharArray();
        String _string = new String(_charArray);
        fsa.generateFile(_tokensFileName, _string);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : MutableTokenDefProvider(org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider) Map(java.util.Map) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter)

Example 2 with MutableTokenDefProvider

use of org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider in project xtext-core by eclipse.

the class AbstractAntlrGeneratorFragment2 method cleanupLexerTokensFile.

protected void cleanupLexerTokensFile(final AntlrGrammar lexerGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) {
    try {
        boolean _isBacktrackLexer = this.options.isBacktrackLexer();
        if (_isBacktrackLexer) {
            final MutableTokenDefProvider provider = this.createLexerTokensProvider(lexerGrammar, helper, fsa);
            final Iterator<Map.Entry<Integer, String>> entries = provider.getTokenDefMap().entrySet().iterator();
            while (entries.hasNext()) {
                {
                    final String value = entries.next().getValue();
                    if ((((!helper.isKeywordRule(value)) && (!value.startsWith("RULE_"))) && (!value.startsWith("SUPER_")))) {
                        entries.remove();
                    }
                }
            }
            final CharArrayWriter writer = new CharArrayWriter();
            PrintWriter _printWriter = new PrintWriter(writer);
            provider.writeTokenFile(_printWriter);
            String _tokensFileName = lexerGrammar.getTokensFileName();
            char[] _charArray = writer.toCharArray();
            String _string = new String(_charArray);
            fsa.generateFile(_tokensFileName, _string);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : MutableTokenDefProvider(org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter)

Example 3 with MutableTokenDefProvider

use of org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider in project xtext-core by eclipse.

the class AbstractAntlrGeneratorFragment2 method createLexerTokensProvider.

protected MutableTokenDefProvider createLexerTokensProvider(final AntlrGrammar lexerGrammar, final KeywordHelper helper, final IXtextGeneratorFileSystemAccess fsa) {
    Charset _forName = Charset.forName(this.codeConfig.getEncoding());
    final MutableTokenDefProvider provider = new MutableTokenDefProvider(helper, _forName);
    final IAntlrTokenFileProvider _function = () -> {
        return fsa.readBinaryFile(lexerGrammar.getTokensFileName());
    };
    provider.setAntlrTokenFileProvider(_function);
    return provider;
}
Also used : Charset(java.nio.charset.Charset) MutableTokenDefProvider(org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider) IAntlrTokenFileProvider(org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider)

Aggregations

MutableTokenDefProvider (org.eclipse.xtext.xtext.generator.parser.antlr.MutableTokenDefProvider)3 CharArrayWriter (java.io.CharArrayWriter)2 PrintWriter (java.io.PrintWriter)2 Charset (java.nio.charset.Charset)1 Map (java.util.Map)1 IAntlrTokenFileProvider (org.eclipse.xtext.parser.antlr.IAntlrTokenFileProvider)1