Skip to content

Commit

Permalink
proper comment handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Oct 17, 2023
1 parent b39a9be commit 41599b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/src/parser/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import {

export const BlockComment = createToken({
name: "BlockComment",
pattern: /(?<=\r?\n)\/(?:[ \t]*\r?\n)[^\\]*\\?/, // TODO
pattern: /(?<=(\r?\n|[ \t]*))\/(?:[ \t]*\r?\n)[^\\]*\\?/,
group: Lexer.SKIPPED,
});

export const LineComment = createToken({
name: "LineComment",
pattern: /(?<=\r?\n|[ \t])\/.*/, // TODO
pattern: /(?:(?<=\r?\n|[ \t])|(?<!.))\/.*/,
longer_alt: BlockComment,
group: Lexer.SKIPPED,
});
Expand Down
2 changes: 1 addition & 1 deletion server/src/qLangServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export default class QLangServer {
),
},
message: error.message,
source: "kdb q",
source: "kdb",
};
diagnostics.push(diagnostic);
}
Expand Down
22 changes: 22 additions & 0 deletions test/suite/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ import * as assert from "assert";
import { QParser } from "../../server/src/parser/parser";

describe("QParser", () => {
describe("comments", () => {
it("should ignore block", () => {
QParser.parse("/\na:\n1\n\\");
assert.deepEqual(QParser.errors, []);
});

it("should ignore line", () => {
QParser.parse("/a:\n");
assert.deepEqual(QParser.errors, []);
});

it("should ignore inline", () => {
QParser.parse("a: 1 /a:\n");
assert.deepEqual(QParser.errors, []);
});

it("should not ignore overloaded slash", () => {
QParser.parse("a: ,/ a:\n");
assert.strictEqual(QParser.errors.length, 1);
});
});

describe("script", () => {
it("should parse empty", () => {
QParser.parse("");
Expand Down

0 comments on commit 41599b6

Please sign in to comment.