Cfpeek User Manual (split by node):   Section:   Chapter:FastBack: Exit Codes   Up: Top   FastForward: Reporting Bugs   Contents: Table of ContentsIndex: Concept Index

7 Scripting

This chapter describes the Scheme functions available for use in cfpeek scripts. For an introduction to cfpeek scripting facility, see Scripts.

Scheme Procedure: grecs-node? obj

Returns ‘#t’ if obj is a valid tree node.

Scheme Procedure: grecs-node-root node

Returns the topmost node that can be traced up from node.

Scheme Procedure: grecs-node-head node

Returns the first node having the same parent and located on the same nesting level as node. I.e. the following always holds true:

(let ((head (grecs-node-head node)))
  (and
    (eq? (grecs-node-up node) (grecs-node-up head))
    (not (grecs-node-prev? head))))
Scheme Procedure: grecs-node-tail node

Returns the last node having the same parent and located on the same nesting level as node. In other words, the following relation is always ‘#t’:

(let ((tail (grecs-node-tail node)))
  (and
    (eq? (grecs-node-up node) (grecs-node-up tail))
         (not (grecs-node-next? tail))))
Scheme Procedure: grecs-node-up? node

Return true if node has a parent node.

Scheme Procedure: grecs-node-up node

Return parent node of node.

Scheme Procedure: grecs-node-down? node

Returns ‘#t’ if node has child nodes.

Scheme Procedure: grecs-node-down node

Returns the first child node of node.

Scheme Procedure: grecs-node-next? node

Returns ‘#t’ if node is followed by another node on the same nesting level.

Scheme Procedure: grecs-node-next node

Returns the node following node on the same nesting level.

Scheme Procedure: grecs-node-prev? node

Returns ‘#t’ if node is preceded by another node on the same nesting level.

Scheme Procedure: grecs-node-prev node

Returns the node preceding node on the same nesting level.

Scheme Procedure: grecs-node-ident node

Returns identifier of the node node.

Scheme Procedure: grecs-node-ident-locus node [full]

Returns locus of the node’s identifier. Returned value is a cons whose parts depend on full, which is a boolean value. If full is ‘#f’, which is the default, then returned value is a cons:

(file-name . line-number)

Oherwise, if full is ‘#t’, the function returns the locations where the node begins and ends:

((beg-file-name beg-line beg-column) . 
 (end-file-name end-line end-column))
Scheme Procedure: grecs-node-path-list node

Returns the full path to the node, converted to a list. Each list element corresponds to a subnode identifier. A subnode which has a tag is represented by a cons, whose car contains the subnode identifier, and cdr its value. For example, the following path:

.foo.bar=x.baz

is represented as

'("foo" ("bar" . "x") "baz")
Scheme Procedure: grecs-node-path node [delim]

Returns the full path to the node (a string).

Scheme Procedure: grecs-node-type node

Returns the type of the node. The following constants are defined:

grecs-node-root

The node is a root node. The following is always ‘#t’:

(and (= (grecs-node-type node) grecs-node-root)
     (not (grecs-node-up? node))
     (not (grecs-node-prev? node)))
grecs-node-stmt

The node is a simple statement. The following is always ‘#t’:

(and (= (grecs-node-type node) grecs-node-stmt)
     (not (grecs-node-down? node)))
grecs-node-block

The node is a block statement.

Scheme Procedure: grecs-node-has-value? node

Returns ‘#t’ if node has a value.

Scheme Procedure: grecs-node-value node

Returns the value of node.

Scheme Procedure: grecs-node-value-locus node [full]

Returns locus of the node’s value. Returned value is a cons whose parts depend on full, which is a boolean value. If full is ‘#f’, which is the default, then returned value is a cons:

(file-name . line-number)

Oherwise, if full is ‘#t’, the function returns the locations where the node begins and ends:

((beg-file-name beg-line beg-column) . 
 (end-file-name end-line end-column))
Scheme Procedure: grecs-node-locus node [full]

Returns source location of the node. Returned value is a cons whose parts depend on full, which is a boolean value. If full is ‘#f’, which is the default, then returned value is a cons:

(file-name . line-number)

Oherwise, if full is ‘#t’, the function returns the locations where the node begins and ends:

((beg-file-name beg-line beg-column) . 
 (end-file-name end-line end-column))
Scheme Procedure: grecs-find-node node path

Returns the first node whose path is path. Starts search from node.

Scheme Procedure: grecs-match-first node pattern

Returns the first node whose path matches pattern. The search is started from node.

Scheme Procedure: grecs-match-next node

Node must be a node returned by a previous call to grecs-match-first or ‘grecs-match-next’. The function returns next node matching the initial pattern, or ‘#f’ if no more matches are found. For example, the following code iterates over all nodes matching pattern:

(define (iterate-nodes root pattern thunk)
  (do ((node (grecs-match-first root pattern)
             (grecs-match-next node)))
      ((not node))
     (thunk node)))

Cfpeek User Manual (split by node):   Section:   Chapter:FastBack: Exit Codes   Up: Top   FastForward: Reporting Bugs   Contents: Table of ContentsIndex: Concept Index