different attempt to parse using collapsable text

ranges
This commit is contained in:
Dave Holoway
2020-05-23 13:20:51 +01:00
parent bdc5b1d4cd
commit 23dc6d3871
18 changed files with 1904 additions and 345 deletions

View File

@@ -0,0 +1,33 @@
const { ModuleBlock, PackageBlock, ImportBlock, TypeDeclBlock } = require('../parser9');
const ParseProblem = require('../parsetypes/parse-problem');
/**
* @param {ModuleBlock} mod
*/
module.exports = function(mod) {
let have_imports, have_type;
const problems = [];
for (let decl of mod.decls()) {
let p;
switch (true) {
case decl instanceof PackageBlock:
if (have_imports || have_type) {
p = ParseProblem.Error(decl, 'package must be declared before import and type declarations');
}
break;
case decl instanceof ImportBlock:
if (have_type) {
p = ParseProblem.Error(decl, 'imports must be declared before type declarations');
}
have_imports = true;
break;
case decl instanceof TypeDeclBlock:
have_type = true;
break;
}
if (p) {
problems.push(p)
}
}
return problems;
}