guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guile Haunt configuration with little markdown parser


From: Amirouche Boubekki
Subject: Re: Guile Haunt configuration with little markdown parser
Date: Fri, 09 Oct 2015 11:36:31 +0200
User-agent: Roundcube Webmail/1.1.2

Le 2015-10-09 02:41, David Thompson a écrit :
Amirouche Boubekki <address@hidden> writes:

Héllo,

I pleased to share with you the haunt [1] configuration I use for my
english only blog [2]. It includes an implementation of little markdown parser powered by a parser combinator. Everything is in the file, so you
should just drop the haunt.scm file somewhere and run it with haunt.

This is really cool!  I'm happy that you are giving Haunt a shot.  It
would be really cool if we could scrape together a decent enough
Markdown parser for all Guilers to use.

What decent enough means?

I tried to port my markdown parser to your library but parse-combinator is missing something. If we define parse-inline as follow:

(define (parse-inline
  (parse-any link bold italic code parse-any-char))

Here i use parse-any-char because otherwise one need to check for control chars like star *, quote ` or bracket [, see how it's done in my parser. I assume that the result can be reconstructed inside a `parse-inline-text` using `parse-map`

Anyway way, this is not the only problem. Now let's try to define `bold` which is the same problem as the others because it boils down to define a parser that can parse closing tags. The perfect solution would be to use something like:

(define (enclosed parser)
  (parse-each parser (parse-one-or-more parse-any-char) parser))

Or better allow to nest inline:

(define (enclosed parser)
  (parse-each parser (parse-one-or-more inline) parser))

But this doesn't work, it consume all the stream and fails at `parse-any-char`, maybe it's possible to backtrack inside parse-each?

FWIW, this is how I parse enclosed tags:

(define (enclosed parser)
  (parse-each parser (parse-one-or-more (parse-not parser)) parser))

parser-combinator has no `parse-not` parser. if `parse-maybe` was taking a procedure instead of single value, `parse-not` could be defined in terms of this `parse-maybe*` as:

(define (parse-not parser)
   (parse-maybe* parser parse-any-char))

Which imo makes sens, since current parse-maybe could be implemented in terms of parse-maybe* and parse-return:

(define* (parse-maybe parser #:optional (default #f))
  (parse-maybe* parser (parse-return default))

But this is hack-ish, i think the best thing would be to be able to build recursive parsers.

Maybe I miss something.

WDYT?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]