judepayne / dictim

a two-way d2 transpiler, written in Clojure
MIT License
12 stars 2 forks source link

Can't parse commented out attrs #8

Closed judepayne closed 1 month ago

judepayne commented 2 months ago

This d2:

scorer.t <- item.t1: rubric {
  #style.stroke-dash: 5
}

cannot be parsed (and throws an error).

When the '#' characters is removed, it can be parsed.

attrs should be allowed to be commented out since this is valid d2

judepayne commented 2 months ago

This will require changes to both the d2 compiler and parser. The dot compiler is a TBD.

dictim represents comments as vectors:

[:comment "I am a comment"]

This could be represented in dictim (in an atto-map) as:

  1. {:comment {:attr-that-is-commented-out val}, attr val ...}

  2. {[:comment :attr-that-is-commented-out] val, attr val ...}

Perhaps some other ways.

Need to that about the most natural representation, before committing to adding this since this is a minor use case

judepayne commented 2 months ago

Decided to add this to dictim using notation no. 1 above

judepayne commented 2 months ago

@krish777 complete See 5724d82 & a85e883 commits. Note that even though attrs may be commented out, they are still validated both during compilation and parsing. This is because attrs in dictim syntax live in a clojure map, which must have keys and values - so no freeform text allowed. i.e. it's a data format whereas d2 is a text format

judepayne commented 2 months ago

@krish777 please review this. Not sure this is the right approach. Maybe it's better to parse commented out attrs as

{:comment "style.italic: true"}

i.e. just treat them as strings

krish777 commented 2 months ago

@eddielao Per our discussion, Can you please test this one?

judepayne commented 1 month ago

Closing