- "Like `match-string-no-properties', for a regexp made with `sregex'.
-This takes one additional optional argument, the `sregex' info, which
-can be obtained with `sregex-info'. The COUNT argument is adjusted to
-allow for \"introduced groups\". If the extra argument is omitted or
-nil, it defaults to the current value of (sregex-info)."
- (match-string-no-properties
- (and count
- (sregex-backref-num
- count
- (sregex--value-groups (or sregex
- sregex--current-sregex))))
- in-string))
-
-(defun sregex-match-beginning (count &optional sregex)
- "Like `match-beginning', for a regexp made with `sregex'.
-This takes one additional optional argument, the `sregex' info, which
-can be obtained with `sregex-info'. The COUNT argument is adjusted to
-allow for \"introduced groups\". If the extra argument is omitted or
-nil, it defaults to the current value of (sregex-info)."
- (match-beginning (sregex-backref-num
- count
- (sregex--value-groups (or sregex
- sregex--current-sregex)))))
-
-(defun sregex-match-end (count &optional sregex)
- "Like `match-end', for a regexp made with `sregex'.
-This takes one additional optional argument, the `sregex' info, which
-can be obtained with `sregex-info'. The COUNT argument is adjusted to
-allow for \"introduced groups\". If the extra argument is omitted or
-nil, it defaults to the current value of (sregex-info)."
- (match-end (sregex-backref-num
- count
- (sregex--value-groups (or sregex
- sregex--current-sregex)))))
-
-(defun sregex-match-data (&optional sregex)
- "Like `match-data', for a regexp made with `sregex'.
-This takes one additional optional argument, the `sregex' info, which
-can be obtained with `sregex-info'. \"Introduced groups\" are removed
-from the result. If the extra argument is omitted or nil, it defaults
-to the current value of (sregex-info)."
- (let* ((data (match-data))
- (groups (sregex--value-groups (or sregex
- sregex--current-sregex)))
- (result (list (car (cdr data))
- (car data))))
- (setq data (cdr (cdr data)))
- (while data
- (if (car groups)
- (setq result (append (list (car (cdr data))
- (car data))
- result)))
- (setq groups (cdr groups)
- data (cdr (cdr data))))
- (reverse result)))
-
-(defun sregex--render-tree (tree sregex)
- (let ((key (car tree)))
- (cond ((eq key 'str)
- (cdr tree))
- ((eq key 'or)
- (mapconcat '(lambda (x)
- (sregex--render-tree x sregex))
- (cdr tree)
- "\\|"))
- ((eq key 'sequence)
- (apply 'concat
- (mapcar '(lambda (x)
- (sregex--render-tree x sregex))
- (cdr tree))))
- ((eq key 'group)
- (concat "\\("
- (sregex--render-tree (cdr tree) sregex)
- "\\)"))
- ((eq key 'opt)
- (concat (sregex--render-tree (cdr tree) sregex)
- "?"))
- ((eq key '0+)
- (concat (sregex--render-tree (cdr tree) sregex)
- "*"))
- ((eq key '1+)
- (concat (sregex--render-tree (cdr tree) sregex)
- "+"))
- ((eq key 'backref)
- (let ((num (sregex-backref-num (cdr tree) sregex)))
- (if (> num 9)
- (error "sregex: backref number %d too high after adjustment"
- num)
- (concat "\\" (int-to-string num)))))
- (t (error "sregex internal error: unknown tree type %S"
- key)))))