Skip to content

Commit

Permalink
Example alist Macro
Browse files Browse the repository at this point in the history
  • Loading branch information
iwillspeak committed Jun 22, 2024
1 parent 027bd17 commit 4be1099
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/alist.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(import (scheme write)
(scheme base))
(define-syntax alist
(syntax-rules ()
((_) ())
((_ x y z ...)
(cons (cons x y) (alist z ...)))))
(display (alist 'foo 10 'bar 20 'baz 30))(newline)
4 changes: 4 additions & 0 deletions test/Feersum.Tests/_snapshots/Parse_alist.scm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Diagnostics": [],
"Root": "PROGRAM: (0..206)\n FORM: (0..39)\n OPEN_PAREN: (0..1) \"(\"\n SYMBOL: (1..7)\n IDENTIFIER: (1..7) \"import\"\n ATMOSPHERE: (7..8) \" \"\n FORM: (8..22)\n OPEN_PAREN: (8..9) \"(\"\n SYMBOL: (9..15)\n IDENTIFIER: (9..15) \"scheme\"\n ATMOSPHERE: (15..16) \" \"\n SYMBOL: (16..21)\n IDENTIFIER: (16..21) \"write\"\n CLOSE_PAREN: (21..22) \")\"\n ATMOSPHERE: (22..25) \"\n \"\n FORM: (25..38)\n OPEN_PAREN: (25..26) \"(\"\n SYMBOL: (26..32)\n IDENTIFIER: (26..32) \"scheme\"\n ATMOSPHERE: (32..33) \" \"\n SYMBOL: (33..37)\n IDENTIFIER: (33..37) \"base\"\n CLOSE_PAREN: (37..38) \")\"\n CLOSE_PAREN: (38..39) \")\"\n ATMOSPHERE: (39..40) \"\n\"\n FORM: (40..154)\n OPEN_PAREN: (40..41) \"(\"\n SYMBOL: (41..54)\n IDENTIFIER: (41..54) \"define-syntax\"\n ATMOSPHERE: (54..55) \" \"\n SYMBOL: (55..60)\n IDENTIFIER: (55..60) \"alist\"\n ATMOSPHERE: (60..63) \"\n \"\n FORM: (63..153)\n OPEN_PAREN: (63..64) \"(\"\n SYMBOL: (64..76)\n IDENTIFIER: (64..76) \"syntax-rules\"\n ATMOSPHERE: (76..77) \" \"\n FORM: (77..79)\n OPEN_PAREN: (77..78) \"(\"\n CLOSE_PAREN: (78..79) \")\"\n ATMOSPHERE: (79..85) \"\n \"\n FORM: (85..93)\n OPEN_PAREN: (85..86) \"(\"\n FORM: (86..89)\n OPEN_PAREN: (86..87) \"(\"\n SYMBOL: (87..88)\n IDENTIFIER: (87..88) \"_\"\n CLOSE_PAREN: (88..89) \")\"\n ATMOSPHERE: (89..90) \" \"\n FORM: (90..92)\n OPEN_PAREN: (90..91) \"(\"\n CLOSE_PAREN: (91..92) \")\"\n CLOSE_PAREN: (92..93) \")\"\n ATMOSPHERE: (93..99) \"\n \"\n FORM: (99..152)\n OPEN_PAREN: (99..100) \"(\"\n FORM: (100..113)\n OPEN_PAREN: (100..101) \"(\"\n SYMBOL: (101..102)\n IDENTIFIER: (101..102) \"_\"\n ATMOSPHERE: (102..103) \" \"\n SYMBOL: (103..104)\n IDENTIFIER: (103..104) \"x\"\n ATMOSPHERE: (104..105) \" \"\n SYMBOL: (105..106)\n IDENTIFIER: (105..106) \"y\"\n ATMOSPHERE: (106..107) \" \"\n SYMBOL: (107..108)\n IDENTIFIER: (107..108) \"z\"\n ATMOSPHERE: (108..109) \" \"\n SYMBOL: (109..112)\n IDENTIFIER: (109..112) \"...\"\n CLOSE_PAREN: (112..113) \")\"\n ATMOSPHERE: (113..120) \"\n \"\n FORM: (120..151)\n OPEN_PAREN: (120..121) \"(\"\n SYMBOL: (121..125)\n IDENTIFIER: (121..125) \"cons\"\n ATMOSPHERE: (125..126) \" \"\n FORM: (126..136)\n OPEN_PAREN: (126..127) \"(\"\n SYMBOL: (127..131)\n IDENTIFIER: (127..131) \"cons\"\n ATMOSPHERE: (131..132) \" \"\n SYMBOL: (132..133)\n IDENTIFIER: (132..133) \"x\"\n ATMOSPHERE: (133..134) \" \"\n SYMBOL: (134..135)\n IDENTIFIER: (134..135) \"y\"\n CLOSE_PAREN: (135..136) \")\"\n ATMOSPHERE: (136..137) \" \"\n FORM: (137..150)\n OPEN_PAREN: (137..138) \"(\"\n SYMBOL: (138..143)\n IDENTIFIER: (138..143) \"alist\"\n ATMOSPHERE: (143..144) \" \"\n SYMBOL: (144..145)\n IDENTIFIER: (144..145) \"z\"\n ATMOSPHERE: (145..146) \" \"\n SYMBOL: (146..149)\n IDENTIFIER: (146..149) \"...\"\n CLOSE_PAREN: (149..150) \")\"\n CLOSE_PAREN: (150..151) \")\"\n CLOSE_PAREN: (151..152) \")\"\n CLOSE_PAREN: (152..153) \")\"\n CLOSE_PAREN: (153..154) \")\"\n ATMOSPHERE: (154..155) \"\n\"\n FORM: (155..196)\n OPEN_PAREN: (155..156) \"(\"\n SYMBOL: (156..163)\n IDENTIFIER: (156..163) \"display\"\n ATMOSPHERE: (163..164) \" \"\n FORM: (164..195)\n OPEN_PAREN: (164..165) \"(\"\n SYMBOL: (165..170)\n IDENTIFIER: (165..170) \"alist\"\n ATMOSPHERE: (170..171) \" \"\n QUOTED_DATUM: (171..176)\n QUOTE: (171..172) \"'\"\n SYMBOL: (172..175)\n IDENTIFIER: (172..175) \"foo\"\n ATMOSPHERE: (175..176) \" \"\n CONSTANT: (176..178)\n NUMBER: (176..178) \"10\"\n ATMOSPHERE: (178..179) \" \"\n QUOTED_DATUM: (179..184)\n QUOTE: (179..180) \"'\"\n SYMBOL: (180..183)\n IDENTIFIER: (180..183) \"bar\"\n ATMOSPHERE: (183..184) \" \"\n CONSTANT: (184..186)\n NUMBER: (184..186) \"20\"\n ATMOSPHERE: (186..187) \" \"\n QUOTED_DATUM: (187..192)\n QUOTE: (187..188) \"'\"\n SYMBOL: (188..191)\n IDENTIFIER: (188..191) \"baz\"\n ATMOSPHERE: (191..192) \" \"\n CONSTANT: (192..194)\n NUMBER: (192..194) \"30\"\n CLOSE_PAREN: (194..195) \")\"\n CLOSE_PAREN: (195..196) \")\"\n FORM: (196..205)\n OPEN_PAREN: (196..197) \"(\"\n SYMBOL: (197..204)\n IDENTIFIER: (197..204) \"newline\"\n CLOSE_PAREN: (204..205) \")\"\n ATMOSPHERE: (205..206) \"\n\"\n EOF: (206..206) \"\"\n"
}
Original file line number Diff line number Diff line change
Expand Up @@ -821,5 +821,10 @@
"Output": "<<{}>>\nfoo\nfoo:bar:baz\n",
"Error": "",
"Exit": 0
},
"alist.scm": {
"Output": "((foo . 10) (bar . 20) (baz . 30))\n",
"Error": "",
"Exit": 0
}
}

0 comments on commit 4be1099

Please sign in to comment.