A Racket implementation of RFC 9402 Concat Notation.
Concat Notation is a text-based language for describing pictures and videos featuring cats, containers, and their interactions. This project implements complete syntax parsing and ASCII art rendering.
$ raco pkg install https://github.com/13m0n4de/concat-notation.git
REPL:
$ concat-notation
Concat Notation (RFC 9402) REPL
Enter expressions (Ctrl+D to exit)
concat> cat
|\ _,,,---,,__
/,`.-'`' -. ;--;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_)
Command-line evaluation:
$ concat-notation -e "[cat]"
[ |\ _,,,---,,__ ]
[ /,`.-'`' -. ;--;;,_ ]
[ |,4- ) )-,_..;\ ( `'-']
['---''(_/--' `-'\_) ]
Run a file:
$ concat-notation examples/adjacent.concat
|\ _,,,---,,__ |\ _,,,---,,__ __
/,`.-'`' -. ;--;;,_ /,`.-'`' -. ;--;;,_ .'..`.
|,4- ) )-,_..;\ ( `'-' |,4- ) )-,_..;\ ( `'-' |"'.';
'---''(_/--' `-'\_) '---''(_/--' `-'\_) `--`~
Debug mode:
$ concat-notation -d -e "cat + @"
AST:
'(sequence
(position
(adjacent
(adjacent (over (multiple (concat (subject "cat")))))
"+"
(over (multiple (concat (subject (yarn-ball "@"))))))))
OUTPUT:
|\ _,,,---,,__ __
/,`.-'`' -. ;--;;,_ .'..`.
|,4- ) )-,_..;\ ( `'-' |"'.';
'---''(_/--' `-'\_) `--`~
| Syntax | Description | Example |
|---|---|---|
cat |
Complete cat | cat |
c, a, t |
Cat parts (head, body, tail) | c[a]t, c + a + t |
catN |
Cat with subscript (N is a number) | cat1 + cat2 => cat2 + cat1 |
@ |
Yarn ball | cat + @ |
[], (), {}, <> |
Containers | [cat], <cat> |
+ |
Adjacent (horizontal composition) | cat + cat |
/ |
Over (vertical stacking) | cat / cat |
=> |
Sequence (temporal progression, change) | cat => @ |
N*expr, Nexpr |
Horizontal repetition N times | 3*cat, 3cat |
N/expr |
Vertical repetition N times | 2/cat |
This project uses a BNF grammar (grammar.rkt) that is functionally equivalent to the ABNF grammar in RFC 9402.
sequence : position
| position "=>" sequence
position : adjacent
adjacent : over
| adjacent "+" over
over : multiple
| multiple "/" position
multiple : concat
| NUMBER ["*"] multiple
| NUMBER "/" multiple
concat : subject [NUMBER]
| [partial-cat] container [partial-cat]
container : LSQUARE opt-pos RSQUARE
| LPAREN opt-pos RPAREN
| LCURLY opt-pos RCURLY
| LANGLE opt-pos RANGLE
opt-pos : [position]
subject : CAT
| partial-cat
| yarn-ball
| text
partial-cat: PARTIAL
yarn-ball : "@"
text: ALPHA+
$ concat-notation -e "c[a]t"
|\ [ _,,,---,,_]_
/,`.[-'`' -. ;-]-;;,_
|,4- [ ) )-,_..;\ ( ] `'-'
'---''[(_/--' `-'\_)]
$ concat-notation -e "c[ c[cat]t / c[@]t ]"
|\ [ |\ [ |\ _,,,---,,__ ]_ ]
/,`.[ /,`.[ /,`.-'`' -. ;--;;,_ ]-;;,_ ]
|,4- [ |,4- [ |,4- ) )-,_..;\ ( `'-'] `'-']
'---''['---''['---''(_/--' `-'\_) ] ]
[ ]
[ |\ [ __ ]_ ]
[ /,`.[.'..`.]-;;,_ ]
[ |,4- [|"'.';] `'-' ]
['---''[ `--`~] ]
$ concat-notation -e "@/cat1 + @/cat2 => cat2/@ + cat1/@"
__ __ |\ _,,,---,,__ 2 |\ _,,,---,,__ 1
.'..`. .'..`. /,`.-'`' -. ;--;;,_ /,`.-'`' -. ;--;;,_
|"'.'; |"'.'; |,4- ) )-,_..;\ ( `'-' |,4- ) )-,_..;\ ( `'-'
`--`~ `--`~ '---''(_/--' `-'\_) '---''(_/--' `-'\_)
=>
|\ _,,,---,,__ 1 |\ _,,,---,,__ 2 __ __
/,`.-'`' -. ;--;;,_ /,`.-'`' -. ;--;;,_ .'..`. .'..`.
|,4- ) )-,_..;\ ( `'-' |,4- ) )-,_..;\ ( `'-' |"'.'; |"'.';
'---''(_/--' `-'\_) '---''(_/--' `-'\_) `--`~ `--`~
For more examples, see examples.