-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6cdda4
commit baee18b
Showing
1 changed file
with
1 addition
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<!doctype html><html lang="en"><head><script async src="https://www.googletagmanager.com/gtag/js?id=G-44C9DS3Q80"></script><script>window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
gtag('config', 'G-44C9DS3Q80');</script><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="canonical" href="https://yamlscript.org/doc/bindings/"><link href="/assets/main.089cde16aad3ee63f22f.css" rel="stylesheet"><link rel="preconnect" href="https://fonts.gstatic.com"><link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans&display=swap" rel="stylesheet"><title>YAMLScript Binding Libraries | YAMLScript</title><link rel="icon" type="“image/x-icon”" href="/images/favicon.ico"><meta property="og:title" content="YAMLScript Binding Libraries"><meta property="og:site_name" content="YAMLScript"><meta property="og:type" content="website"><meta property="og:url" content="https://yamlscript.org/doc/bindings/"><meta name="twitter:card" content="summary_large_image"><meta name="description" content="YAMLScript Binding Libraries Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka..."><meta property="og:description" content="YAMLScript Binding Libraries Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka..."><meta name="description" content="YAMLScript Binding Libraries Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka..."><script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script><script>mermaid.initialize({startOnLoad:true});</script></head><body><div class="layout-wrapper"><header class="header"><div class="header__content"><h1 class="site-title"><a href="/"><img src="/images/yamlscript-logo.svg"></a></h1><nav class="nav"><ul class="nav__list"><li class="nav-item"><a href="/doc">Docs</a></li><li class="nav-item"><a href="/blog">Blog</a></li><li class="nav-item"><a href="/about">About</a></li></ul></nav></div></header><main class="main"><article class="post"><header class="post__header"><h1>YAMLScript Binding Libraries</h1></header><main class="post__content"><p>Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka module or package) these files can be loaded into objects just like a YAML loader would do.</p><p>Without a <code>!yamlscript/v0</code> tag at the top they will load the same as normal. With that tag, they can be made to take advantage of any of YAMLScript's vast functional capabilities.</p><p>YAMLScript intends to provide a loader library for every programming language that uses YAML.</p><p>Currently there are working libraries for: <a href="https://clojars.org/org.yamlscript/clj-yamlscript">Clojure</a>, <a href="https://github.com/yaml/yamlscript-go">Go</a>, <a href="https://clojars.org/org.yamlscript/yamlscript">Java</a>, <a href="https://juliahub.com/ui/Packages/General/YAMLScript">Julia</a>, <a href="https://www.npmjs.com/package/@yaml/yamlscript">NodeJS</a>, <a href="https://metacpan.org/dist/YAMLScript/view/lib/YAMLScript.pod">Perl</a>, <a href="https://pypi.org/project/yamlscript/">Python</a>, <a href="https://raku.land/zef:ingy/YAMLScript">Raku</a>, <a href="https://rubygems.org/search?query=yamlscript">Ruby</a> and <a href="https://crates.io/crates/yamlscript">Rust</a>.</p><p>Install these libraries like you would any other library for your language. You must also install the matching version of the <code>libyamlscript.so</code> shared library. See <a href="/doc/install">Installing YAMLScript</a> for more info.</p><p>You can use these libraries like any other YAML loader. Here's an example usage in Python:</p><p>File <code>program.py</code>:</p><pre class="language-python"><code class="language-python"><span class="token keyword">from</span> yamlscript <span class="token keyword">import</span> YAMLScript<br>ys <span class="token operator">=</span> YAMLScript<span class="token punctuation">(</span><span class="token punctuation">)</span><br><span class="token builtin">input</span> <span class="token operator">=</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'file.ys'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span><br>data <span class="token operator">=</span> ys<span class="token punctuation">.</span>load<span class="token punctuation">(</span><span class="token builtin">input</span><span class="token punctuation">)</span><br><span class="token keyword">print</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span></code></pre><p>File <code>file.ys</code>:</p><pre class="language-yaml"><code class="language-yaml"><span class="token tag">!yamlscript/v0/</span><br><br><span class="token key atrule">=></span><span class="token punctuation">:</span> <span class="token comment"># Set values to use in data</span><br> <span class="token key atrule">name =</span><span class="token punctuation">:</span> <span class="token string">"World"</span><br> <span class="token key atrule">other =</span><span class="token punctuation">:</span> load("other.yaml")<br><br>foo<span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token punctuation">-</span><span class="token punctuation">[</span>(6 * 7)<span class="token punctuation">,</span> inc(41)<span class="token punctuation">,</span> 43.<span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">,</span> (3 .. 9)<span class="token punctuation">:</span>sum<span class="token punctuation">]</span><br>bar<span class="token punctuation">:</span><span class="token punctuation">:</span> other.stuff<span class="token punctuation">:</span>shuffle.take(3)<br>baz<span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token string">"Hello, $name!"</span></code></pre><p>File <code>other.yaml</code>:</p><pre class="language-yaml"><code class="language-yaml"><span class="token key atrule">stuff</span><span class="token punctuation">:</span><br><span class="token punctuation">-</span> ark<br><span class="token punctuation">-</span> banana<br><span class="token punctuation">-</span> cat<br><span class="token punctuation">-</span> doll<br><span class="token punctuation">-</span> electron<br><span class="token punctuation">-</span> flan<br><span class="token punctuation">-</span> golf ball</code></pre><p>Run:</p><pre class="language-text"><code class="language-text">$ python prog.py<br>{'foo': [42, 42, 42, 42], 'bar': ['cat', 'flan', 'doll'], 'baz': 'Hello, World!'}</code></pre></main><aside class="post__aside"><nav class="post__pagination"></nav></aside></article></main><footer class="footer"><div class="footer__content"><ul class="hero__social-links"><li><a href="https://github.com/yaml/yamlscript" target="_blank" rel="noopener noreferrer">GitHub</a></li><li><a href="/feed.xml" target="_blank" rel="noopener noreferrer">RSS</a></li></ul><p class="footer__attribution">Powered by <a href="https://www.11ty.dev" target="_blank" rel="noopener">Eleventy</a>. Theme: <a href="https://github.com/yinkakun/eleventy-duo" target="_blank" rel="noopener noreferrer">Eleventy Duo</a>.</p></div></footer></div><script src="/assets/main.31d6cfe0d16ae931b73c.js"></script></body></html> | ||
gtag('config', 'G-44C9DS3Q80');</script><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="canonical" href="https://yamlscript.org/doc/bindings/"><link href="/assets/main.089cde16aad3ee63f22f.css" rel="stylesheet"><link rel="preconnect" href="https://fonts.gstatic.com"><link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans&display=swap" rel="stylesheet"><title>YAMLScript Binding Libraries | YAMLScript</title><link rel="icon" type="“image/x-icon”" href="/images/favicon.ico"><meta property="og:title" content="YAMLScript Binding Libraries"><meta property="og:site_name" content="YAMLScript"><meta property="og:type" content="website"><meta property="og:url" content="https://yamlscript.org/doc/bindings/"><meta name="twitter:card" content="summary_large_image"><meta name="description" content="YAMLScript Binding Libraries Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka..."><meta property="og:description" content="YAMLScript Binding Libraries Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka..."><meta name="description" content="YAMLScript Binding Libraries Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka..."><script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script><script>mermaid.initialize({startOnLoad:true});</script></head><body><div class="layout-wrapper"><header class="header"><div class="header__content"><h1 class="site-title"><a href="/"><img src="/images/yamlscript-logo.svg"></a></h1><nav class="nav"><ul class="nav__list"><li class="nav-item"><a href="/doc">Docs</a></li><li class="nav-item"><a href="/blog">Blog</a></li><li class="nav-item"><a href="/about">About</a></li></ul></nav></div></header><main class="main"><article class="post"><header class="post__header"><h1>YAMLScript Binding Libraries</h1></header><main class="post__content"><p>Your YAML existing YAML files are perfectly valid YAMLScript files! Using a YAMLScript binding library (aka module or package) these files can be loaded into objects just like a YAML loader would do.</p><p>Without a <code>!yamlscript/v0</code> tag at the top they will load the same as normal. With that tag, they can be made to take advantage of any of YAMLScript's vast functional capabilities.</p><p>YAMLScript intends to provide a loader library for every programming language that uses YAML.</p><p>Currently there are working libraries for:</p><ul><li><a href="https://clojars.org/org.yamlscript/clj-yamlscript">Clojure</a></li><li><a href="https://github.com/yaml/yamlscript-go">Go</a></li><li><a href="https://clojars.org/org.yamlscript/yamlscript">Java</a></li><li><a href="https://juliahub.com/ui/Packages/General/YAMLScript">Julia</a></li><li><a href="https://www.npmjs.com/package/@yaml/yamlscript">NodeJS</a></li><li><a href="https://metacpan.org/dist/YAMLScript/view/lib/YAMLScript.pod">Perl</a></li><li><a href="https://pypi.org/project/yamlscript/">Python</a></li><li><a href="https://raku.land/zef:ingy/YAMLScript">Raku</a></li><li><a href="https://rubygems.org/search?query=yamlscript">Ruby</a></li><li><a href="https://crates.io/crates/yamlscript">Rust</a></li></ul><p>Install these libraries like you would any other library for your language. You must also install the matching version of the <code>libyamlscript.so</code> shared library. See <a href="/doc/install">Installing YAMLScript</a> for more info.</p><p>You can use these libraries like any other YAML loader. Here's an example usage in Python:</p><p>File <code>program.py</code>:</p><pre class="language-python"><code class="language-python"><span class="token keyword">from</span> yamlscript <span class="token keyword">import</span> YAMLScript<br>ys <span class="token operator">=</span> YAMLScript<span class="token punctuation">(</span><span class="token punctuation">)</span><br><span class="token builtin">input</span> <span class="token operator">=</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'file.ys'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span><br>data <span class="token operator">=</span> ys<span class="token punctuation">.</span>load<span class="token punctuation">(</span><span class="token builtin">input</span><span class="token punctuation">)</span><br><span class="token keyword">print</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span></code></pre><p>File <code>file.ys</code>:</p><pre class="language-yaml"><code class="language-yaml"><span class="token tag">!yamlscript/v0/</span><br><br><span class="token key atrule">=></span><span class="token punctuation">:</span> <span class="token comment"># Set values to use in data</span><br> <span class="token key atrule">name =</span><span class="token punctuation">:</span> <span class="token string">"World"</span><br> <span class="token key atrule">other =</span><span class="token punctuation">:</span> load("other.yaml")<br><br>foo<span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token punctuation">-</span><span class="token punctuation">[</span>(6 * 7)<span class="token punctuation">,</span> inc(41)<span class="token punctuation">,</span> 43.<span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">,</span> (3 .. 9)<span class="token punctuation">:</span>sum<span class="token punctuation">]</span><br>bar<span class="token punctuation">:</span><span class="token punctuation">:</span> other.stuff<span class="token punctuation">:</span>shuffle.take(3)<br>baz<span class="token punctuation">:</span><span class="token punctuation">:</span> <span class="token string">"Hello, $name!"</span></code></pre><p>File <code>other.yaml</code>:</p><pre class="language-yaml"><code class="language-yaml"><span class="token key atrule">stuff</span><span class="token punctuation">:</span><br><span class="token punctuation">-</span> ark<br><span class="token punctuation">-</span> banana<br><span class="token punctuation">-</span> cat<br><span class="token punctuation">-</span> doll<br><span class="token punctuation">-</span> electron<br><span class="token punctuation">-</span> flan<br><span class="token punctuation">-</span> golf ball</code></pre><p>Run:</p><pre class="language-text"><code class="language-text">$ python prog.py<br>{'foo': [42, 42, 42, 42], 'bar': ['cat', 'flan', 'doll'], 'baz': 'Hello, World!'}</code></pre></main><aside class="post__aside"><nav class="post__pagination"></nav></aside></article></main><footer class="footer"><div class="footer__content"><ul class="hero__social-links"><li><a href="https://github.com/yaml/yamlscript" target="_blank" rel="noopener noreferrer">GitHub</a></li><li><a href="/feed.xml" target="_blank" rel="noopener noreferrer">RSS</a></li></ul><p class="footer__attribution">Powered by <a href="https://www.11ty.dev" target="_blank" rel="noopener">Eleventy</a>. Theme: <a href="https://github.com/yinkakun/eleventy-duo" target="_blank" rel="noopener noreferrer">Eleventy Duo</a>.</p></div></footer></div><script src="/assets/main.31d6cfe0d16ae931b73c.js"></script></body></html> |