|If there is one feature I love in ruby whose absence I despise in java, it's string interpolation. The happy outcome of a complete rewrite of parser.arc is string interpolation for arc, as well as a mostly-complete implementation of 'read in arc. And it doesn't use 'ccc any more!|
Here's a brief demo:
(map [load "libs/#(_)"] (dir "libs"))
I know arc defines the prf macro which does much the same thing, but there are some imho slight deficiencies:
arc> (load "lib/parser.arc")
arc> (si-repl) ; opens a repl that uses 'parse from parser.arc to read expressions from the prompt
enjoy interpolating. type x! to return to the usual repl
arc$ (set world "you")
arc$ "hello, #(world)"
arc$ (set fallen 3)
arc$ "there are #((- 10 fallen)) green bottles on the wall"
"there are 7 green bottles on the wall"
# I want string interpolation to be the universal default; I don't want to have to tell arc which strings to interpolate.
# I can write (prf "foo is #x") to get "foo is 3.14", but not (prf "foo is #x/10") to get "foo is 3.14/10". (Undefined symbol: x/10)
# Nested strings are impossible - the reader can't tell that the quote delimiters of the nested string are not delimiting the outer string.
parser.arc lives on anarki on github at lib/parser.arc. Its reader simply expands
"hello, #(world), you have #((+ 1 2 3)) points"
so interpolations have full access to their lexical context. You can escape interpolations:
(string "hello, " world ", you have " (+ 1 2 3) " points")
but careful, arc's native parser gets upset when it encounters "\#".
arc$ "hello, \#(world)"
parser.arc defines arc-tokeniser, parse, and si-repl. You can
foo.arc and other subsequently loaded code can enjoy string interpolations. There are parser tests under lib/tests/parser-tests.arc (also on anarki). There are some constructs it doesn't support - notably scheme stuff (#f, #x3cf9), ad multi-line comments (for another day), and probably some others. Welder (the arc arc editor), although it is still horribly slow, supports proper syntax highlighting and paren matching for interpolations.
arc> (set read parse)
arc> (load "foo.arc")
I would love to enhance parser.arc so it is easy to extend the grammar - for example to support CatDancer's inline table syntax. It's not difficult to change parser.arc to do that, but it would be great to supply tokeniser/parser hooks instead. Any ideas?
Interpolations are also supported by rainbow's reader. This was perhaps a mistake, as it involved a big fight with javacc and regular expressions, and rainbow's builtin parser is good enough to bootstrap and load parser.arc. Unless my regexps are all wrong, it was pretty amazing how much easier it was to describe the tokeniser as a recursive state-machine in arc.