Skip to content
Open
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
2 changes: 1 addition & 1 deletion packages/parser/lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const INVALID_SLASH_OPEN = createToken({

const PROCESSING_INSTRUCTION = createToken({
name: "PROCESSING_INSTRUCTION",
pattern: makePattern`<\\?${f.Name}.*\\?>`,
pattern: makePattern`<\\?${f.Name}.*?\\?>`,
});

const OPEN = createToken({ name: "OPEN", pattern: /</, push_mode: "INSIDE" });
Expand Down
22 changes: 22 additions & 0 deletions packages/parser/test/parser-smoke-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,26 @@ describe("The XML Parser", () => {
const lexAndParseResult = parse(inputText);
expect(lexAndParseResult.parseErrors).to.be.empty;
});

it("should tokenize processing instructions in sibling elements separately", () => {
const inputText =
'<list><value id="all"><label>All</label></value><value id="one-one"><?group one?><label>One</label></value><value id="one-two"><?group one?><label>Two</label></value><value id="two-one"><?group two?><label>One</label></value><value id="two-two"><?group two?><label>Two</label></value></list>';
const { lexErrors, parseErrors, tokenVector } = parse(inputText);
const processingInstructionImages = tokenVector.reduce(
(images, token) =>
token.tokenType.name === "PROCESSING_INSTRUCTION"
? [...images, token.image]
: images,
[]
);

expect(lexErrors).to.be.empty;
expect(parseErrors).to.be.empty;
expect(processingInstructionImages).to.deep.equal([
"<?group one?>",
"<?group one?>",
"<?group two?>",
"<?group two?>",
]);
});
});