@@ -34,6 +34,7 @@ import { Parser } from 'prettier';
34
34
import ohm , { Node } from 'ohm-js' ;
35
35
import { toAST } from 'ohm-js/extras' ;
36
36
import {
37
+ LiquidDocGrammar ,
37
38
LiquidGrammars ,
38
39
TextNodeGrammar ,
39
40
placeholderGrammars ,
@@ -81,7 +82,6 @@ export enum ConcreteNodeTypes {
81
82
RenderMarkup = 'RenderMarkup' ,
82
83
PaginateMarkup = 'PaginateMarkup' ,
83
84
RenderVariableExpression = 'RenderVariableExpression' ,
84
- LiquidDocBody = 'LiquidDocBody' ,
85
85
}
86
86
87
87
export const LiquidLiteralValues = {
@@ -504,13 +504,7 @@ function toCST<T>(
504
504
source : string /* the original file */ ,
505
505
grammars : LiquidGrammars ,
506
506
grammar : ohm . Grammar ,
507
- cstMappings : (
508
- | 'HelperMappings'
509
- | 'LiquidMappings'
510
- | 'LiquidHTMLMappings'
511
- | 'LiquidStatement'
512
- | 'LiquidDocMappings'
513
- ) [ ] ,
507
+ cstMappings : ( 'HelperMappings' | 'LiquidMappings' | 'LiquidHTMLMappings' | 'LiquidStatement' ) [ ] ,
514
508
matchingSource : string = source /* for subtree parsing */ ,
515
509
offset : number = 0 /* for subtree parsing location offsets */ ,
516
510
) : T {
@@ -638,11 +632,8 @@ function toCST<T>(
638
632
body : ( tokens : Node [ ] ) => tokens [ 1 ] . sourceString ,
639
633
children : ( tokens : Node [ ] ) => {
640
634
const contentNode = tokens [ 1 ] ;
641
- return toCST (
635
+ return toLiquidDocAST (
642
636
source ,
643
- grammars ,
644
- grammars . Liquid ,
645
- [ 'LiquidDocMappings' ] ,
646
637
contentNode . sourceString ,
647
638
offset + contentNode . source . startIdx ,
648
639
) ;
@@ -1108,15 +1099,24 @@ function toCST<T>(
1108
1099
} ;
1109
1100
1110
1101
const LiquidDocMappings : Mapping = {
1111
- Node : {
1112
- type : ConcreteNodeTypes . LiquidDocBody ,
1113
- locStart,
1114
- locEnd,
1115
- source,
1116
- description : ( tokens : Node [ ] ) => tokens [ 0 ] . sourceString ,
1117
- } ,
1102
+ Node : 0 ,
1103
+ TextNode : textNode ,
1118
1104
} ;
1119
1105
1106
+ function toLiquidDocAST ( source : string , matchingSource : string , offset : number ) {
1107
+ const res = LiquidDocGrammar . match ( matchingSource , 'Node' ) ;
1108
+ if ( res . failed ( ) ) {
1109
+ throw new LiquidHTMLCSTParsingError ( res ) ;
1110
+ }
1111
+
1112
+ const LiquidDocMappings : Mapping = {
1113
+ Node : 0 ,
1114
+ TextNode : textNode ,
1115
+ } ;
1116
+
1117
+ return toAST ( res , LiquidDocMappings ) ;
1118
+ }
1119
+
1120
1120
const LiquidHTMLMappings : Mapping = {
1121
1121
Node ( frontmatter : Node , nodes : Node ) {
1122
1122
const self = this as any ;
@@ -1272,7 +1272,6 @@ function toCST<T>(
1272
1272
LiquidMappings,
1273
1273
LiquidHTMLMappings,
1274
1274
LiquidStatement,
1275
- LiquidDocMappings,
1276
1275
} ;
1277
1276
1278
1277
const selectedMappings = cstMappings . reduce (
0 commit comments