https://github.com/zbjornson/myaml
YAML importer for Wolfram Mathematica
https://github.com/zbjornson/myaml
mathematica yaml
Last synced: about 1 year ago
JSON representation
YAML importer for Wolfram Mathematica
- Host: GitHub
- URL: https://github.com/zbjornson/myaml
- Owner: zbjornson
- Created: 2016-10-12T02:58:30.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-10T01:59:32.000Z (over 8 years ago)
- Last Synced: 2025-03-25T02:39:50.532Z (about 1 year ago)
- Topics: mathematica, yaml
- Language: Mathematica
- Size: 235 KB
- Stars: 10
- Watchers: 5
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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.
```Mathematica
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](#extension-detection)).
```Mathematica
Import["filename.yaml", "YAML"]
```
### YAML Spec Compliance
This library is a thin binding to [SnakeYAML](https://bitbucket.org/asomov/snakeyaml),
which is a complete YAML 1.1 processor.
* All [language-independent types](http://www.yaml.org/type/) 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
`List`s, and (planned) all `List`s 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.
```Mathematica
Unprotect[Import];
Import[name_String, opts___?OptionQ] :=
Import[name, "YAML", opts] /;
ToLowerCase[FileExtension[name]] === "yaml";
Protect[Import];
```