๐ง How to Read Gradient Pattern DSL โ
Gradient Pattern DSL may look complex at first, but it follows a small set of consistent rules. This section teaches you how to read any pattern step by step.
๐ Start from the boundaries โ
Every pattern always has:
^ ... .Read it as:
Start of pattern
...
End of pattern๐ง Example: Basic repeating pattern โ
Pattern โ
^[color-stop,~color-stop].๐ Step 1 - boundaries โ
^ - Begin pattern
. - End of patternSo we know:
everything between
^and.is the rule we need to read
๐ Step 2 - look inside โ
[color-stop,~color-stop]This is a sequence ([]), which means:
do this, then this๐ Step 3 - first element โ
color-stopThis means:
the pattern must start with a color-stop
๐ Step 4 - second element โ
~color-stopThe ~ operator means:
repeat zero or more timesSo:
~color-stopmeans:
zero or more additional color-stops
๐ Step 5 - combine everything โ
Now combine both parts:
[color-stop,~color-stop]Becomes:
one color-stop
then any number of additional color-stops๐ Final explanation โ
Start of pattern
Expect:
one color-stop
Then:
zero or more additional color-stops
End of pattern๐ก Intuition โ
You can read this pattern as:
โat least one color-stop, then as many as you wantโ
๐ Try it โ
Open the playground and test:
color-stop
color-stop, color-stop
color-stop, color-stop, color-stopAll of them should be valid.
๐ Understand sequence [] โ
[a,b]Means:
a then bSo:
[color-stop,~color-stop]Becomes:
color-stop, then repeat color-stop N-times๐ Understand repetition ~ โ
~color-stopMeans:
zero or more color-stopSo the full meaning:
at least one color-stop
then any number of additional color-stops๐ Final result โ
^[color-stop,~color-stop].
`^` - Start of pattern
Expect:
at least one `color-stop`
Then:
zero or more additional color-stops
`.` - End of pattern๐ Reading OR conditions โ
Now a more complex pattern:
(config|color-stop)This means:
either config
or color-stop๐ Combining sequence and OR โ
([config,color-stop]|color-stop)Read it as:
Either:
config followed by color-stop
Or:
color-stop๐ Reading nested patterns โ
Example:
^[([config,color-stop]|color-stop),~color-stop].Step-by-step:
Start of pattern
Then:
Either:
config followed by color-stop
Or:
color-stop
Then:
repeat color-stop
End of pattern๐ Color hints โ
[color-hint,color-stop]Means:
a color-hint must always be followed by a color-stop๐ง Mental model โ
Think of DSL as a set of instructions:
Read input from left to right
Match expected tokens
Branch when needed
Repeat when allowed๐ Try it interactively โ
Reading patterns becomes much easier when you see them visually.
๐ Open the playground to explore patterns interactively:
๐ Summary โ
^โ BEGIN.โ END[]โ SEQUENCE()โ GROUPPING|โ OR~โ REPETITION (Array)configโ CONFIG (angle, dimension, position)color-stopโ COLOR STOP (red, gren 10% 20%, blue 50%, rgb(1,2,3))color-hintโ COLOR HINT (10%, 20%, 50%) - offset of the gradient intersection point
Once you understand these, you can read any pattern.
๐ก Tip โ
Start simple:
^color-stop.Then gradually add:
[]
()
|
~