Function: srecode-compile-split-code

srecode-compile-split-code is a byte-compiled function defined in compile.el.gz.

Signature

(srecode-compile-split-code TAG STR STATE &optional END-NAME)

Documentation

Split the code for TAG into something templatable.

STR is the string of code from TAG to split. STATE is the current compile state. ESCAPE_START and ESCAPE_END are regexps that indicate the beginning escape character, and end escape character pattern for expandable macro names. Optional argument END-NAME specifies the name of a token upon which parsing should stop.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/srecode/compile.el.gz
(defun srecode-compile-split-code (tag str STATE
				       &optional end-name)
  "Split the code for TAG into something templatable.
STR is the string of code from TAG to split.
STATE is the current compile state.
ESCAPE_START and ESCAPE_END are regexps that indicate the beginning
escape character, and end escape character pattern for expandable
macro names.
Optional argument END-NAME specifies the name of a token upon which
parsing should stop."
  (let* ((what str)
	 (end-token nil)
	 (comp nil)
	 (regex (concat "\n\\|" (regexp-quote (oref STATE escape_start))))
	 (regexend (regexp-quote (oref STATE escape_end)))
	 )
    (while (and what (not end-token))
      (cond
       ((string-match regex what)
	(let* ((prefix (substring what 0 (match-beginning 0)))
	       (match (substring what
				 (match-beginning 0)
				 (match-end 0)))
	       (namestart (match-end 0))
	       (junk (string-match regexend what namestart))
	       end tail name)
	  ;; Add string to compiled output
	  (when (> (length prefix) 0)
	    (setq comp (cons prefix comp)))
	  (if (string= match "\n")
	      ;; Do newline thingy.
	      (let ((new-inserter
		     (srecode-compile-inserter
		      "INDENT"
		      "\n"
		      STATE
		      :secondname nil
		      ;; This newline is "hard" meaning ALWAYS do it
		      ;; if the previous entry is also a newline.
		      ;; Without it, user entered blank lines will be
		      ;; ignored.
		      :hard (srecode-compile-do-hard-newline-p comp)
		      )))
		;; Trim WHAT back.
		(setq what (substring what namestart))
		(when (> (length what) 0)
		  ;; make the new inserter, but only if we aren't last.
		  (setq comp (cons new-inserter comp))
		  ))
	    ;; Regular inserter thingy.
	    (setq end (if junk
			  (match-beginning 0)
			(error "Could not find end escape for %s"
			       (semantic-tag-name tag)))
		  tail (match-end 0))
	    (cond ((not end)
		   (error "No matching escape end for %s"
			  (semantic-tag-name tag)))
		  ((<= end namestart)
		   (error "Stray end escape for %s"
			  (semantic-tag-name tag)))
		  )
	    ;; Add string to compiled output
	    (setq name (substring what namestart end))
	    ;; Trim WHAT back.
	    (setq what (substring what tail))
	    ;; Get the inserter
	    (let ((new-inserter
		   (srecode-compile-parse-inserter name STATE))
		  )
	      ;; If this is an end inserter, then assign into
	      ;; the end-token.
	      (if (srecode-match-end new-inserter end-name)
		  (setq end-token new-inserter))
	      ;; Add the inserter to our compilation stream.
	      (setq comp (cons new-inserter comp))
	      ;; Allow the inserter an opportunity to modify
	      ;; the input stream.
	      (setq what (srecode-parse-input new-inserter tag what
					      STATE))
	      )
	    )))
       (t
	(if end-name
	    (error "Unmatched section end %s" end-name))
	(setq comp (cons what comp)
	      what nil))))
    (cons what (nreverse comp))))