Git Product home page Git Product logo

hml's Introduction

hml

NuGet Donate

Hierarchy Markup Language, or less verbose xml.

Quickstart

node(property="value", other="another value"): this is the content
  child: content of the child
  child2
  	child21(prop="v1")
  child3(prop="v3"): another content
var node = HmlParser.Default.Parse(hmlContent).Root;
var other = node["other"]; //another value
var child = node.First(); 
var text = child.Text; //content of the child

Usage

Writing a document

An hml document should be structured following those rules :

  • A unique root node
  • One node per line
  • A node must have a name
  • A node can have properties
  • A node property must have a key and a string value.
  • A node can have text content
  • The parent of a node is the first node in the tree that has an indentation level lower than the current node (except for the first one in the document which the root node)

Parser

The parser will load an hml content as an HmlDocument, which is a tree of HmlNode.

Loading a document from a string
var hml = "node(property=\"value\"): sample\n child: test";
var document = HmlParser.Default.Parse(hml);
Accessing nodes
HmlNode node = document.Root;
HmlNode child = node[0];
Accessing properties
string value = node["property"];
Accessing text
string text = node.Text;

Lexer

The lexer splits a document into tokens. You shouldn't use the lexer until you want to analyze the document structure more precisely (for example for pretty printing an hml document).

Loading tokens
var hml = "node(property=\"value\")";
HmlToken[] tokens = HmlLexer.Default.Tokenize(hmlContent);
Accessing tokens
var nodeName = tokens[0];
var startProperties = tokens[1];
var propertyName = tokens[2];
var equals = tokens[3];
var propertyValue = tokens[4];
var endProperties = tokens[5];
Accessing token data
var type = nodeName.Type; // HmlTokenType.Identifier
var content = nodeName.Content; // "node"
var line = nodeName.Position.Line; // 0
var column = nodeName.Position.Column; // 0

Parsing exceptions

In case of a parsing error an HmlParsingException that will contains token information (position in content, expected token, ...).

Specification

A .hml describe a tree where each node has a name, set of properties (with a name and a string value), a value (string), a list of descendants.

  • Node : <Indent>``<Name>``<Properties>? (: <Text>)?
  • Indent : ( )*
  • Whitespaces : ( )*
  • Name : <Letter>|_``<Letter>|<digit>|.|_|-*
  • Properties : (``<Property>(,``<Property>)*)
  • Property : <Name>``=``"``<Value>``"
  • Value : (^")*
  • Text : (^\r|^\n|^\r\n)*

About

You might guess why I felt the need for a new data description model while there is already JSON, XML, YAML and so on. Because I like XML for the way its describing a tree of elements, but I find it may be too verbose. For example, I liked the simplicity of template engines like pug.

Contributions

Contributions are welcome! If you find a bug please report it and if you want a feature please report it.

If you want to contribute code please file an issue and create a branch off of the current dev branch and file a pull request.

License

MIT © Aloïs Deniel

hml's People

Contributors

nedlanon avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

hml's Issues

Add children accessors

/*
node
    name
    other
        name
    name
*/

var child = node.FirstChild("name"); // the first child node with name "name"
var children = node.Children("name"); // the first level children with name "name" (2 results here)

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.