use of org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnosticSource in project ballerina by ballerina-lang.
the class Parser method generateCompilationUnit.
private CompilationUnitNode generateCompilationUnit(PackageSourceEntry sourceEntry) {
try {
int prevErrCount = dlog.errorCount;
BDiagnosticSource diagnosticSrc = getDiagnosticSource(sourceEntry);
String entryName = sourceEntry.getEntryName();
BLangCompilationUnit compUnit = (BLangCompilationUnit) TreeBuilder.createCompilationUnit();
compUnit.setName(sourceEntry.getEntryName());
compUnit.pos = new DiagnosticPos(diagnosticSrc, 1, 1, 1, 1);
ANTLRInputStream ais = new ANTLRInputStream(new ByteArrayInputStream(sourceEntry.getCode()));
ais.name = entryName;
BallerinaLexer lexer = new BallerinaLexer(ais);
lexer.removeErrorListeners();
lexer.addErrorListener(new BallerinaParserErrorListener(context, diagnosticSrc));
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
BallerinaParser parser = new BallerinaParser(tokenStream);
parser.setErrorHandler(getErrorStrategy(diagnosticSrc));
parser.addParseListener(newListener(tokenStream, compUnit, diagnosticSrc));
parser.compilationUnit();
return compUnit;
} catch (IOException e) {
throw new RuntimeException("Error in populating package model: " + e.getMessage(), e);
}
}
use of org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnosticSource in project ballerina by ballerina-lang.
the class Parser method parse.
public BLangPackage parse(PackageSource pkgSource) {
BLangPackage pkgNode = (BLangPackage) TreeBuilder.createPackageNode();
pkgSource.getPackageSourceEntries().forEach(e -> pkgNode.addCompilationUnit(generateCompilationUnit(e)));
pkgNode.pos = new DiagnosticPos(new BDiagnosticSource(pkgSource.getPackageId(), pkgSource.getName()), 1, 1, 1, 1);
pkgNode.repos = pkgSource.getRepoHierarchy();
return pkgNode;
}
Aggregations