?
Current Path : /usr/share/emacs/24.3/lisp/obsolete/ |
Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 |
Current File : //usr/share/emacs/24.3/lisp/obsolete/sregex.elc |
;ELC ;;; Compiled by mockbuild@buildfarm06-new.corp.cloudlinux.com on Fri Oct 11 10:09:10 2024 ;;; from file /builddir/build/BUILD/emacs-24.3/lisp/obsolete/sregex.el ;;; in Emacs version 24.3.1 ;;; with all optimizations. ;;; This file uses dynamic docstrings, first added in Emacs 19.29. ;;; This file does not contain utf-8 non-ASCII characters, ;;; and so can be loaded in Emacs versions earlier than 23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar sregex--current-sregex nil) (defalias 'sregex-info #[nil "\300\207" [nil] 1]) (defalias 'sregex-save-match-data '(macro . #[(&rest forms) "\301B\207" [forms save-match-data] 2])) (defalias 'sregex-replace-match #[(r &optional f l str subexp x) "\305 \n\f%\207" [r f l str subexp replace-match] 6]) (defalias 'sregex-match-string #[(c &optional i x) "\302 \"\207" [c i match-string] 3]) (defalias 'sregex-match-string-no-properties #[(count &optional in-string sregex) "\302 \"\207" [count in-string match-string-no-properties] 3]) (defalias 'sregex-match-beginning #[(count &optional sregex) "\224\207" [count] 1]) (defalias 'sregex-match-end #[(count &optional sregex) "\225\207" [count] 1]) (defalias 'sregex-match-data #[(&optional sregex) "\300 \207" [match-data] 1]) (defalias 'sregex-backref-num #[(n &optional sregex) "\207" [n] 1]) #@495 Symbolic regular expression interpreter. This is exactly like `sregexq' (q.v.) except that it evaluates all its arguments, so literal sregex clauses must be quoted. For example: (sregex '(or "Bob" "Robert")) => "Bob\\|Robert" An argument-evaluating sregex interpreter lets you reuse sregex subexpressions: (let ((dotstar '(0+ any)) (whitespace '(1+ (syntax ?-))) (digits '(1+ (char (?0 . ?9))))) (sregex 'bol dotstar ":" whitespace digits)) => "^.*:\\s-+[0-9]+" (defalias 'sregex #[(&rest exps) "\301\302\"\207" [exps sregex--sequence nil] 3 (#$ . 1415)]) #@6843 Symbolic regular expression interpreter. This macro allows you to specify a regular expression (regexp) in symbolic form, and converts it into the string form required by Emacs's regex functions such as `re-search-forward' and `looking-at'. Here is a simple example: (sregexq (or "Bob" "Robert")) => "Bob\\|Robert" As you can see, an sregex is specified by placing one or more special clauses in a call to `sregexq'. The clause in this case is the `or' of two strings (not to be confused with the Lisp function `or'). The list of allowable clauses appears below. With `sregex', it is never necessary to "escape" magic characters that are meant to be taken literally; that happens automatically. For example: (sregexq "M*A*S*H") => "M\\*A\\*S\\*H" It is also unnecessary to "group" parts of the expression together to overcome operator precedence; that also happens automatically. For example: (sregexq (opt (or "Bob" "Robert"))) => "\\(Bob\\|Robert\\)?" It *is* possible to group parts of the expression in order to refer to them with numbered backreferences: (sregexq (group (or "Go" "Run")) ", Spot, " (backref 1)) => "\\(Go\\|Run\\), Spot, \\1" If `sregexq' needs to introduce its own grouping parentheses, it will automatically renumber your backreferences: (sregexq (opt "resent-") (group (or "to" "cc" "bcc")) ": " (backref 1)) => "\\(resent-\\)?\\(to\\|cc\\|bcc\\): \\2" `sregexq' is a macro. Each time it is used, it constructs a simple Lisp expression that then invokes a moderately complex engine to interpret the sregex and render the string form. Because of this, I don't recommend sprinkling calls to `sregexq' throughout your code, the way one normally does with string regexes (which are cheap to evaluate). Instead, it's wiser to precompute the regexes you need wherever possible instead of repeatedly constructing the same ones over and over. Example: (let ((field-regex (sregexq (opt "resent-") (or "to" "cc" "bcc")))) ... (while ... ... (re-search-forward field-regex ...) ...)) The arguments to `sregexq' are automatically quoted, but the flipside of this is that it is not straightforward to include computed (i.e., non-constant) values in `sregexq' expressions. So `sregex' is a function that is like `sregexq' but which does not automatically quote its values. Literal sregex clauses must be explicitly quoted like so: (sregex '(or "Bob" "Robert")) => "Bob\\|Robert" but computed clauses can be included easily, allowing for the reuse of common clauses: (let ((dotstar '(0+ any)) (whitespace '(1+ (syntax ?-))) (digits '(1+ (char (?0 . ?9))))) (sregex 'bol dotstar ":" whitespace digits)) => "^.*:\\s-+[0-9]+" Here are the clauses allowed in an `sregex' or `sregexq' expression: - a string This stands for the literal string. If it contains metacharacters, they will be escaped in the resulting regex (using `regexp-quote'). - the symbol `any' This stands for ".", a regex matching any character except newline. - the symbol `bol' Stands for "^", matching the empty string at the beginning of a line - the symbol `eol' Stands for "$", matching the empty string at the end of a line - (group CLAUSE ...) Groups the given CLAUSEs using "\\(" and "\\)". - (sequence CLAUSE ...) Groups the given CLAUSEs; may or may not use "\\(" and "\\)". Clauses grouped by `sequence' do not count for purposes of numbering backreferences. Use `sequence' in situations like this: (sregexq (or "dog" "cat" (sequence (opt "sea ") "monkey"))) => "dog\\|cat\\|\\(?:sea \\)?monkey" where a single `or' alternate needs to contain multiple subclauses. - (backref N) Matches the same string previously matched by the Nth "group" in the same sregex. N is a positive integer. - (or CLAUSE ...) Matches any one of the CLAUSEs by separating them with "\\|". - (0+ CLAUSE ...) Concatenates the given CLAUSEs and matches zero or more occurrences by appending "*". - (1+ CLAUSE ...) Concatenates the given CLAUSEs and matches one or more occurrences by appending "+". - (opt CLAUSE ...) Concatenates the given CLAUSEs and matches zero or one occurrence by appending "?". - (repeat MIN MAX CLAUSE ...) Concatenates the given CLAUSEs and constructs a regex matching at least MIN occurrences and at most MAX occurrences. MIN must be a non-negative integer. MAX must be a non-negative integer greater than or equal to MIN; or MAX can be nil to mean "infinity." - (char CHAR-CLAUSE ...) Creates a "character class" matching one character from the given set. See below for how to construct a CHAR-CLAUSE. - (not-char CHAR-CLAUSE ...) Creates a "character class" matching any one character not in the given set. See below for how to construct a CHAR-CLAUSE. - the symbol `bot' Stands for "\\`", matching the empty string at the beginning of text (beginning of a string or of a buffer). - the symbol `eot' Stands for "\\'", matching the empty string at the end of text. - the symbol `point' Stands for "\\=\=", matching the empty string at point. - the symbol `word-boundary' Stands for "\\b", matching the empty string at the beginning or end of a word. - the symbol `not-word-boundary' Stands for "\\B", matching the empty string not at the beginning or end of a word. - the symbol `bow' Stands for "\\=\<", matching the empty string at the beginning of a word. - the symbol `eow' Stands for "\\=\>", matching the empty string at the end of a word. - the symbol `wordchar' Stands for the regex "\\w", matching a word-constituent character (as determined by the current syntax table) - the symbol `not-wordchar' Stands for the regex "\\W", matching a non-word-constituent character. - (syntax CODE) Stands for the regex "\\sCODE", where CODE is a syntax table code (a single character). Matches any character with the requested syntax. - (not-syntax CODE) Stands for the regex "\\SCODE", where CODE is a syntax table code (a single character). Matches any character without the requested syntax. - (regex REGEX) This is a "trapdoor" for including ordinary regular expression strings in the result. Some regular expressions are clearer when written the old way: "[a-z]" vs. (sregexq (char (?a . ?z))), for instance. Each CHAR-CLAUSE that is passed to (char ...) and (not-char ...) has one of the following forms: - a character Adds that character to the set. - a string Adds all the characters in the string to the set. - A pair (MIN . MAX) Where MIN and MAX are characters, adds the range of characters from MIN through MAX to the set. (defalias 'sregexq '(macro . #[(&rest exps) "\301\302\303DE\207" [exps apply 'sregex quote] 4 (#$ . 2012)])) (defalias 'sregex--engine #[(exp combine) ";\203! \203 \302=\203 G\303U\204 \304\305!\306Q\207\305!\2079\203\234 \307\310\"\203/ \311\207\307\312\"\2038 \313\207\307\314\"\203A \315\207\307\316\"\203J \317\207\307\320\"\203S \321\207\307\322\"\203\\ \323\207\307\324\"\203e \325\207\307\326\"\203n \327\207\307\330\"\203w \331\207\307\332\"\203\200 \333\207\307\334\"\203\211 \335\207\307\336\"\203\222 \337\207\340\341\342#\205\262 \343\207:\203\256 \344\345\346@!P!A \"\207\340\347\"\207" [exp combine suffix 1 "\\(?:" regexp-quote "\\)" eql any "." bol "^" eol "$" wordchar "\\w" not-wordchar "\\W" bot "\\`" eot "\\'" point "\\=" word-boundary "\\b" not-word-boundary "\\B" bow "\\<" eow "\\>" error "cl-ecase failed: %s, %s" (any bol eol wordchar not-wordchar bot eot point word-boundary not-word-boundary bow eow) nil intern "sregex--" symbol-name "Invalid expression: %s"] 4]) (defalias 'sregex--sequence #[(exps combine) "G\303U\203 \304@ \"\207\305\306\307# \310=\203 \311\n\312Q\202! \n)\207" [exps combine re 1 sregex--engine mapconcat #[(e) "\301\302\"\207" [e sregex--engine concat] 3] "" suffix "\\(?:" "\\)"] 4]) (defalias 'sregex--or #[(exps combine) "G\303U\203 \304@ \"\207\305\306\307# \310=\204 \311\n\312Q\202! \n)\207" [exps combine re 1 sregex--engine mapconcat #[(e) "\301\302\"\207" [e sregex--engine or] 3] "\\|" or "\\(?:" "\\)"] 4]) (defalias 'sregex--group #[(exps combine) "\301\302\303\"\304Q\207" [exps "\\(" sregex--sequence nil "\\)"] 4]) (defalias 'sregex--backref #[(exps combine) "\301\302@!P\207" [exps "\\" int-to-string] 3]) (defalias 'sregex--opt #[(exps combine) "\301\302\"\303P\207" [exps sregex--sequence suffix "?"] 3]) (defalias 'sregex--0+ #[(exps combine) "\301\302\"\303P\207" [exps sregex--sequence suffix "*"] 3]) (defalias 'sregex--1+ #[(exps combine) "\301\302\"\303P\207" [exps sregex--sequence suffix "+"] 3]) (defalias 'sregex--char #[(exps combine) "\301\302\"\207" [exps sregex--char-aux nil] 3]) (defalias 'sregex--not-char #[(exps combine) "\301\302\"\207" [exps sregex--char-aux t] 3]) (defalias 'sregex--syntax #[(exps combine) "\301\302@\"\207" [exps format "\\s%c"] 3]) (defalias 'sregex--not-syntax #[(exps combine) "\301\302@\"\207" [exps format "\\S%c"] 3]) (defalias 'sregex--regex #[(exps combine) "\203\n \302 @\303Q\207 @\207" [combine exps "\\(?:" "\\)"] 3]) (defalias 'sregex--repeat #[(exps combine) "\211A@\206 \304\305 !\211A@\306\307\"\310\n\311\205\"