Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/kicad/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function is_atom(c: string) {
"=",
"~",
"$",
"|",
].includes(c)
);
}
Expand Down Expand Up @@ -109,7 +110,10 @@ export function* tokenize(input: string) {
state = State.number;
start_idx = i;
continue;
} else if (is_alpha(c) || ["*", "&", "$", "/", "%"].includes(c)) {
} else if (
is_alpha(c) ||
["*", "&", "$", "/", "%", "|"].includes(c)
) {
state = State.atom;
start_idx = i;
continue;
Expand Down
25 changes: 25 additions & 0 deletions test/kicad/tokenizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,31 @@ suite("kicad.tokenizer.tokenize(): s-expression tokenizer", function () {
CLOSE_TOKEN,
]);
});

test("with embedded data containing pipes", function () {
const tokens = tokenizer.tokenize(
"(data |KLUv/aCvzgcAAAAQiVBORw0KGgoAAAANSUhEUgAABiAAAANoCAYAAABJLCIrAAAABHNCSVQICAgI)",
);
assert_tokens(tokens, [
OPEN_TOKEN,
[ATOM, "data"],
[
ATOM,
"|KLUv/aCvzgcAAAAQiVBORw0KGgoAAAANSUhEUgAABiAAAANoCAYAAABJLCIrAAAABHNCSVQICAgI",
],
CLOSE_TOKEN,
]);
});

test("with pipe character in middle of atom", function () {
const tokens = tokenizer.tokenize("(test |middle|end)");
assert_tokens(tokens, [
OPEN_TOKEN,
[ATOM, "test"],
[ATOM, "|middle|end"],
CLOSE_TOKEN,
]);
});
});

suite("kicad.tokenizer.listify()", function () {
Expand Down