Search in sources :

Example 1 with CeylonLexer

use of org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer in project ceylon by eclipse.

the class CeylonVersionTool method updateModuleVersion.

private boolean updateModuleVersion(Module module, Map<String, String> updatedModuleVersions) throws IOException, RecognitionException {
    String moduleDescriptorPath = module.getUnit().getFullPath();
    CeylonLexer lexer = new CeylonLexer(new ANTLRFileStream(moduleDescriptorPath, encoding));
    TokenRewriteStream tokenStream = new TokenRewriteStream(lexer);
    CeylonParser parser = new CeylonParser(tokenStream);
    Tree.CompilationUnit cu = parser.compilationUnit();
    fixModuleImportNames(cu);
    String v = this.confirm == Confirm.dependencies ? this.newVersion : confirm("update.module.version", module.getNameAsString(), module.getVersion(), this.newVersion);
    if (v == null) {
        return false;
    } else if (!v.isEmpty()) {
        // record the new version for this module
        updatedModuleVersions.put(module.getNameAsString(), v);
        updateModuleVersion(moduleDescriptorPath, tokenStream, cu, v);
    }
    return true;
}
Also used : ANTLRFileStream(org.antlr.runtime.ANTLRFileStream) TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) CeylonLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer) CeylonParser(org.eclipse.ceylon.compiler.typechecker.parser.CeylonParser)

Example 2 with CeylonLexer

use of org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer in project ceylon by eclipse.

the class CeylonVersionTool method updateModuleImports.

private boolean updateModuleImports(Module module, Map<String, String> updatedModuleVersions) throws IOException, RecognitionException {
    String moduleDescriptorPath = module.getUnit().getFullPath();
    CeylonLexer lexer = new CeylonLexer(new ANTLRFileStream(moduleDescriptorPath, encoding));
    TokenRewriteStream tokenStream = new TokenRewriteStream(lexer);
    CeylonParser parser = new CeylonParser(tokenStream);
    Tree.CompilationUnit cu = parser.compilationUnit();
    fixModuleImportNames(cu);
    List<Tree.ImportModule> moduleImports = findUpdatedImport(cu, updatedModuleVersions);
    for (Tree.ImportModule moduleImport : moduleImports) {
        String importedModuleName = moduleImport.getName();
        String newVersion = updatedModuleVersions.get(importedModuleName);
        if (newVersion == null)
            newVersion = this.newVersion;
        String v = confirm("update.dependency.version", importedModuleName, module.getNameAsString(), module.getVersion(), newVersion);
        if (v == null) {
            return false;
        } else if (!v.isEmpty()) {
            updateImportVersion(moduleDescriptorPath, tokenStream, moduleImport, v);
        }
    }
    return true;
}
Also used : ANTLRFileStream(org.antlr.runtime.ANTLRFileStream) TokenRewriteStream(org.antlr.runtime.TokenRewriteStream) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) CeylonLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) CeylonParser(org.eclipse.ceylon.compiler.typechecker.parser.CeylonParser) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule)

Example 3 with CeylonLexer

use of org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer in project ceylon by eclipse.

the class PhasedUnits method parseFile.

