Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Nov 28, 2021
1 parent 6fca6dc commit 7b3f2e0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
37 changes: 37 additions & 0 deletions lib/text_builder/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { assertEquals } from "../../deps/std/testing.ts";
import { T } from "../tokenize/mod.ts";
import {
cleanComment,
makeFileEndEventContext,
makeFileStartEventContext,
makeInlineCommentEventContext,
makeLoadEventContext,
makeMultilineCommentEventContext,
makeSetPropertyEventContext,
makeStructCloseEventContext,
makeStructOpenEventContext,
} from "./utils.ts";

Deno.test("cleans inlined comments to extract text content", () => {
const expectation = ["example"];
const reality = cleanComment(T.comment("; example", 1, 1));
assertEquals(expectation, reality);
});

Deno.test("cleans multi-inlined comments to extract text content", () => {
const expectation = ["example"];
const reality = cleanComment(T.multiline_comment("/* example */", 1, 1));
assertEquals(expectation, reality);
});

Deno.test("cleans multi-inlined comments to extract text content (omits whitespace on edges)", () => {
const expectation = ["example"];
const reality = cleanComment(T.multiline_comment(
`/*
example
*/`,
1,
1,
));
assertEquals(expectation, reality);
});
14 changes: 6 additions & 8 deletions lib/text_builder/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ export const cleanComment = (commentToken: Token): string[] => {
const rawComment = commentToken.value;
const lineBreakIndex = rawComment.indexOf("\n");
const inlineCommentContent = rawComment
.slice(
1,
lineBreakIndex > -1 ? lineBreakIndex : rawComment.length,
)
.slice(0, lineBreakIndex > -1 ? lineBreakIndex : rawComment.length)
.trim();
trimmedCommentLines.push(inlineCommentContent);
break;
}
case Lexicon.MultilineComment: {
const rawCommentLines = commentToken.value.slice(2, -2).split("\n");
rawCommentLines.forEach((rawCommentLine) =>
trimmedCommentLines.push(rawCommentLine.trim())
);
const rawCommentLines = commentToken.value.split("\n");
rawCommentLines.forEach((rawCommentLine) => {
// TODO: push only if the line is not a blank edge
trimmedCommentLines.push(rawCommentLine.trim());
});
break;
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/tokenize/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export class Token {
switch (this.kind) {
case Lexicon.TextLiteral: {
// strips expected text markers from beginning and end of input string
return this.value.slice(1, this.value.length - 1);
return this.raw.slice(1, this.value.length - 1);
}
case Lexicon.InlineComment: {
return this.raw.slice(1).trim();
}
case Lexicon.MultilineComment: {
return this.raw.slice(2, this.raw.length - 2).trim();
}
default: {
return this.raw;
Expand Down

1 comment on commit 7b3f2e0

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 7b3f2e0 Nov 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

failed to fetch 'https://raw.githubusercontent.com/EthanThatOneKid/fart/7b3f2e0ea070117469ecee41b30d19a67edcb6c5/std/server/worker.ts': HTTP status client error (404 Not Found) for url (https://raw.githubusercontent.com/EthanThatOneKid/fart/7b3f2e0ea070117469ecee41b30d19a67edcb6c5/std/server/worker.ts)

Please sign in to comment.