Skip to content

Commit

Permalink
refactoed ohm logic, stage2 and prettier broken
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilGenius13 committed Jan 17, 2025
1 parent 2e56122 commit 2b3cdd9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
6 changes: 5 additions & 1 deletion packages/liquid-html-parser/grammar/liquid-html.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,15 @@ LiquidDoc <: Helpers {

fallbackNode = "@" anyExceptStar<endOfParam>
paramNode = "@param" strictSpace* paramType? strictSpace* paramName (strictSpace* "-")? strictSpace* paramDescription
paramType = "{" strictSpace* paramTypeContent strictSpace* "}"
paramType = "{" anyExceptPlus<"}"> "}"
paramTypeContent = anyExceptStar<("}"| strictSpace)>
paramName = identifierCharacter+
paramDescription = anyExceptStar<endOfParam>
endOfParam = strictSpace* (newline | end)

exampleNode = "@example" strictSpace* exampleContent
exampleContent = anyExceptStar<endOfExample>
endOfExample = strictSpace* ("@" | end)
}

LiquidHTML <: Liquid {
Expand Down
10 changes: 6 additions & 4 deletions packages/liquid-html-parser/src/stage-1-cst.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,12 @@ describe('Unit: Stage 1 (CST)', () => {
expectPath(cst, '0.name').to.equal('doc');
expectPath(cst, '0.children.0.type').to.equal('LiquidDocExampleNode');
expectPath(cst, '0.children.0.exampleContent.value').to.equal('');
expectPath(cst, '0.children.0.locStart').to.equal(testStr.indexOf('@example'));
expectPath(cst, '0.children.0.locEnd').to.equal(
testStr.indexOf('@example') + '@example'.length,
);
});

it('should parse example tag with content that has leading whitespace', () => {
const testStr = `{% doc %} @example hello there {%- enddoc %}`;
cst = toCST(testStr);
expectPath(cst, '0.children.0.exampleContent.value').to.equal('hello there');
});

it('should parse an example tag with a value', () => {
Expand Down
12 changes: 2 additions & 10 deletions packages/liquid-html-parser/src/stage-1-cst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,17 +1359,9 @@ function toLiquidDocAST(source: string, matchingSource: string, offset: number)
locStart,
locEnd,
source,
exampleContent: function (nodes: Node[]) {
const contentNode = nodes[1];
return {
type: ConcreteNodeTypes.TextNode,
value: contentNode.sourceString,
source,
locStart: offset + contentNode.source.startIdx,
locEnd: offset + contentNode.source.endIdx,
};
},
exampleContent: 2,
},
exampleContent: textNode,
fallbackNode: textNode,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ It should normalize the param description
{% doc %}
@param paramName - param with description
{% enddoc %}

It should push example content to the next line
{% doc %}
@example
This is a valid example
{% enddoc %}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ It should normalize the param description
{% doc %}
@param paramName - param with description
{% enddoc %}

It should push example content to the next line
{% doc %}
@example This is a valid example
{% enddoc %}

0 comments on commit 2b3cdd9

Please sign in to comment.