protected void parseFile(VirtualFile file, VirtualFile srcDir) throws Exception {
    if (file.getName().endsWith(".ceylon") && (sourceFiles.isEmpty() || sourceFiles.contains(file))) {
        // System.out.println("Parsing " + file.getName());
        CeylonLexer lexer = new CeylonLexer(new ANTLRInputStream(file.getInputStream(), getEncoding()));
        CommonTokenStream tokenStream = new CommonTokenStream(new CeylonInterpolatingLexer(lexer));
        CeylonParser parser = new CeylonParser(tokenStream);
        Tree.CompilationUnit cu = parser.compilationUnit();
        PhasedUnit phasedUnit = new PhasedUnit(file, srcDir, cu, moduleSourceMapper.getCurrentPackage(), moduleManager, moduleSourceMapper, context, new ArrayList<Token>(tokenStream.getTokens()));
        addPhasedUnit(file, phasedUnit);
        List<LexError> lexerErrors = lexer.getErrors();
        for (LexError le : lexerErrors) {
            // System.out.println("Lexer error in " + file.getName() + ": " + le.getMessage());
            cu.addLexError(le);
        }
        lexerErrors.clear();
        List<ParseError> parserErrors = parser.getErrors();
        for (ParseError pe : parserErrors) {
            // System.out.println("Parser error in " + file.getName() + ": " + pe.getMessage());
            cu.addParseError(pe);
        }
        parserErrors.clear();
    }
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) Token(org.antlr.runtime.Token) CeylonLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer) CeylonInterpolatingLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonInterpolatingLexer) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ParseError(org.eclipse.ceylon.compiler.typechecker.parser.ParseError) CeylonParser(org.eclipse.ceylon.compiler.typechecker.parser.CeylonParser) ANTLRInputStream(org.antlr.runtime.ANTLRInputStream) LexError(org.eclipse.ceylon.compiler.typechecker.parser.LexError)

Example 4 with CeylonLexer

use of org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer in project ceylon by eclipse.

the class CeylonInterpolatingLexer method createInterpolatedLexer.

private void createInterpolatedLexer(String text, int start, int end) {
    String substring = text.substring(start + 2, end);
    try {
        interpolatedExpressionLexer = new CeylonLexer(new ANTLRReaderStream(new StringReader(substring)));
    } catch (IOException e) {
        interpolatedStringToken = null;
        interpolatedExpressionLexer = null;
    }
    currentIndexInStringToken = end;
}
Also used : StringReader(java.io.StringReader) ANTLRReaderStream(org.antlr.runtime.ANTLRReaderStream) CeylonLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer) IOException(java.io.IOException)

Example 5 with CeylonLexer

use of org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer in project ceylon by eclipse.

the class IssuesTests_1500_1999 method benchmarkParse.

private void benchmarkParse(String file) throws Exception {
    String readSource = readFile(new File(getPackagePath(), file));
    String source = readSource.toString();
    char[] chars = source.toCharArray();
    LineMap map = Position.makeLineMap(chars, chars.length, false);
    System.err.println(map.hashCode());
    ANTLRStringStream input = new ANTLRStringStream(source);
    CeylonLexer lexer = new CeylonLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    CeylonParser parser = new CeylonParser(tokens);
// CompilationUnit cu = parser.compilationUnit();
// System.err.println(cu.hashCode());
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) LineMap(org.eclipse.ceylon.langtools.tools.javac.util.Position.LineMap) CeylonLexer(org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer) File(java.io.File) CeylonParser(org.eclipse.ceylon.compiler.typechecker.parser.CeylonParser)

Aggregations

CeylonLexer (org.eclipse.ceylon.compiler.typechecker.parser.CeylonLexer)6 CeylonParser (org.eclipse.ceylon.compiler.typechecker.parser.CeylonParser)5 CommonTokenStream (org.antlr.runtime.CommonTokenStream)3 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)3 File (java.io.File)2 IOException (java.io.IOException)2 ANTLRFileStream (org.antlr.runtime.ANTLRFileStream)2 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)2 TokenRewriteStream (org.antlr.runtime.TokenRewriteStream)2 CeylonInterpolatingLexer (org.eclipse.ceylon.compiler.typechecker.parser.CeylonInterpolatingLexer)2 LexError (org.eclipse.ceylon.compiler.typechecker.parser.LexError)2 ParseError (org.eclipse.ceylon.compiler.typechecker.parser.ParseError)2 LineMap (org.eclipse.ceylon.langtools.tools.javac.util.Position.LineMap)2 StringReader (java.io.StringReader)1 ANTLRInputStream (org.antlr.runtime.ANTLRInputStream)1 ANTLRReaderStream (org.antlr.runtime.ANTLRReaderStream)1 Token (org.antlr.runtime.Token)1 CeylonCompilationUnit (org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit)1 ModuleSourceMapper (org.eclipse.ceylon.compiler.typechecker.analyzer.ModuleSourceMapper)1 Warning (org.eclipse.ceylon.compiler.typechecker.analyzer.Warning)1