Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 50e47961a8bb1c9a6e1796f1d75e9385581cb4be Tomohiro Matsuyama committed May 31, 2012
Showing with 2,865 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +22 −0 ruby-parser.asd
  3. +198 −0 src/ast.lisp
  4. +17 −0 src/env.lisp
  5. +1,234 −0 src/lexer.lisp
  6. +10 −0 src/packages.lisp
  7. +1,263 −0 src/parser.lisp
  8. +71 −0 src/source.lisp
  9. +22 −0 src/specials.lisp
  10. +16 −0 src/types.lisp
  11. +7 −0 src/util.lisp
@@ -0,0 +1,5 @@
+*.fasl
+*.dx64fsl
+*.dx32fsl
+*.lx64fsl
+*.x86f
@@ -0,0 +1,22 @@
+(asdf:defsystem :ruby-parser
+ :description "Ruby Parser"
+ :author "Tomohiro Matsuyama"
+ :depends-on (:alexandria
+ :iterate
+ :anaphora
+ :optima
+ :yacc
+ :cl-ppcre
+ :closer-mop
+ :parse-number)
+ :components ((:module "src"
+ :serial t
+ :components ((:file "packages")
+ (:file "util")
+ (:file "specials")
+ (:file "types")
+ (:file "ast")
+ (:file "source")
+ (:file "env")
+ (:file "lexer")
+ (:file "parser")))))
@@ -0,0 +1,198 @@
+(in-package :ruby-parser)
+
+(defstruct node loc)
+
+;;; Literals
+
+(defvariant (literal (:include node))
+ (string-lit (value (proper-list string-content)))
+ (xstring-lit (value (proper-list string-content)))
+ (symbol-lit (value (proper-list string-content)))
+ (integer-lit (value integer))
+ (float-lit (value float))
+ (regexp-lit (value (proper-list string-content))
+ (flag regexp-flag :init-form nil)))
+
+(deftype string-content ()
+ '(or string expr))
+
+(deftype regexp-flag ()
+ '(member nil :once))
+
+;;; Identifiers
+
+(defvariant (identifier (:include node))
+ (lvar (name string))
+ (dvar (name string))
+ (ivar (name string))
+ (cvar (name string))
+ (gvar (name string))
+ (const (cpath cpath))
+ (pvar (name pseudo-variable)))
+
+(defvariant (cpath (:include node))
+ (cpath-name (string string))
+ (cpath-rel (base expr)
+ (string string))
+ (cpath-glob (cpath cpath)))
+
+(deftype pseudo-variable ()
+ '(member :nil :true :false :self :__FILE__ :__LINE__))
+
+;;; Parameters
+
+(defvariant (parameter (:include node))
+ (param (name string))
+ (opt-param (name string)
+ (init expr))
+ (rest-param (name string))
+ (star-param)
+ (block-param (name string)))
+
+;;; Arguments
+
+(defvariant (argument (:include node))
+ (arg-value (expr expr))
+ (arg-splat (expr expr))
+ (arg-block (expr expr))
+ (arg-hash (list (proper-list expr))))
+
+;;; LHS
+
+(defvariant (lhs (:include node))
+ (lhs-id (id identifier))
+ (lhs-decl (id identifier))
+ (lhs-dest (list (proper-list lhs)))
+ (lhs-rest (lhs lhs))
+ (lhs-star)
+ (lhs-attr (self expr)
+ (meth string))
+ (lhs-aref (self expr)
+ (args (proper-list argument)))
+ (lhs-op (lhs lhs)
+ (op string))
+ (lhs-or (lhs lhs))
+ (lhs-and (lhs lhs)))
+
+;;; Misc
+
+(defstruct (blk (:include node))
+ (vars (required-argument) :type (proper-list lhs))
+ (body (required-argument) :type (proper-list stmt)))
+
+(deftype assign-kind ()
+ '(member :single :svalue :multi))
+
+;;; Statements
+
+(defvariant (stmt (:include node))
+ (alias-stmt (new string)
+ (old string))
+ (undef-stmt (list (proper-list string)))
+ (if-mod-stmt (stmt stmt)
+ (test expr))
+ (unless-mod-stmt (stmt stmt)
+ (test expr))
+ (while-mod-stmt (stmt stmt)
+ (test expr))
+ (until-mod-stmt (stmt stmt)
+ (test expr))
+ (rescue-mod-stmt (stmt stmt)
+ (else stmt))
+ (pre-exec-stmt (body (proper-list stmt)))
+ (post-exec-stmt (body (proper-list stmt)))
+ (expr-stmt (expr expr)))
+
+;;; Expressions
+
+(defvariant (expr (:include node))
+ (lit-expr (lit literal))
+ (id-expr (id identifier))
+ (nth-ref-expr (n fixnum))
+ (back-ref-expr (c character))
+ (array-expr (args (proper-list argument)))
+ (hash-expr (args (proper-list expr)))
+ (dot2-expr (lhs expr)
+ (rhs expr))
+ (dot3-expr (lhs expr)
+ (rhs expr))
+ (not-expr (expr expr))
+ (and-expr (lhs expr)
+ (rhs expr))
+ (or-expr (lhs expr)
+ (rhs expr))
+ (defined-expr (expr expr))
+ (tern-expr (test expr)
+ (then expr)
+ (else expr))
+ (if-expr (test expr)
+ (then (proper-list stmt))
+ (else (proper-list stmt)))
+ (unless-expr (test expr)
+ (then (proper-list stmt))
+ (else (proper-list stmt)))
+ (while-expr (test expr)
+ (body (proper-list stmt)))
+ (until-expr (test expr)
+ (body (proper-list stmt)))
+ (for-expr (lhs lhs)
+ (gen expr)
+ (body (proper-list stmt)))
+ (case-expr (test (or null expr) :init-form nil)
+ (whens (proper-list (cons (proper-list argument)
+ (proper-list stmt))))
+ (else (proper-list stmt)))
+ (break-expr (args (proper-list argument) :init-form '()))
+ (next-expr (args (proper-list argument) :init-form '()))
+ (redo-expr)
+ (retry-expr)
+ (call-expr (recv (or null expr) :init-form nil)
+ (meth string)
+ (args (proper-list argument) :init-form '())
+ (block (or null blk) :init-form nil))
+ (return-expr (args (proper-list argument) :init-form '()))
+ (yield-expr (args (proper-list argument) :init-form '()))
+ (super-expr (args (proper-list argument) :init-form '())
+ (block (or null blk) :init-form nil))
+ (zsuper-expr (block (or null blk) :init-form nil))
+ (assign-expr (lhs lhs)
+ (rhs expr)
+ (kind assign-kind))
+ (body-stmt (body (proper-list stmt))
+ (rescues (proper-list (cons (proper-list argument)
+ (proper-list stmt))))
+ (else (proper-list stmt))
+ (ensure (proper-list stmt)))
+ (class-expr (cpath cpath)
+ (super (or null expr) :init-form nil)
+ (body body-stmt))
+ (sclass-expr (expr expr)
+ (body body-stmt))
+ (module-expr (cpath cpath)
+ (body body-stmt))
+ (defn-expr (name string)
+ (params (proper-list parameter))
+ (body body-stmt))
+ (defs-expr (expr expr)
+ (name string)
+ (params (proper-list parameter))
+ (body body-stmt))
+ (begin-expr (body body-stmt))
+ (block-expr (body (proper-list stmt))))
+
+;;; Export
+
+(labels ((subclasses (class)
+ (let ((direct-subclasses (closer-mop:class-direct-subclasses class)))
+ (remove-duplicates (apply #'append direct-subclasses (mapcar #'subclasses direct-subclasses))))))
+ (iter (for class in (subclasses (find-class 'node)))
+ (for class-name = (class-name class))
+ (for predicate = (symbolicate class-name :-p))
+ (export class-name :ruby-parser)
+ (export predicate :ruby-parser)
+ (iter (for slot in (closer-mop:class-direct-slots class))
+ (for slot-name = (closer-mop:slot-definition-name slot))
+ (for accessor = (symbolicate class-name :- slot-name))
+ (export accessor :ruby-parser)
+ (import slot-name :ruby-parser.slots)
+ (export slot-name :ruby-parser.slots))))
@@ -0,0 +1,17 @@
+(in-package :ruby-parser)
+
+(defun make-env ())
+
+(defun env-find (env name))
+
+(defun env-find-in-current (env name))
+
+(defun env-use (env name))
+
+(defun env-add (env name kind))
+
+(defun env-extend (env &optional dynamic))
+
+(defun env-unextend (env))
+
+
Oops, something went wrong.

0 comments on commit 50e4796

Please sign in to comment.