@imc-trading/svlangserver
Version:
A language server for systemverilog
212 lines (190 loc) • 6.14 kB
JavaScript
/*import {
GrammarEngine
} from './grammar_engine';
import {
svcompletion_grammar
} from './svgrammar';
let grammar_engine: GrammarEngine = new GrammarEngine(svcompletion_grammar, "meta.any.systemverilog");
//grammar_engine.debugPrint();*/
//const R_COMMENT_LINE: string = String.raw`//.*(?:\n|\r)`;
//const T_COMMENT_LINE: string = "comment.line.systemverilog";
//
//const R_COMMENT_BLOCK: string = String.raw`/\*(?:.|\n|\r)*?(?:\*/|$)`;
//const T_COMMENT_BLOCK: string = "comment.block.systemverilog";
//
//const R_WHITESPACE: string = String.raw`(?:\s|\n|\r)+`;
//const T_WHITESPACE: string = "meta.whitespace.systemverilog";
//
//let match1: RegExp = new RegExp(String.raw`;`, 'y');
////let match2: RegExp = new RegExp(`((?:(?:${R_WHITESPACE})|(?:${R_COMMENT_LINE})|(?:${R_COMMENT_BLOCK}))*)\\b(else)\\b`, 'y');
//let match2: RegExp = new RegExp(`((?:(?:${R_WHITESPACE})|(?:${R_COMMENT_LINE})|(?:${R_COMMENT_BLOCK}))*)` + String.raw`\b(else)\b`, 'y');
//let text: string = `;
//else
// $display("");
//`
//console.log(`DEBUG: text = ${text}`);
//
//let m1 = match1.exec(text);
//console.log(`DEBUG: ${m1} [${m1[0]}]`);
//
//match2.lastIndex = match1.lastIndex;
//let m2 = match2.exec(text);
//console.log(`DEBUG: ${m2} [${m2[0]}][${m2[1]}][${m2[2]}]`);
/*
function proc(txt: string, pos: number): string {
let endPos: number = txt.indexOf("::", pos > 0 ? pos - 1 : 0);
endPos = endPos < 0 ? txt.length : endPos;
txt = txt.slice(0, endPos);
txt = txt.replace(/::\*$/, '');
if (txt == "*") {
return "null";
}
else {
return txt;
}
}
let symText: string = "func_pkg::clog2";
for (let i: number = 0; i < symText.length; i++) {
console.log(`DEBUG: ${symText}[${i}] = ${symText.slice(0, i + 1)} = ${proc(symText, i)}`);
}
symText = "some_pkg::*";
for (let i: number = 0; i < symText.length; i++) {
console.log(`DEBUG: ${symText}[${i}] = ${symText.slice(0, i + 1)} = ${proc(symText, i)}`);
}
symText = "*::*";
for (let i: number = 0; i < symText.length; i++) {
console.log(`DEBUG: ${symText}[${i}] = ${symText.slice(0, i + 1)} = ${proc(symText, i)}`);
}*/
/*const line1: string = "Warning: ./some.sv:13:14: test error";
const line2: string = "Warning: :13:14: test error";
const line3: string = "Warning: ./some.sv:14: test error";
const line4: string = "Warning: :14: test error";
const regex1 = String.raw`(Error|Warning)(-[A-Z0-9_]+)?: (`;
const regex2 = String.raw`):(\d+):(?:(\d+):)? (.*)`;
function test(lines: string[], file: string) {
const regex: RegExp = new RegExp(regex1 + file.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') + regex2, 'i');
console.log(`DEBUG: regex = ${regex.toString()}`);
for (let line of lines) {
const terms = line.match(regex);
console.log(`line --- ${line}`);
if (terms != null) {
for (let i: number = 0; i < terms.length; i++) {
console.log(` term[${i}] = ${terms[i]}, ${parseInt(terms[i])}`);
}
}
}
}
test([line1, line3], "./some.sv");
test([line2], "");
test([line4], "");*/
/*const msg: string = 'unsupported: Interfaced port on top level module'
const wmsgs: RegExp[] = [
/Unsupported: Interfaced port on top level module/i
];
for (let wmsg of wmsgs) {
if (msg.search(wmsg) >= 0) {
console.log(`DEBUG: --- ${msg} --- matches whitelisted message ${wmsg}`);
}
else {
console.log(`DEBUG: --- ${msg} --- DOES NOT match whitelisted message ${wmsg}`);
}
}
*/
/*let lines: string[] = ["abcd", "efgh", "ijkl"];
lines.forEach((line, i) => {
if (line.startsWith("ef")) {
console.log(`DEBUG: ${line} starts with ef`);
return;
}
console.log(`DEBUG: ${line}`);
});*/
/*import {
Position
} from 'vscode-languageserver-types';
let foo: Position = Position.create(10, 12);
console.log(`DEBUG: position = ${JSON.stringify(foo)}`);*/
/*function func(arg1: string, arg2: number[]) {
console.log(`DEBUG: arg1 = ${arg1}, arg2 = ${arg2}`);
}
function foo(): [string, number[]] {
return ["abcd", [1, 2, 3]];
}
func(...foo());*/
/*
{
let objects: [number, string][] = [];
function newObj(num: number): [number, string] {
return [123 + num, `string ${123 + num}`];
}
function checkObj(obj: [number, string], num: number): boolean {
return (obj[0] == 123 + num) && (obj[1] == `string ${123 + num}`);
}
for (let i: number = 0; i < 1000000; i++) {
objects.push(newObj(i));
}
const usage = process.memoryUsage();
for (let key in usage) {
console.log(`${key} usage = ${usage[key]}`);
}
for (let i: number = 0; i < 1000000; i++) {
if (!checkObj(objects[i], i)) {
console.log(`This should never happen`);
}
}
console.log(`DONE 2`);
}
try {
global.gc();
} catch (e) {
console.log("`Use --expose-gc option`");
process.exit();
}
{
class C {
number_member: number;
string_member: string;
constructor(num: number) {
this.number_member = 123 + num;
this.string_member = `string ${123 + num}`;
}
check(num: number): boolean {
return (this.number_member == 123 + num) && (this.string_member == `string ${123 + num}`);
}
}
let objects: C[] = [];
for (let i: number = 0; i < 1000000; i++) {
objects.push(new C(i));
}
const usage = process.memoryUsage();
for (let key in usage) {
console.log(`${key} usage = ${usage[key]}`);
}
for (let i: number = 0; i < 1000000; i++) {
if (!objects[i].check(i)) {
console.log(`This should never happen`);
}
}
console.log(`DONE 1`);
}
*/
/*
class C {
n: string;
constructor(n: string) {
this.n = n;
}
}
function foo(): [string, C, C[]] {
return ["abc", new C("on"), [new C("on1"), new C("on2")]];
}
let s: string;
let o: C;
[s, o] = foo();
console.log(`DEBUG: string = ${s}, object = ${o.n}`);
*/
function f() {
return "BLAH";
}
let foo = [undefined, undefined];
foo[0][0] = f();
console.log(`DEBUG: ${foo[0] == undefined} ${foo[0][0]}`);