Arc Forumnew | comments | leaders | submitlogin
String madness?
1 point by wfarr 5878 days ago | 5 comments
I'm currently using Markdown.pl to do some parsing of Markdown for me in an Arc app (because Arc's Markdown parsing doesn't have things like headings, or lists, etc), and I'm seeing some weird behavior with some strings.

  (defopl newpost req
     (let user (get-user req)
       (blogpage (+ blogtitle* " : New Post!")
         (if (admin user)
           (aform (fn (req)
                    (let user (get-user req)
                      (post-page user
                        (addpost user (arg req "title") (md-pl (arg req "content"))))))
                (divid "new"
                  (label-input 'text "title" "Title")
                  (label-ta    "content" "Content")
                  (submit))) (pr admin-warn*)))))
  
  (def md-pl (text)
    (w/stdout (outfile "mdtmp") (pr text))
    (system "perl Markdown.pl --html4tags mdtmp"))
So, what happens is if I pass md-pl something like this:

  *Foo*
  
  Bar
  
  **Baz**
It properly returns:

  <p><i>Foo</i></p>
  
  <p>Bar</p>
  
  <p><b>Baz</b></p>
The problem being that when I use the aform from defopl newpost, the result is like [so](http://picpaste.com/pics/Screenshot-4.1205635488.png). Basically, the HTML is being printed out at one point (hence the stuff at the top), but nothing is stored in the actual text field. Examining the hash table for the post shows that there's not even a "text" key, nor value.

Any ideas? Nex3 and I worked away on this one for a while, and I'm personally rather confused about this oddity.



4 points by almkglor 5878 days ago | link

The return value of 'system is always nil I think.

I'm not sure if wrapping it in a (tostring ...) form will work

Edit: It does:

  arc> (system "echo foo")
  foo
  nil
  arc> (tostring (system "echo foo"))
  "foo\n"

-----

3 points by almkglor 5878 days ago | link

Probably better formatted this way:

  (tostring:system "perl whatever")

-----

1 point by wfarr 5878 days ago | link

That did it. Thanks greatly!

-----

2 points by almkglor 5878 days ago | link

Welcome, I'm glad you actually bothered to put me up in your blog ^^

That said it would probably be a good project to build some sort of decent parsing in Arc. It might be good to use raymyer's parser combinator library, which although intended to work on lists will probably also work on string scanners. That said while I have a general knowledge of parser combinators I haven't actually used them (although I did write a value-change-dump (.vcd) file parser which I suspect used parser combinator concepts before I even learned about parser combinators - it was plenty slow though).

The other concern is the real problem of namespace pollution, raymyers' code uses some very short names - alt, lit. Fortunately they're not macros; raymyers specifically introduced optional laziness via delay-parser in order to reduce macro namespace collision.

-----

1 point by wfarr 5878 days ago | link

I'd be more than glad to help in what (little) ways I can to get Arc's string libraries up to par so that Markdown could be truly reimplemented in it.

-----