terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
16.17k stars 399 forks source link

compiler: overriding substitutions #1721

Open alixander opened 7 months ago

alixander commented 7 months ago

This should've overridden the label set by the substitution. Since the compiler has to compile the current map to get the variables, we compile substitutions only after.

Screen Shot 2023-11-10 at 3 06 23 PM

One simple solution is to do two passes. The first pass to build up the variable stack and the second to make the subs.

alixander commented 6 months ago

nvm, vars has to be reimplemented.

Consider this:

vars: {
  x: {
    label: var-set
  }
}
a: ${x}
a.label: self-set

b.label: self-set
b: ${x}

You just can't know after map compilation whether the substitution came before or after.

We just compile vars in main map compilation. Every time we pop out of a map, we should pop stack of vars.