Skip to content

Meta parsing design #168

Closed
Closed
@bvssvni

Description

@bvssvni

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.

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions