aboutsummaryrefslogtreecommitdiffstats
path: root/src/init.el
diff options
context:
space:
mode:
authorsmihica <smihica@gmail.com>2013-03-12 10:50:02 +0900
committersmihica <smihica@gmail.com>2013-03-12 10:50:02 +0900
commit7ff95cafdcf85b5048e5ec51f5fd51a176e3d97e (patch)
tree535b19965e0c8dc6d4871348680ecc7d113bfb9b /src/init.el
parent4bbdc0f091446bd56dc105429e6d7118a59b2805 (diff)
downloademmet-mode-7ff95cafdcf85b5048e5ec51f5fd51a176e3d97e.tar.lz
emmet-mode-7ff95cafdcf85b5048e5ec51f5fd51a176e3d97e.tar.xz
emmet-mode-7ff95cafdcf85b5048e5ec51f5fd51a176e3d97e.zip
Created emmet branch.
Diffstat (limited to 'src/init.el')
-rw-r--r--src/init.el58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/init.el b/src/init.el
new file mode 100644
index 0000000..b5d2efe
--- /dev/null
+++ b/src/init.el
@@ -0,0 +1,58 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;;; Code:
+
+(defconst zencoding-mode:version "0.5.1")
+
+;; Include the trie data structure for caching
+;(require 'zencoding-trie)
+
+(require 'cl)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Generic parsing macros and utilities
+
+(defmacro zencoding-aif (test-form then-form &rest else-forms)
+ "Anaphoric if. Temporary variable `it' is the result of test-form."
+ `(let ((it ,test-form))
+ (if it ,then-form ,@(or else-forms '(it)))))
+
+(defmacro zencoding-pif (test-form then-form &rest else-forms)
+ "Parser anaphoric if. Temporary variable `it' is the result of test-form."
+ `(let ((it ,test-form))
+ (if (not (eq 'error (car it))) ,then-form ,@(or else-forms '(it)))))
+
+(defmacro zencoding-parse (regex nums label &rest body)
+ "Parse according to a regex and update the `input' variable."
+ `(zencoding-aif (zencoding-regex ,regex input ',(number-sequence 0 nums))
+ (let ((input (elt it ,nums)))
+ ,@body)
+ `,`(error ,(concat "expected " ,label))))
+
+(defmacro zencoding-run (parser then-form &rest else-forms)
+ "Run a parser and update the input properly, extract the parsed
+ expression."
+ `(zencoding-pif (,parser input)
+ (let ((input (cdr it))
+ (expr (car it)))
+ ,then-form)
+ ,@(or else-forms '(it))))
+
+(defmacro zencoding-por (parser1 parser2 then-form &rest else-forms)
+ "OR two parsers. Try one parser, if it fails try the next."
+ `(zencoding-pif (,parser1 input)
+ (let ((input (cdr it))
+ (expr (car it)))
+ ,then-form)
+ (zencoding-pif (,parser2 input)
+ (let ((input (cdr it))
+ (expr (car it)))
+ ,then-form)
+ ,@else-forms)))
+
+(defun zencoding-regex (regexp string refs)
+ "Return a list of (`ref') matches for a `regex' on a `string' or nil."
+ (if (string-match (concat "^" regexp "\\([^\n]*\\)$") string)
+ (mapcar (lambda (ref) (match-string ref string))
+ (if (sequencep refs) refs (list refs)))
+ nil))