Re: YAML parser?
On Tue, Mar 24, 2020 at 6:04 PM Matt Wette 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
Re: YAML parser?
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
Re: YAML parser?
On Wed, Mar 4, 2020 at 6:22 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. > Thanks! I'll take a look. Aleix
Re: YAML parser?
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
Re: YAML parser?
On Fri, Feb 21, 2020 at 11:13 PM Aleix Conchillo Flaqué 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
Re: YAML parser?
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_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
Re: YAML parser?
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_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 ---