Function: hif-strtok
hif-strtok is a byte-compiled function defined in hideif.el.gz.
Signature
(hif-strtok STRING &optional REMATCH)
Documentation
Convert STRING into a hideif mode internal token.
Assuming we've just performed a hif-token-regexp lookup.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/hideif.el.gz
(defun hif-strtok (string &optional rematch)
"Convert STRING into a hideif mode internal token.
Assuming we've just performed a `hif-token-regexp' lookup."
;; This function relies on the regexp groups of `hif-token-regexp'
;; New hideif internal number representation: a text string with `hif-value'
;; property to keep its value. Strings without `hif-value' property is a
;; normal C(++) string. This is mainly for stringification. The original
;; implementation only keep the value thus a C++ number like octal 01234
;; will become "668" after being stringified instead of the expected "01234".
(let (bufstr m1 m3 m5 m6 m8 neg ch val dec)
(when rematch
(string-match hif-token-regexp string)
(setq bufstr string))
(cond
;; decimal/octal
((match-string 8 bufstr)
(setq m6 (match-string 9 bufstr))
(setq val
(if (or (setq m8 (match-string 11 bufstr))
(match-string 10 bufstr)) ;; floating
;; TODO: do we need to add 'hif-type property for
;; type-checking, but this will slow things down
(hif-string-to-decfloat string m6 m8)
(setq ch (aref string 0))
(hif-string-to-number
string
;; octal begin with `0'
(if (and (> (length string) 1)
(or (eq ch ?0)
;; -0... or +0...
(and (memq ch '(?- ?+))
(eq (aref string 1) ?0))))
8 (setq dec 10)))))
;; Decimal integer without sign and extension is identical to its
;; string form, make it as simple as possible
(if (and dec
(null (match-string 12 bufstr)) ;; no extension like 'UL'
(not (memq ch '(?- ?+))))
val
(add-text-properties 0 1 (list 'hif-value val) string)
string))
;; hex/binary
((match-string 1 bufstr)
(setq m3 (match-string 3 bufstr))
(add-text-properties
0 1
(list 'hif-value
(if (or (setq m5 (match-string 5 bufstr))
m3)
(hif-string-to-hexfloat
string
(match-string 2 bufstr) m3 m5) ;; hexfloat
(setq neg (if (eq (aref string 0) ?-) -1 1))
(* neg
(hif-string-to-number
;; (5-(-1))/2=3; (5-1)/2=2
(substring-no-properties string (ash (- 5 neg) -1))
;; (3-(-1))/2=2; (3-1)/2=1
(if (or (eq (setq ch (aref string (ash (- 3 neg) -1))) ?x)
(eq ch ?X)) ;; hex
16 2)))))
string) string)
;; operator
((setq m1 (match-string 14 bufstr))
(cdr (assoc m1 hif-token-alist #'string-equal)))
(t
(setq hif-simple-token-only nil)
(intern-safe string)))))