Skip to content

Commit 8cd59da

Browse files
committed
parsing graph progress
1 parent d13292e commit 8cd59da

File tree

6 files changed

+558
-152
lines changed

6 files changed

+558
-152
lines changed

exampleVault/Test.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ text: asdasddas
99

1010
`--INPUT[suggester(option([[low]]), option([[medium]]), option([[high]])):frequency]`
1111

12-
```dataviewjs
12+
```_dataviewjs
1313
const setFilter = "" ;
1414
let filter = "Need | "
1515
const pages = await dv.pages()
@@ -28,7 +28,7 @@ console.log(`${filter}${backticks}${codeblock}${list}):needs]${backticks}`);
2828
await dv.paragraph(`${filter}${backticks}${codeblock}${list}):needs]${backticks}`);
2929
```
3030

31-
```dataviewjs
31+
```_dataviewjs
3232
const setFilter = "" ;
3333
let filter = "Need | "
3434
const pages = await dv.pages()
@@ -46,3 +46,7 @@ console.log(`${filter}${backticks}${codeblock}${backticks}`);
4646
4747
await dv.paragraph(`${filter}${backticks}${codeblock}${backticks}`);
4848
```
49+
50+
51+
```meta-bind-parser-test
52+
```

src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { createMarkdownRenderChildWidgetEditorPlugin } from './cm6/Cm6_ViewPlugi
1212
import { MDRCManager } from './MDRCManager';
1313
import { DEFAULT_SETTINGS, MetaBindPluginSettings } from './settings/Settings';
1414
import { IPlugin } from './IPlugin';
15+
import { ParserTestMDRC } from './renderChildren/ParserTestMDRC';
1516

1617
export default class MetaBindPlugin extends Plugin implements IPlugin {
1718
// @ts-ignore defined in `onload`
@@ -84,6 +85,10 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
8485
ctx.addChild(inputField);
8586
});
8687

88+
this.registerMarkdownCodeBlockProcessor('meta-bind-parser-test', (source, el, ctx) => {
89+
ctx.addChild(new ParserTestMDRC(el, RenderChildType.BLOCK, this, ctx.sourcePath, self.crypto.randomUUID(), {}));
90+
});
91+
8792
// this.registerMarkdownCodeBlockProcessor('meta-bind-js', (source, el, ctx) => {
8893
// ctx.addChild(new ScriptMarkdownRenderChild(el, source, ctx, this));
8994
// });

src/parsers/newInputFieldParser/InputFieldParser.ts

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InputFieldArgumentType, InputFieldDeclaration, InputFieldType } from '.
33
import { BindTargetDeclaration } from '../BindTargetParser';
44
import { InputFieldArgumentContainer } from '../../inputFieldArguments/InputFieldArgumentContainer';
55
import { ErrorCollection } from '../../utils/errors/ErrorCollection';
6-
import { TreeLayoutLoop, TreeLayoutOr, ValidationGraph } from './TreeValidator';
6+
import { TL_C_Literal, TL_C_Loop, TL_C_Optional, TL_C_Or, TL_Loop, TL_Or, ValidationGraph } from './TreeValidator';
77
import { IPlugin } from '../../IPlugin';
88
import { AbstractInputFieldArgument } from '../../inputFieldArguments/AbstractInputFieldArgument';
99
import { InputFieldArgumentFactory } from '../../inputFieldArguments/InputFieldArgumentFactory';
@@ -544,7 +544,11 @@ export class DeclarationParser {
544544

545545
private parseDeclaration(): InputFieldDeclaration {
546546
// literal.closure or literal.closure.closure
547-
const layoutValidationGraph = new ValidationGraph([AST_El_Type.LITERAL, new TreeLayoutLoop([AST_El_Type.CLOSURE], 1, 2)]);
547+
const layoutValidationGraph = new ValidationGraph([
548+
new TL_C_Literal(AST_El_Type.LITERAL, InputFieldTokenType.WORD, 'INPUT'),
549+
new TL_C_Loop([new TL_C_Literal(AST_El_Type.CLOSURE, InputFieldTokenType.L_PAREN)], 1, 2),
550+
// AST_El_Type.LITERAL, new TL_Loop([AST_El_Type.CLOSURE], 1, 2)
551+
]);
548552
this.validateNodeAndThrow(this.ast, layoutValidationGraph);
549553

550554
const inputLiteral = this.ast.getChild(0, InputFieldTokenType.WORD) as AST_Literal;
@@ -584,21 +588,40 @@ export class DeclarationParser {
584588
}
585589

586590
private parsePureDeclaration(closure: AST_Closure): void {
591+
// const layoutValidationGraph = new ValidationGraph([
592+
// AST_El_Type.LITERAL, // input field type
593+
// new TL_Or([], [AST_El_Type.CLOSURE]), // optional arguments
594+
// new TL_Or(
595+
// [],
596+
// [
597+
// AST_El_Type.LITERAL, // bind target separator
598+
// new TL_Or(
599+
// [AST_El_Type.LITERAL, AST_El_Type.LITERAL], // file and hashtag
600+
// [] // no file
601+
// ),
602+
// AST_El_Type.LITERAL, // first bind target metadata path part
603+
// new TL_Loop([new TL_Loop([AST_El_Type.LITERAL], 0, -1), new TL_Loop([AST_El_Type.CLOSURE], 0, -1)], 0, -1), // the other bind target metadata path part
604+
// ]
605+
// ),
606+
// ]);
587607
const layoutValidationGraph = new ValidationGraph([
588-
AST_El_Type.LITERAL, // input field type
589-
new TreeLayoutOr([], [AST_El_Type.CLOSURE]), // optional arguments
590-
new TreeLayoutOr(
591-
[],
592-
[
593-
AST_El_Type.LITERAL, // bind target separator
594-
new TreeLayoutOr(
595-
[AST_El_Type.LITERAL, AST_El_Type.LITERAL], // file and hashtag
596-
[] // no file
597-
),
598-
AST_El_Type.LITERAL, // first bind target metadata path part
599-
new TreeLayoutLoop([new TreeLayoutLoop([AST_El_Type.LITERAL], 0, -1), new TreeLayoutLoop([AST_El_Type.CLOSURE], 0, -1)], 0, -1), // the other bind target metadata path part
600-
]
601-
),
608+
new TL_C_Literal(AST_El_Type.LITERAL, InputFieldTokenType.WORD), // input field type
609+
new TL_C_Optional([new TL_C_Literal(AST_El_Type.CLOSURE, InputFieldTokenType.L_PAREN)]), // optional arguments
610+
new TL_C_Optional([
611+
new TL_C_Literal(AST_El_Type.LITERAL, InputFieldTokenType.COLON), // bind target separator
612+
new TL_C_Optional([
613+
new TL_C_Literal(AST_El_Type.LITERAL, InputFieldTokenType.WORD), // file
614+
new TL_C_Literal(AST_El_Type.LITERAL, InputFieldTokenType.HASHTAG), // hashtag
615+
]), // optional file and hashtag
616+
new TL_C_Literal(AST_El_Type.LITERAL), // first bind target metadata path part
617+
new TL_C_Loop(
618+
[
619+
new TL_C_Or([new TL_C_Literal(AST_El_Type.LITERAL)], [new TL_C_Literal(AST_El_Type.CLOSURE)]), // either literal or closure or none, in a loop
620+
],
621+
0,
622+
-1
623+
), // the other bind target metadata path part
624+
]),
602625
]);
603626
this.validateNodeAndThrow(closure, layoutValidationGraph);
604627

0 commit comments

Comments
 (0)