Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta parsing design #168

Closed
bvssvni opened this issue May 16, 2016 · 0 comments
Closed

Meta parsing design #168

bvssvni opened this issue May 16, 2016 · 0 comments
Assignees

Comments

@bvssvni
Copy link
Member

bvssvni commented May 16, 2016

Dyon uses the Piston-Meta library for meta parsing.

List of included functions for meta parsing

  • fn load__meta_file(meta_file: str, file: str) -> res[[]]
  • fn load__meta_url(meta_file: str, url: str) -> res[[]]
  • fn syntax__in_string(name: str, text: str) -> res[any] { ... }
  • fn meta__syntax_in_string(syntax: any, name: str, text: str) -> res[[any]] { ... }

What is meta parsing?

Meta parsing is like having a language like regular expressions, but for whole text documents. The rules describes the syntax in a short and concise form.

When a document is read through meta parsing, it gets transformed into a list of commands describing a tree structure called "meta data". This structure consists of these commands:

  • start node (name)
  • end node (name)
  • bool (name, value)
  • f64 (name, value)
  • string (name, value)

Meta parsing happens in two steps:

  1. Convert text document into meta data
  2. Convert meta data into application data

When there is a syntax error in the text document, the meta parser reports this with a nice error message.

Example: JSON

This meta format validates JSON documents:

0 , = [.w? "," .w?]
1 object = ["{" .w? .s?(, [.t? .w? ":" .w? value .w?]) "}"]
2 array = ["[" .w? .s?(, value) .w? "]"]
3 value = [{
    .t?
    .$
    object
    array
    "true"
    "false"
    "null"
}]
4 document = [.w? value .w?]

Why use meta parsing?

Meta parsing has the following benefits:

  • easy to design your own custom human readable text formats by need
  • easy to verify document structure of a JSON document
  • can read a wide variety of existing text documents that uses JSON building blocks

Dyon's syntax is using meta parsing!

Dyon uses meta parsing on its own syntax. Dyon's meta syntax.

You can use this to parse Dyon code, generate documentation, do some analysis etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant