{"action":"opened","issue":{"url":"https://api.github.com/repos/PistonDevelopers/dyon/issues/182","repository_url":"https://api.github.com/repos/PistonDevelopers/dyon","labels_url":"https://api.github.com/repos/PistonDevelopers/dyon/issues/182/labels{/name}","comments_url":"https://api.github.com/repos/PistonDevelopers/dyon/issues/182/comments","events_url":"https://api.github.com/repos/PistonDevelopers/dyon/issues/182/events","html_url":"https://github.com/PistonDevelopers/dyon/issues/182","id":155316980,"number":182,"title":"`meta` and `macro`","user":{"login":"bvssvni","id":1743862,"avatar_url":"https://avatars.githubusercontent.com/u/1743862?v=3","gravatar_id":"","url":"https://api.github.com/users/bvssvni","html_url":"https://github.com/bvssvni","followers_url":"https://api.github.com/users/bvssvni/followers","following_url":"https://api.github.com/users/bvssvni/following{/other_user}","gists_url":"https://api.github.com/users/bvssvni/gists{/gist_id}","starred_url":"https://api.github.com/users/bvssvni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvssvni/subscriptions","organizations_url":"https://api.github.com/users/bvssvni/orgs","repos_url":"https://api.github.com/users/bvssvni/repos","events_url":"https://api.github.com/users/bvssvni/events{/privacy}","received_events_url":"https://api.github.com/users/bvssvni/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/PistonDevelopers/dyon/labels/discussion","name":"discussion","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-17T17:31:06Z","updated_at":"2016-05-17T17:31:06Z","closed_at":null,"body":"*Notice! Don't know yet whether this is possible*\r\n\r\nThe idea is to make it simpler to use meta parsing, by adding built-in syntax for converting meta data.\r\n\r\nThen, by using the same syntax, one could create a macro system with a `macro` keyword.\r\n\r\nThe meta syntax can be reused across meta parsing and macros.\r\n\r\n### Example using `meta`:\r\n\r\nYou want to parse a custom format looking like this:\r\n\r\nassets/test_data.txt\r\n```\r\n0 1 2\r\n3 4 5\r\n6 7 8\r\n```\r\n\r\nSo, you write a meta syntax file:\r\n\r\nassets/test_meta.txt\r\n```\r\n1 pos = [.w? .$_:\"x\" .w! .$_:\"y\" .w! .$_:\"z\" .w?]\r\n0 doc = .l(pos:\"pos\")\r\n```\r\n\r\nThis generates the meta data (formatted in JSON):\r\n\r\n```\r\n\"pos\":{\r\n \"x\":0,\r\n \"y\":1,\r\n \"z\":2\r\n},\r\n\"pos\":{\r\n \"x\":3,\r\n \"y\":4,\r\n \"z\":5\r\n},\r\n\"pos\":{\r\n \"x\":6,\r\n \"y\":7,\r\n \"z\":8\r\n}\r\n```\r\n\r\nThen you write a Dyon program that parses the data using the meta syntax, and then uses `meta` to convert to a Dyon application structure:\r\n\r\n```rust\r\nfn main() {\r\n    meta_data := load(meta: \"assets/test_meta.txt\", file: \"assets/test_data.txt\")\r\n    data := unwrap(meta_data)\r\n    arr := meta data {\r\n        pos := [x: f64, y: f64, z: f64] => [x, y, z],\r\n        doc := repeat pos:\"pos\",\r\n        doc\r\n    }\r\n    println(arr)\r\n}\r\n```\r\n\r\nThis should print:\r\n\r\n```\r\n[[0, 1, 2], [3, 4, 5], [6, 7, 8]]\r\n```\r\n\r\n### Example using `macro`\r\n\r\nThis uses similar syntax as `meta`, but uses meta rules expanding to AST with corresponding types.\r\n\r\n```rust\r\nmacro! numbers \"assets/test_meta.txt\" {\r\n    pos := [x: f64, y: f64, z: f64] => [x, y, z],\r\n    doc := repeat pos:\"pos\",\r\n    doc\r\n}\r\n\r\nfn main() {\r\n    x := 4\r\n    arr := numbers! {{{\r\n        1 2 3\r\n        x 5 6\r\n        7 8 9\r\n    }}}\r\n}\r\n```\r\n\r\nIt looks just the same as when reading from data, but you can use variables and expressions where the meta syntax expects number, boolean or text.\r\n\r\n### Motivation\r\n\r\n`meta`:\r\n\r\n- Custom text formats\r\n- Data driven design\r\n\r\n`macro`:\r\n\r\n- Template languages\r\n- Custom text formats\r\n- Custom scripting languages"}}