Permalink
Browse files

rxx: Finally figured out the right way to specify regexp options.

  Added a standard namespace std with generally useful utilities.
  • Loading branch information...
1 parent 5851772 commit 8c7d240b87d837bc63c7d2f0411a53c22b09c32a @notestaff committed Apr 13, 2012
Showing with 21 additions and 27 deletions.
  1. +2 −12 rxx-org.el
  2. +19 −15 rxx.el
View
@@ -5,7 +5,7 @@
(def-rxx-namespace org
"Org mode expressions"
- :imports elu-valu
+ :imports (std elu-valu)
)
;; should this be def-rxx-regexp instead?
@@ -63,17 +63,7 @@
(seq bol (sep-by (eval (if org-odd-levels-only "*" ""))
(1+ (named-grp star "*")))) (length star-list))
- (word-from-list (str-list) "one of a list of words" (seq bow (eval-rxx (cons 'or str-list)) eow))
-
- ; ((one-of str-list) "one of a list of strings"
- ; (seq bow (named-grp the-todo (eval-rxx (cons (quote or) str-list))) eow)
- ; (todo "the todo keyword" (named-grp todo-kw (one-of org-todo-keywords-1)))
-
- ;(todo "The todo keyword" (seq bow (named-grp the-todo (eval-rxx (cons (quote or) todo-keywords))) eow) the-todo
- ; (todo-keywords (elu-when-bound todo-keywords )
- ;
-; (todo "The todo keyword" (seq bow (named-grp the-todo (eval-rxx (cons 'or org-todo-keywords-1))) eow) the-todo)
- (todo "The todo keyword" (word-from-list (org-todo-keywords-1)))
+ ((todo :case-fold-search t) "The todo keyword" (word-from-list (org-todo-keywords-1)))
(priority-char "A priority character. Parsed as the priority char."
(eval-regexp (format "[%c-%c]" org-highest-priority org-lowest-priority))
View
34 rxx.el
@@ -238,7 +238,7 @@ Fields:
;; other things to store here:
;; case-sens, posix-search,
- namespace name descr form (parser 'identity) args)
+ namespace name descr form (parser 'identity) args case-fold-search posix-search)
@@ -514,13 +514,19 @@ Params:
"Construct the name of the global var storing the given rxx-def"
(intern (concat (symbol-name namespace) "-" (symbol-name name) "-rxx-def")))
-(defmacro* def-rxx-regexp (&rest all-args)
+(defmacro* def-rxx-regexp (namespace name-and-opts descr form &optional (parser 'identity)
+ &aux ((name args case-fold-search-val posix-search)
+ (destructuring-bind
+ (name &key args ((:case-fold-search case-fold-search-val) 'default) (posix-search 'default))
+ (elu-make-seq name-and-opts)
+ (list name args case-fold-search-val posix-search))))
"Define an rxx regexp.
Params:
NAMESPACE - the namespace for this regexp.
- NAME - the name for this regexp within NAMESPACE
+ NAME-AND-OPTS - the name for this regexp within NAMESPACE, and possibly some options.
+ If just a name, can be just the symbol.
DESCR - a string documenting what this regexp matches, and what the matches are
parsed into by PARSER
FORM - the sexp defining the regexp (described below).
@@ -536,18 +542,11 @@ refer to the list of parsed matches as G-LIST.
(named-grp NAME FORM)
"
- (if (listp (third all-args))
- (destructuring-bind (namespace name args descr form &optional (parser 'identity)) all-args
- `(defconst ,(rxx-def-global-var namespace name)
- (make-rxx-def :namespace (quote ,namespace) :name (quote ,name) :descr ,descr
- :form (quote ,form) :parser (quote ,parser) :args (quote ,args))
- ,descr)
- )
- (destructuring-bind (namespace name descr form &optional (parser 'identity) &optional args) all-args
- `(defconst ,(rxx-def-global-var namespace name)
- (make-rxx-def :namespace (quote ,namespace) :name (quote ,name) :descr ,descr
- :form (quote ,form) :parser (quote ,parser) :args (quote ,args))
- ,descr))))
+ `(defconst ,(rxx-def-global-var namespace name)
+ (make-rxx-def :namespace (quote ,namespace) :name (quote ,name) :descr ,descr
+ :form (quote ,form) :parser (quote ,parser) :args (quote ,args)
+ :case-fold-search (quote ,case-fold-search-val) :posix-search (quote ,posix-search))
+ ,descr))
(defmacro def-rxx-regexps (namespace &rest regexp-defs)
"Define several regexps in the same NAMESPACE."
@@ -1117,6 +1116,11 @@ the parsed result in case of match, or nil in case of mismatch."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(def-rxx-namespace std "The standard namespace, with generally applicable regexps")
+
+(def-rxx-regexps std
+ ((word-from-list :args (str-list)) "one of a list of words" (seq bow (eval-rxx (cons 'or str-list)) eow)))
+
(defstruct rxx-parsed-obj
"An object that was parsed from a text string.

0 comments on commit 8c7d240

Please sign in to comment.