Closed faulknermano closed 5 years ago
You you are right. The regex based parsing is performed line by line. Thus one cannot use multi-line regex expressions.
I think for the cases like yours a dedicated simple mapper is a better approach: https://github.com/oleg-shilo/codemap.vscode/wiki/Adding-custom-mappers.
It is actually much simpler than one may think. Have a look at Markdown syntax parser sample at the link above. It might be the approach that would want to go with.
@oleg-shilo Thanks! Yes it was easy and I eventually did my own custom mapper that way. Thanks very much for this useful extension. I never thought this would ever come around. Now I can finally do LS development in VS Code (I used to have to do it in Notepad++). :-)
Glad you sorted it al out 👍
@faulknermano, @oleg-shilo I am also interested to make a multi-line mapper. This time for Verilog. Could you paste here a simple, working example how you did it? Thank you.
For what it's worth this is what I did for LScript (LightWave3D):
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
class mapper {
static read_all_lines(file) {
let text = fs.readFileSync(file, 'utf8');
return text.split(/\r?\n/g);
}
static generate(file) {
let members = [];
try
{
let line_num = 0;
let prev_line = "";
mapper
.read_all_lines(file)
.forEach(line => {
line_num++;
// line = line.trimStart();
if (line.startsWith("// SECTION:"))
members.push(`${line}|${line_num}|level1`);
else if (line.startsWith("{"))
members.push(`${prev_line}|${line_num-1}|function`);
prev_line = line;
});
}
catch (error) {
}
return members;
}
}
exports.mapper = mapper;
Do you mind if I include it in the extension distro?
@oleg-shilo not at all. Please feel free to!
Done. The LScript mapper (*.ld documents) is now a part of the default CodeMap distribution. https://marketplace.visualstudio.com/items?itemName=oleg-shilo.codemap
Hi, I'm trying to to add a custom mapper for a very old scripting language (LScript). It doesn't have a any sort of function keyword. A function is always at the topmost/global scope, and is defined if it precedes
{
and}
.So I wrote a simple regexp:
"^[A-z].*(?=\\n{)"
But this one doesn't work -- no result in CodeMap.
So I tried removing the newline lookahead:
"^[A-z].*"
And this one 'worked', but not my intended result. It seems like CodeMap is not able to use Regexp to process multiple lines? Is this possible to do?
This is an example of LScript code: