What can make this dsl easier to type or read?

I wrote a working grammar to replace dbunit in scala called ScalaDBTest. The whole program works - just 2 days to write. I have a lot of polishing.

In any case, the grammar that I use for DSL to enter data into the database is malleable, and I would like some feedback from it.

The basic syntax looks like this. It is pretty simple:

country:
- country_id: 1, name: "Canada"
- country_id: 2, name: "United States"

This is certainly better than XML or SQL insert statements.

I discussed the use of ":" or "=". The former looks better, but the latter seems automatic to me.

There is also a concept in which you can β€œlabel” a record. In a sense, the above syntax was anonymous. Shortcuts will be an interesting feature because you can use them in various ways.

country:
    record: Canada -> country_id: 1, name: $label # produces "Canada"
    record: UnitedStates -> country_id: 2, name: $label.uncamel # produces "United States"

I do not like this syntax. These are a few two words. Using "-" does not look right, but if I use the actual command word, for example, "record", I need to put "->" to separate them, otherwise it looks very bad (this is not necessary for technical reasons).

$ label will simply repeat the label, so you can use the label at the minimum minimum to reuse the string. $ label.uncamel will add spaces where it looks like a camel case.

- API- . , , "", "", .

, :

province:
? country_id: 1, nice_weather: true
- province_id: 1, name: "British Columbia"
- province_id: 2, name: "Manitoba", nice_weather: false
- province_id: 3, name: "New York", country_id: 2

- . 3- 4 . 2 , . -. / .

, , , . .

:

article:
? date_create: $now
- article_id: 1, title: "The Fed Sucks"
- article_id: 2, title: null

, - , , dbUnit. DbUnit , (, "[NULL]" ) .

, , . , $now sql- /. , .

, , . - , , , .

+3
4

:

  • / . : [label: name]
    - country_id: 1, : ""
    - country_id: 2, : " "
  • / , . : [: 2]
    - country_id: 1, : ""
    - country_id: 2, : " "

  • :
    - [: 2] _: 1, : ""
    - [label: name] country_id: 2, : "United States"

, , .

, , concurrency , , 5K 5 :

: [label: name] [concurrency: 5]
- [: 2] _: 1, : ""
- [label: name] country_id: 2, : "United States"

+1

Scala DSL. , , - case, , .

+1

, , IMHO - , . XML, JSON HAML? , , .

+1

YAML, . YAML , :

country:
  - country_id: 1
    name: Canada
  - country_id: 2
    name: United States

# country
---
country_id: 1
name: Canada
---
country_id: 2
name: United States
+1

Source: https://habr.com/ru/post/1770438/


All Articles