Skip to content

Commit f4fcb76

Browse files
blog: add sections
1 parent 6678527 commit f4fcb76

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

website/blog/yaml-vs-dsl.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,23 @@ The original argument is quoted as follows:
3232
3333
## Direct rebuttal to the argument
3434

35+
### Abstraction does not necessitate DSL
36+
3537
> effectively built a DSL inside YAML
3638
3739
This is a misunderstanding of DSL and abstraction. To model Abstract Syntax Tree (AST) manipulation, you will have to have some form of concepts, such as pattern, metavariable, etc. This is true for both DSL and YAML. You cannot cut more concepts out of the tool even if you have [Occam's razor](https://en.wikipedia.org/wiki/Occam%27s_razor).
3840

3941
ast-grep does support pattern. It is a concept to match a strcture that contains multiple AST nodes, which makes it easier to write a rule. You can use `kind`/`has`/`all` to simulate pattern matching. But it does not mean that ast-grep should cut the concept of pattern since it looks like a DSL. In fact, ast-grep's pattern is just one of its [atomic rules](/guide/rule-config/atomic-rule.html). It does not meant to be a special embedded DSL.
4042

43+
### Pattern has its limitations
44+
4145
> your documentation, where you have to extensively explain how pattern syntax works, how pattern syntax works, how metavariables work
4246
4347
As stated before, pattern makes ast-grep users' life easier. Explaining how pattern works is necessary to help users understand how to write rules. This is not a sign of a DSL being necessary, but rather a sign of the limitation of pattern: it is not general enough to cover all cases, and you have to communicate to your users how pattern works in your system. For example, see this [tweet](https://x.com/hd_nvim/status/1941876968363798766) about how to write a pattern to match `function` declation in JavaScript. Another brain teaser, how to tell if `$a = $b` is an `assignment_expression` or `field_initializer`?
4448

4549
(an [ad-hominen](https://en.wikipedia.org/wiki/Ad_hominem) note: it is ironic to see this argument from a tool without proper documentation. I cannot suspend my suspect whether the author has used pattern to write non-trivial rules at all.)
4650

51+
### Slippery slope fallacy
4752

4853
> if you're creating a DSL anyway, you're better off doing it properly than to go halfway
4954
@@ -52,6 +57,8 @@ This argument is a [slippery slope fallacy](https://en.wikipedia.org/wiki/Slippe
5257
Using one concept in your library, framework or tool does not imply that you have to design a whole new syntax for it. The similar comparison will be frontend frameworks. Some frameworks like React and Vue use [hook](https://react.dev/reference/react/hooks) or [signals](https://dev.to/this-is-learning/the-evolution-of-signals-in-javascript-8ob) to represent state changes. But using these building blocks does not grant the verdict to design a new language for your frontend framework. Even the most avant-garde company only introduces [new syntax](https://flow.org/en/docs/react/hook-syntax/) in JavaScript, not inventing a new language.
5358

5459

60+
### Subjective opinion is not objective fact
61+
5562
> I think GritQL queries are significantly easier to read than ast-grep's mix of DSL of YAML.
5663
5764
This is a subjective opinion, instead of an fundamental blocker. The author failed to capture the difference between _"pattern syntax"_ and _"rule system"_. ast-grep's rule system is YAML based, so it is easier to write a [well-formed](https://en.wikipedia.org/wiki/Well-formedness) rule. Instead, DSL based rule system using their own syntax and can be more difficult to write a valid rule, especially for beginners.

0 commit comments

Comments
 (0)