Git Product home page Git Product logo

datalist's Introduction

datalist

A data format used by our game engine. It's just like a simpler version of yaml, or an enhanced version of json.

A simple dictionary

key should be a string without space, use : or = to separate value.

a = datalist.parse [[
x : 1 # comments ...
y = 2 # = is equivalent to :
100 : number
]]

-- a = { x = 1, y = 2, ["100"] = "number" }

Or you can use datalist.parse_list to parse dictionary into a list with key value pairs.

a = datalist.parse_list [[
x : 1
y : 2
]]

-- a = { x , 1, y , 2 }

A simple list

Use white space ( space, tab, cr, newline , etc) to separate atoms.

a = datalist.parse[[
hello "world"
0x1p+0 # hex float 1.0
2 
0x3 # hex integer
nil
true 
false
on  # true
off # false
yes # true
no  # false
]]

-- a = { "hello", "world", 1.0, 2, 3, nil, true, false, true, false, true, false }

section list

--- can be used to separate sections of a list.

a = datalist.parse [[
---
x : hello
y : world
---
1 2 3
]]

-- a = { { x = "hello", y = "world" }, { 1,2,3 } }

Use indent or {} to describe a multilayer structure

a = datalist.parse [[
x :
  1 2 3
y :
  dict : "hello world"
z : { foobar }
]]

-- a = {  x = { 1,2,3 },  y = { dict = "hello world" }, z = { "foobar" } }

b = datalist.parse [[
---
hello world
  ---
  x : 1
  y : 2
]]

-- a = { "hello", "world", { x = 1, y = 2 } }

Use tag to reference a structure

tag is a 64bit hex integer id.

a = datalist.parse [[
--- &1   # This structure tagged by 1
"hello\nworld"
---
x : *1   # The value is the structure with tag 1
]]

-- a = { { "hello\nworld" } , { x = { "hello\nworld" } } }

Converter

The structure in [] would be convert by a user function.

a = datalist.parse( "[ 1, 2, 3 ]" , function (t)
  local s = 0
  for _, v in ipairs(t) do  -- t = { 1,2,3 }
    s = s + v
  end
  return s)
  
-- a = { 6 }

a = datalist.parse([[
[ sum 1 2 3 ]
[ vec 4 5 6 ]
]], function (t)
  if t[1] == "sum" then
    local s = 0
    for i = 2, #t do
      s = s + t[i]
    end
  elseif t[2] == "vec" then
    table.remove(t, 1)
  end
  return t)
  
-- a = { 6 , { 4,5,6 } }

datalist's People

Contributors

cloudwu avatar

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.