emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] dynamic-modules eae5da9 20/22: yaml module: add `yaml-pars


From: Noah Friedman
Subject: [Emacs-diffs] dynamic-modules eae5da9 20/22: yaml module: add `yaml-parse-string'.
Date: Mon, 8 May 2017 19:46:15 -0400 (EDT)

branch: dynamic-modules
commit eae5da99db78c541ce9f29607d57feeb1cff6049
Author: Aurélien Aptel <address@hidden>
Commit: Ted Zlatanov <address@hidden>

    yaml module: add `yaml-parse-string'.
---
 modules/yaml/yaml.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/modules/yaml/yaml.c b/modules/yaml/yaml.c
index 4096205..6d2647f 100644
--- a/modules/yaml/yaml.c
+++ b/modules/yaml/yaml.c
@@ -56,7 +56,7 @@ parse_element (struct context *ctx)
     case YAML_SCALAR_EVENT:
       res = parse_scalar (ctx, &e);
       if (s)
-          Fputhash (make_string (s, strlen (s)), res, ctx->anchors);
+        Fputhash (make_string (s, strlen (s)), res, ctx->anchors);
       break;
 
     case YAML_SEQUENCE_START_EVENT:
@@ -143,6 +143,25 @@ context_init (struct context *ctx)
   ctx->anchors = Fmake_hash_table (2, args);
 }
 
+EXFUN (Fyaml_parse_string, 1);
+DEFUN ("yaml-parse-string", Fyaml_parse_string, Syaml_parse_string, 1, 1, 0,
+       doc: "Parse STRING as yaml.")
+  (Lisp_Object string)
+{
+  struct context ctx;
+  Lisp_Object res = Qnil;
+
+  context_init (&ctx);
+
+  yaml_parser_initialize (&ctx.p);
+  yaml_parser_set_input_string (&ctx.p, SDATA (string), SBYTES (string));
+  res = parse_element (&ctx);
+  yaml_parser_delete (&ctx.p);
+
+  return res;
+}
+
+
 EXFUN (Fyaml_parse, 0);
 DEFUN ("yaml-parse", Fyaml_parse, Syaml_parse, 0, 0, 0,
        doc: "Parse current buffer as yaml.")
@@ -206,6 +225,7 @@ void init ()
   DEFSYM (Qyaml, "yaml");
 
   defsubr (&Syaml_parse_file);
+  defsubr (&Syaml_parse_string);
   defsubr (&Syaml_parse);
 
   Fprovide (Qyaml, Qnil);



reply via email to

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