Next: , Previous: , Up: parsing   [Index]


10.4 Tooling a parser,

It is possible to change the fundamental behavior of the parser and for that function define all the parser combinators and tools needed to effectively generat AST or just parse out information. The tool is in (logic guile-log parser). Use it as

(setup-parser  <p-define> <p-lambda> <fail> <p-cc> <succeds> .. xx 
               X XL ((N 0) (M 0))
               s-false s-true s-mk-seq s-mk-and s-mk-or)

The first row points to the basic parser framework. The second line defines the name of X and XL, that is standard on all parsers. But then rhe second two syntax parameters N,M has also initial values. The last line need also to have been defined before and is usually made by make-guile-log.scanner -tools. As an example this is a basic parser tool for python,

(begin
  (define-guile-log-parser-tool (<p-lambda> (X XL N M INDENT)) <p-define> .. 
    xx <p-cc>)
 
 
  (make-guile-log-scanner-tools <p-lambda> <fail> <p-cc> <succeds> .. 
                              (X XL N M INDENT)
                              (c) (d)
                              s-false s-true s-mk-seq s-mk-and s-mk-or)
 
  ;; Sets up a standar parser functionals with INDENT field added
  (setup-parser
   <p-define> <p-lambda> <fail> <p-cc> <succeds> .. xx
   X XL ((N 0) (M 0) (INDENT (list 0)))
   s-false s-true s-mk-seq s-mk-and s-mk-or))

And then you can create your parser to AST, by simply translating the grammar in the python docs. Happy Parsing!!