Giter VIP home page Giter VIP logo

lua-yaml's Introduction

YAML

LUA YAML parser, based on js-lua , fast and tiny. Although this implementation does not currently support the entire YAML specification, feel free to fork the project and submit a patch :)

Usage

require('yaml').eval(string_of_yaml)

Currently Supports

  • Comments
  • Sequences (arrays)
  • Maps (hashes)
  • Inline sequences
  • Inline maps
  • Nesting
  • Primitive scalars (integers, floats, booleans, etc)
  • Extended bools (enabled, disabled, yes, no, on, off, true, false)

Installation

$ luarocks install lua-yaml

Testing

Install busted & luacheck luarocks install busted && luarocks install luacheck and run:

$ busted
$ luacheck yaml.lua

or just:

$ make test

License

(The MIT License)

Copyright (c) 2017 Dominic Letz [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

lua-yaml's People

Contributors

dominicletz avatar godzil avatar qimatluo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lua-yaml's Issues

only decoding ?

Hello,

I'm searching a lua implementation for yamldata = yaml.encode(luadata) & luadata = yaml.decode(yamldata).

Is you current lua-yaml implementation only support decoding (with require"yaml".eval(yamldata)) ?

Best Regards,

only decode the first block of yaml

yaml:

---
hooks:
  AfterInstall:
    - location: /Users/derekmorgan/src/deploy-plugin/afterinstall.sh
      timeout: 2
    - location: /Users/derekmorgan/src/deploy-plugin/afterinstall.sh
      timeout: 2
files:
  - source: ./my-file.txt
    destination: /temp

lua:

tprint(require('yaml').eval(s), 1)
  hooks:
    AfterInstall:
      1:
        location: /Users/derekmorgan/src/deploy-plugin/afterinstall.sh
        timeout: 2
      2:
        location: /Users/derekmorgan/src/deploy-plugin/afterinstall.sh
        timeout: 2

The parser have trouble parsing list with no trailing space before the closing bracket

So it seems the parser is confused when an inline list does not have space juste before the ]:

item:
  test: [ 1, 0, 1 ]

will work fine, but the other valid

item:
  test: [ 1, 0, 1]

will end with an error about a missing comma because it think that 1] is a string token instead of a number followed by ]

I'm trying to find a way to solve the issue as it prevent to parse some perfectly valid YAML files.

Add parsing for comments

Add ability to parse yaml like this

key: #comment 1
   - value line 1
   #comment 2
   - value line 2
   #comment 3
   - value line 3
key2: 30 # comment 4
key3: "String value" # comment 5
key4: "#not a comment"

some of bad value. "values":"'on': 1\n'off': 0"

Still, have some issue.
chungear.yaml.txt

this is for smaple file the integration items will be this like:
{"traits":[{"append_name":" fan","attributes":{"on_off":{"key":"H00","values":"'on': 1\n'off': 0"},"percentage":{"before":[{"key":"H00","value":1}],"key":"H02","max":100,"min":1}},"description":"Satellite MR101W-FAR1L2/UAR1L2 FAN","id":"fan","type":"switch"},{"append_name":" light","attributes":{"brightness":{"before":[{"key":"H0B","value":1}],"key":"H0C","max":100,"min":1},"on_off":{"key":"H0B","values":"'on': 1\n'off': 0"}},"description":"Satellite MR101W-FAR1L2/UAR1L2 LIGHT","id":"light"}]}

Text block followed by more items skips said items

In the following file, the second item (bar) does not appear in the parsed data. Changing the value of foo for an inline value solves the problem.

baz:
  - foo: |
      x
  - bar: y

This is because the first token after the | is an indent, and it is not counted towards the number of indents to undo to finish a textblock. Here's a fix:

diff --git a/yaml.lua b/yaml.lua
index 55211dc..6432b4a 100644
--- a/yaml.lua
+++ b/yaml.lua
@@ -448,6 +448,9 @@ Parser.parseTextBlock = function (self, sep)
   local token = self:advance()
   local result = string_trim(token.raw, "\n")
   local indents = 0
+  if token[1] == "indent" then
+     indents = 1
+  end
   while self:peek() ~= nil and ( indents > 0 or not self:peekType("dedent") ) do
     local newtoken = self:advance()
     while token.row < newtoken.row do

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.