Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

YAML importer for Mathematica.

Installation

This snippet will install the converter in the $BaseDirectory. (You may also use $UserBaseDirectory instead.) After installation, the format will be available like any other importer.

tmp = URLSave["https://github.com/zbjornson/MYaml/archive/master.zip"];
dest = FileNameJoin[{$BaseDirectory, "SystemFiles", "Formats"}];
Quiet[CreateDirectory[dest]];
tmpExpanded = CreateDirectory[];
ExtractArchive[tmp, tmpExpanded];
CopyDirectory[FileNameJoin[{tmpExpanded, "MYaml-master", "YAML"}], FileNameJoin[{dest, "YAML"}]];
DeleteFile[tmp];
DeleteDirectory[tmpExpanded, DeleteContents -> True];
Print["Installed YAML importer to " <> dest <> ". Please restart Mathematica or the kernel."]

Usage

Note that the format must be specified when calling Import (note).

Import["filename.yaml", "YAML"]

YAML Spec Compliance

This library is a thin binding to SnakeYAML, which is a complete YAML 1.1 processor.

  • All language-independent types are supported.
  • Only single documents are supported; multiple documents separated by "---" are not supported.
  • Recursive references are not supported; these will currently cause a stack overflow.
  • Mathematica does not have distinct types corresponding to all of the YAML collection types (unordered vs. ordered maps, allowing vs. disallowing duplicates; sets vs. plain lists). All of the collections are imported as Lists, and (planned) all Lists are exported as !!seq (sequences).

Developer Notes

The YAML directory is what gets copied to $[User]BaseDirectory/SystemFiles/Formats. All other files and folders are only needed for testing and building from source. After building, generate the yaml.jar file using mbuild.jardesc.

Extension Detection

I can't quite get Mathematica to automatically import "*.yaml" files as YAML. You could put the following code in an init.m file; it does not seem to load properly when placed in the importer source code.

Unprotect[Import];
Import[name_String, opts___?OptionQ] :=
  Import[name, "YAML", opts] /;
   ToLowerCase[FileExtension[name]] === "yaml";
Protect[Import];

About

YAML importer for Wolfram Mathematica

Topics

Resources

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.