Skip to content

Instantly share code, notes, and snippets.

@jlongster
Created January 7, 2012 20:51
Show Gist options
  • Save jlongster/1576001 to your computer and use it in GitHub Desktop.
Save jlongster/1576001 to your computer and use it in GitHub Desktop.
Beginning of Outlet compiler in Outlet (compiles to js and lua)
(require (reader "./ext/Parser")
(util "util")
(ast "./ast")
(grammar "./grammar"))
;; util
(define (assert v msg)
(if (not v)
(throw msg)))
(define (assert_type node type msg)
(assert (= (node-type node) type)
(string-append "invalid type, expected "
type
": "
(inspect node))))
;; main functions
(define (read src)
(reader grammar src))
(define (parse node generator)
(let ((parser (vector-ref parsers (node-type node))))
(assert parser (string-append "No parser for node type:"
(node-type node)))
(parser node
(lambda (node) (parse node generator))
generator)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment