unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* YAML parser?
@ 2020-02-22  4:12 Aleix Conchillo Flaqué
  2020-02-23 15:29 ` Matt Wette
  2020-02-24 14:48 ` Thompson, David
  0 siblings, 2 replies; 8+ messages in thread
From: Aleix Conchillo Flaqué @ 2020-02-22  4:12 UTC (permalink / raw)
  To: guile-user

Hi,

does anyone know if there's any YAML parser for Guile? Haven't been able to
find any.

Thanks!

Aleix


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: YAML parser?
  2020-02-22  4:12 YAML parser? Aleix Conchillo Flaqué
@ 2020-02-23 15:29 ` Matt Wette
  2020-02-24 14:35   ` Matt Wette
  2020-03-04 14:21   ` Matt Wette
  2020-02-24 14:48 ` Thompson, David
  1 sibling, 2 replies; 8+ messages in thread
From: Matt Wette @ 2020-02-23 15:29 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué, guile-user

On 2/21/20 8:12 PM, Aleix Conchillo Flaqué wrote:
> Hi,
>
> does anyone know if there's any YAML parser for Guile? Haven't been able to
> find any.
>
> Thanks!
>
> Aleix

Hi Aleix,

I don't know of a YAML parser for Guile, but if you look at my email 
posted 2/22 I have
a Guile package called NYACC.  This includes a "FFI Helper" that can 
generate the Guile
FFI code based on yaml.h from libyaml.   The API is going to be C-like 
but if you do some
work to paste something on the front you will have something, I think.

Below I have a demo program and the yaml.ffi file used to generate yaml.scm.
When executed, the demo program outputs the following:

$ guile demo1.scm
#<yaml_node_t* 0x56353bc4af80>
YAML_MAPPING_NODE


The demo program: =====================================
(use-modules ((system foreign) #:prefix ffi:))
(use-modules (bytestructures guile))
(use-modules (system ffi-help-rt))
(use-modules (ffi yaml))

(define (sf fmt . args) (apply simple-format #t fmt args))

(define fopen
   (let ((~fopen (ffi:pointer->procedure
          '* (dynamic-func "fopen" (dynamic-link)) (list '* '*))))
     (lambda (filename mode)
       (~fopen (ffi:string->pointer filename) (ffi:string->pointer mode)))))

(define fclose
   (let ((~fclose (ffi:pointer->procedure
          ffi:int (dynamic-func "fclose" (dynamic-link)) (list '*))))
     (lambda (file)
       (~fclose file))))

(let* ((filename "demo1.yml")
        (parser (make-yaml_parser_t))
        (&parser (pointer-to parser))
        (document (make-yaml_document_t))
        (&document (pointer-to document))
        (file (fopen filename "r"))
        (root #f))
   (yaml_parser_initialize &parser)
   (yaml_parser_set_input_file &parser file)
   (yaml_parser_load &parser &document)
   (set! root (yaml_document_get_root_node &document))
   (sf "~S\n" root)
   (sf "~S\n" (wrap-yaml_node_type_t (fh-object-ref root 'type)))
   (yaml_document_delete &document)
   (yaml_parser_delete &parser)
   (fclose file))

The yaml.ffi file (included in nyacc): =========================
;; yaml.ffi                -*- Scheme -*-

;; Copyright (C) 2020 Matthew R. Wette
;;
;; Copying and distribution of this file, with or without modification,
;; are permitted in any medium without royalty provided the copyright
;; notice and this notice are preserved.  This file is offered as-is,
;; without any warranty.

(define-ffi-module (ffi yaml)
   #:include '("yaml.h")
   #:library '("libyaml"))

;; --- last line ---





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: YAML parser?
  2020-02-23 15:29 ` Matt Wette
@ 2020-02-24 14:35   ` Matt Wette
  2020-03-04 14:21   ` Matt Wette
  1 sibling, 0 replies; 8+ messages in thread
From: Matt Wette @ 2020-02-24 14:35 UTC (permalink / raw)
  To: guile-user



On 2/23/20 7:29 AM, Matt Wette wrote:
> On 2/21/20 8:12 PM, Aleix Conchillo Flaqué wrote:
>> Hi,
>>
>> does anyone know if there's any YAML parser for Guile? Haven't been 
>> able to
>> find any.
>>
>> Thanks!
>>
>> Aleix
>
> Hi Aleix,
>
> I don't know of a YAML parser for Guile, but if you look at my email 
> posted 2/22 I have
> a Guile package called NYACC.  This includes a "FFI Helper" that can 
> generate the Guile
> FFI code based on yaml.h from libyaml.   The API is going to be C-like 
> but if you do some
> work to paste something on the front you will have something, I think.
>
> Below I have a demo program and the yaml.ffi file used to generate 
> yaml.scm.
> When executed, the demo program outputs the following:
>
> $ guile demo1.scm
> #<yaml_node_t* 0x56353bc4af80>
> YAML_MAPPING_NODE
>

I am working on this a bit more.  This requires some second order 
programming
(e.g., pointers used as vectors) so  don't kill yourself.  I'm looking 
into it more.

Matt




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: YAML parser?
  2020-02-22  4:12 YAML parser? Aleix Conchillo Flaqué
  2020-02-23 15:29 ` Matt Wette
@ 2020-02-24 14:48 ` Thompson, David
  1 sibling, 0 replies; 8+ messages in thread
From: Thompson, David @ 2020-02-24 14:48 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué; +Cc: guile-user

On Fri, Feb 21, 2020 at 11:13 PM Aleix Conchillo Flaqué
<aconchillo@gmail.com> wrote:
>
> Hi,
>
> does anyone know if there's any YAML parser for Guile? Haven't been able to
> find any.

None that I know of. I made an attempt to write one years ago, but the
YAML specification is so complex that it didn't feel worth the effort.

- Dave



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: YAML parser?
  2020-02-23 15:29 ` Matt Wette
  2020-02-24 14:35   ` Matt Wette
@ 2020-03-04 14:21   ` Matt Wette
  2020-03-06 19:49     ` Aleix Conchillo Flaqué
  2020-03-25  1:04     ` Matt Wette
  1 sibling, 2 replies; 8+ messages in thread
From: Matt Wette @ 2020-03-04 14:21 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué, guile-user

On 2/23/20 7:29 AM, Matt Wette wrote:
> On 2/21/20 8:12 PM, Aleix Conchillo Flaqué wrote:
>> Hi,
>>
>> does anyone know if there's any YAML parser for Guile? Haven't been 
>> able to
>> find any.
>>
>> Thanks!
>>
>> Aleix
>
> Hi Aleix,
>
> I don't know of a YAML parser for Guile, but if you look at my email 
> posted 2/22 I have
> a Guile package called NYACC.  This includes a "FFI Helper" that can 
> generate the Guile
> FFI code based on yaml.h from libyaml.   The API is going to be C-like 
> but if you do some
> work to paste something on the front you will have something, I think.
>

I have something working for reads.   Check github dot com / mwette / 
guile-libyaml

Download and run "guile demo1.scm".  Compare to demo1.yml.

Matt




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: YAML parser?
  2020-03-04 14:21   ` Matt Wette
@ 2020-03-06 19:49     ` Aleix Conchillo Flaqué
  2020-03-25  1:04     ` Matt Wette
  1 sibling, 0 replies; 8+ messages in thread
From: Aleix Conchillo Flaqué @ 2020-03-06 19:49 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

On Wed, Mar 4, 2020 at 6:22 AM Matt Wette <matt.wette@gmail.com> wrote:

> On 2/23/20 7:29 AM, Matt Wette wrote:
> > On 2/21/20 8:12 PM, Aleix Conchillo Flaqué wrote:
> >> Hi,
> >>
> >> does anyone know if there's any YAML parser for Guile? Haven't been
> >> able to
> >> find any.
> >>
> >> Thanks!
> >>
> >> Aleix
> >
> > Hi Aleix,
> >
> > I don't know of a YAML parser for Guile, but if you look at my email
> > posted 2/22 I have
> > a Guile package called NYACC.  This includes a "FFI Helper" that can
> > generate the Guile
> > FFI code based on yaml.h from libyaml.   The API is going to be C-like
> > but if you do some
> > work to paste something on the front you will have something, I think.
> >
>
> I have something working for reads.   Check github dot com / mwette /
> guile-libyaml
>
> Download and run "guile demo1.scm".  Compare to demo1.yml.
>

Thanks! I'll take a look.

Aleix


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: YAML parser?
  2020-03-04 14:21   ` Matt Wette
  2020-03-06 19:49     ` Aleix Conchillo Flaqué
@ 2020-03-25  1:04     ` Matt Wette
  2020-03-25 23:02       ` Aleix Conchillo Flaqué
  1 sibling, 1 reply; 8+ messages in thread
From: Matt Wette @ 2020-03-25  1:04 UTC (permalink / raw)
  To: guile-user

On 3/4/20 6:21 AM, Matt Wette wrote:
> On 2/23/20 7:29 AM, Matt Wette wrote:
>> On 2/21/20 8:12 PM, Aleix Conchillo Flaqué wrote:
>>> Hi,
>>>
>>> does anyone know if there's any YAML parser for Guile? Haven't been 
>>> able to
>>> find any.
>>>
>>> Thanks!
>>>
>>> Aleix
>>
>> Hi Aleix,
>>
>> I don't know of a YAML parser for Guile, but if you look at my email 
>> posted 2/22 I have
>> a Guile package called NYACC.  This includes a "FFI Helper" that can 
>> generate the Guile
>> FFI code based on yaml.h from libyaml.   The API is going to be 
>> C-like but if you do some
>> work to paste something on the front you will have something, I think.
>>
>
> I have something working for reads.   Check github dot com / mwette / 
> guile-libyaml
>
> Download and run "guile demo1.scm".  Compare to demo1.yml.
>
> Matt
>
>
I have updated this.   I now have a procedure read-yaml-file which will 
read a yaml file and convert to a scheme tree.

Matt

$ GUILE_LOAD_PATH= guile demo1.scm
(("doe" . "a deer, a female deer")
  ("ray" . "a drop of golden sun")
  ("pi" . "3.14159")
  ("xmas" . "true")
  ("french-hens" . "3")
  ("calling-birds"
   .
   #("huey" "dewey" "louie" "fred"))
  ("xmas-fifth-day"
   ("calling-birds" . "four")
   ("french-hens" . "3")
   ("golden-rings" . "5")
   ("partridges"
    ("count" . "1")
    ("location" . "a pear tree"))
   ("turtle-doves" . "two"))


from


$ cat demo1.yml
---
  doe: "a deer, a female deer"
  ray: "a drop of golden sun"
  pi: 3.14159
  xmas: true
  french-hens: 3
  calling-birds:
    - huey
    - dewey
    - louie
    - fred
  xmas-fifth-day:
    calling-birds: four
    french-hens: 3
    golden-rings: 5
    partridges:
      count: 1
      location: "a pear tree"
    turtle-doves: two





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: YAML parser?
  2020-03-25  1:04     ` Matt Wette
@ 2020-03-25 23:02       ` Aleix Conchillo Flaqué
  0 siblings, 0 replies; 8+ messages in thread
From: Aleix Conchillo Flaqué @ 2020-03-25 23:02 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

On Tue, Mar 24, 2020 at 6:04 PM Matt Wette <matt.wette@gmail.com> wrote:

> >
> I have updated this.   I now have a procedure read-yaml-file which will
> read a yaml file and convert to a scheme tree.
>
> Matt
>
> $ GUILE_LOAD_PATH= guile demo1.scm
> (("doe" . "a deer, a female deer")
>   ("ray" . "a drop of golden sun")
>   ("pi" . "3.14159")
>   ("xmas" . "true")
>   ("french-hens" . "3")
>   ("calling-birds"
>    .
>    #("huey" "dewey" "louie" "fred"))
>   ("xmas-fifth-day"
>    ("calling-birds" . "four")
>    ("french-hens" . "3")
>    ("golden-rings" . "5")
>    ("partridges"
>     ("count" . "1")
>     ("location" . "a pear tree"))
>    ("turtle-doves" . "two"))
>
>
> from
>
>
> $ cat demo1.yml
> ---
>   doe: "a deer, a female deer"
>   ray: "a drop of golden sun"
>   pi: 3.14159
>   xmas: true
>   french-hens: 3
>   calling-birds:
>     - huey
>     - dewey
>     - louie
>     - fred
>   xmas-fifth-day:
>     calling-birds: four
>     french-hens: 3
>     golden-rings: 5
>     partridges:
>       count: 1
>       location: "a pear tree"
>     turtle-doves: two
>
>
This is great! Thank you so much.

Aleix


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-03-25 23:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-22  4:12 YAML parser? Aleix Conchillo Flaqué
2020-02-23 15:29 ` Matt Wette
2020-02-24 14:35   ` Matt Wette
2020-03-04 14:21   ` Matt Wette
2020-03-06 19:49     ` Aleix Conchillo Flaqué
2020-03-25  1:04     ` Matt Wette
2020-03-25 23:02       ` Aleix Conchillo Flaqué
2020-02-24 14:48 ` Thompson, David

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).