You might want to use 0!:0 instead of ". in some cases. 0!:0 handles newlines gracefully, but has a result of i.0 0
This suggests that you might simplify your markup - if an eval string contains a newline, use ,0!:0 otherwise use ". (This means you would only need one pair of delimiters). You might also want to think about error handling. Especially if you are thinking of putting this in a public-facing web server. (J interpreter needs battle hardening before it would be suited in that role. If nothing else: it should compile without error or warning on OpenBSD and succeed on all the acceptance tests -- everything in https://github.com/openj/core/tree/master/test except the ones ending in t.ijs.) Thanks, -- Raul On Tue, Jun 24, 2014 at 5:42 PM, Joe Bogner <[email protected]> wrote: > I was browsing http://www.jsoftware.com/jwiki/Literate and became > motivated > to start working on a basic implementation of the Workbook concept > > The terseness of J is a good fit for an embedded language in a larger text > document or report (along the lines of ipython notebook) or rmarkdown. > > I envision a web page that allows a document to be rendered that includes a > markup like: > > {{{ > NB. commands to set up the document > load 'data.ijs' > loadData'' > }}} > # Summary > There are {{ # Customers }} customers and {{ # Orders }} orders. The most > recent order was {{ {. Order }} > > # Top Customers > {{ renderTable 10 { Customers }} > > Here is the start of my implementation. I welcome any feedback on it. > > require 'regex' > PATTERN =. '\{\{.*?\}\}' > SUBPATTERN =. '\{\{(.*?)\}\}' > parse =. 3 : 0 > matches =. PATTERN rxmatches y > ret =. matches rxcut y > ( 0 ~: > # each ret ) # ret > ) > eval =. 3 : 0 > m=.SUBPATTERN rxmatches y > if. 0 = # m do. > y > else. > ret =. {. ": ". > 1{"1 ( m rxfrom y) > end. > ) > > template =: 3 : 0 > ret=. eval each parse y > ; ( 0 ~: > # each ret ) # ret > ) > > tests=: 3 : 0 > assert. '1+1 is 2' -: template '1+1 is {{1+1}}' > assert. 'hello joe' -: template 'hello {{''''[a=:''joe''}}{{a}}' > a=:i.10 > assert. 'the first number is 0' -: template 'the first number is {{{. a}}' > assert. 'the tail number is 9' -: template 'the tail number is {{{: a}}' > people=: 'bob';'frank' > tmpl=:template 'the people are {{}: }: ; (],&'', '') each ''Mr. ''&, each > people }}' > assert. 'the people are Mr. bob, Mr. frank' -: tmpl > ) > tests'' > > > After more searching, it has some overlap with JHP ( > > http://www.jsoftware.com/wsvn/addons/trunk/web/jhp/?#a76117735fae0ef49b3a78a3c9520a2c9 > ). > My template implementation might be more straightforward to use > standalone. In any event, more choices the better. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
