Skip to content

Instantly share code, notes, and snippets.

@clarete
Created September 19, 2017 23:35
Show Gist options
  • Save clarete/85c26421584826ac2b7905e4cdffd11b to your computer and use it in GitHub Desktop.
Save clarete/85c26421584826ac2b7905e4cdffd11b to your computer and use it in GitHub Desktop.
start = definitions;
module :m = definitions:xs => this.gen(m, xs);
definitions = [definition+:xs] => xs;
definition = include | struct_def | func;
include
= [:include string:name] => "#include " + name
;
struct_def
= [:struct string:n !{Struct.new}:s !{s.setName(n)} params(s)] => s
| [:struct string:n !{Struct.new}:s !{s.setName(n)}] => s
;
func
= [:func string:n !{this.newFun(n)}:f
params(f) !{f.newReturnType()}:r
type(r):rt] => f
;
params :obj
= [typed(obj)*:x]
;
typed :obj
= [!{obj.newChild()}:p type(p) string:n !{p.setName(n)}] => p
;
type :p
= [:list type(p) !{p.setIsArray(true)}]
| [:annotations type(p) _:a !{p.setAnnotations(a)}]
| [:pointer type(p) _:c !{p.setIsPointer(c)}]
| [:const type(p) !{p.setIsConst(true)}]
| [:unsigned type(p) !{p.setIsUnsigned(true)}]
| type0(p)
;
type0 :p
= [:builtin string:t !{p.setTypeName(t)}]
| [:struct string:t !{p.setTypeName("struct " + t)}]
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment