Skip to content

Commit

Permalink
feat: added support for single line comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IamShobe committed Jan 10, 2025
1 parent fe1e30c commit 1c261b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/components/ui/editor/Highlighter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const typeToStyle = (type: string) => {

case "param":
return { color: "rgb(105, 177, 177)" };

case "comment":
return { color: "rgb(173, 196, 176)" };
}

return { color: "gray" };
Expand Down
1 change: 0 additions & 1 deletion src/core/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useEffect, useState } from "react";
import { Toaster } from "react-hot-toast";
import { LuChartArea, LuLogs, LuTable } from "react-icons/lu";
import { Provider } from "~components/ui/provider";
import { Tooltip } from "~components/ui/tooltip";
import { QueryProvider } from "./common/interface";
import { isDateSelectorOpen } from "./DateSelector";
import { queryEditorAtom } from "./Editor";
Expand Down
13 changes: 13 additions & 0 deletions src/core/qql/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const WhiteSpace = createToken({
pattern: /\s+/,
group: Lexer.SKIPPED,
});

const Comment = createToken({
name: "Comment",
pattern: /\/\/.*/,
line_breaks: false,
group: "singleLineComments",
});

const Comma = createToken({ name: "Comma", pattern: /,/ });
const Pipe = createToken({ name: "Pipe", pattern: /\|/ });
const DoubleQoutedString = createToken({
Expand Down Expand Up @@ -174,6 +182,7 @@ const RightSquareBracket = createToken({ name: "RightSquareBracket", pattern: m
// note we are placing WhiteSpace first as it is very common thus it will speed up the lexer.
const allTokens = [
WhiteSpace,
Comment,
DoubleQoutedString,
RegexPattern,

Expand Down Expand Up @@ -561,6 +570,10 @@ export class QQLParser extends EmbeddedActionsParser {
return this.highlightData;
}

public highlightComment = (token: IToken) => {
this.addHighlightData("comment", token);
}

public query = this.RULE("query", () => {
const controllerParams: ControllerIndexParam[] = [];

Expand Down
4 changes: 4 additions & 0 deletions src/core/qql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const allData = (input: string) => {
parser.input = lexer.tokens;
const response = parser.query();

lexer.groups["singleLineComments"].forEach((comment) => {
parser.highlightComment(comment);
});

return {
ast: response,
highlight: parser.getHighlightData(),
Expand Down

0 comments on commit 1c261b8

Please sign in to comment.