Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sdecl

sdecl is a small declarative language for tree-shaped data.

It is designed to be:

  • compact
  • fast
  • easy to parse
  • convenient for UI markup, config files, and build descriptions

The core of the language provides a typed AST with nodes, metadata, constructor arguments, typed values, attributes, and children.

Syntax

App("demo") #root {
    title = "Hello"
    width = 800
    flags = [true, false, null]
    position = { x: 10 y: 20 }

    @meta(debug)
    Button("OK") #ok {
        text = "OK"
    }

    {
        visible = true
    }
}

Rules:

  • Type { ... } creates a node with explicit type
  • Type(arg1, arg2) { ... } creates a node with constructor-like arguments
  • #name { ... } creates a node with implicit Node type
  • { ... } creates a node with implicit type and no name
  • @meta and @meta(...) attach metadata to the next node
  • attr = value defines an attribute
  • foo.bar { ... } is parsed as a single dotted node type

Supported value kinds:

  • null
  • true / false
  • identifiers
  • integers and floats
  • quoted strings
  • arrays: [a, b, 1]
  • objects: { key: value }

Supported number forms:

  • decimal integers: 0, 10, -1
  • decimal floats: 1.2, 2., -.5
  • decimal exponent form: 4.5e1, -5.e2
  • binary integers: 0b10
  • octal integers: 0o23
  • hexadecimal integers: 0x10
  • base-prefixed numbers with exponent: 0o23e2

Reserved attribute names:

  • type
  • name
  • children

Haxe API

import s.decl.Node;
import s.decl.Value;

var root = Node.parse(source);
var fileRoot = Node.parseFile("example.sdecl");

Each parsed node contains:

  • type:String
  • name:String
  • meta:Array<{name:String, params:Array<Value>}>
  • arguments:Array<Value>
  • attributes:Map<String, Value>
  • children:Array<Node>

Value supports:

  • VNull
  • VBool
  • VIdent
  • VInt
  • VFloat
  • VString
  • VArray
  • VObject

Development

Run tests:

haxe build_tests.hxml

Releases

Packages

Contributors

Languages

Generated from selibs/shaxelib