176 lines
6.5 KiB
HTML
176 lines
6.5 KiB
HTML
|
<html>
|
||
|
<head>
|
||
|
<!-- This file has been generated by unroff 1.0, 03/21/96 19:29:44. -->
|
||
|
<!-- Do not edit! -->
|
||
|
<link rev="made" href="mailto:net@informatik.uni-bremen.de">
|
||
|
<title>unroff Programmer's Manual, section 8.</title>
|
||
|
</head><body>
|
||
|
<h2><a name="section8">8.</a> <tt> </tt>Calling the Parser
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>The following Scheme primitives are used by event procedures for
|
||
|
requests, macros, and escape characters to parse their arguments
|
||
|
or to parse lines of text that have been read from an input source.<tt> </tt>
|
||
|
Each of the primitives can be invoked with zero or more arguments
|
||
|
of type string, symbol, or character.<tt> </tt>
|
||
|
The arguments are concatenated to form a Scheme string which is then
|
||
|
passed to the parser, and the result is returned as a new string.<tt> </tt>
|
||
|
<h2>
|
||
|
<a name=".parse">(parse <i>.</i> <i>args</i>)</a></h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>This primitive feeds its arguments to the ``escape parsing''
|
||
|
pass as described in the previous section.<tt> </tt>
|
||
|
It scans its arguments for special characters and escape
|
||
|
sequences and replaces them by the corresponding event values
|
||
|
(or results), and it executes character translations.<tt> </tt>
|
||
|
<h2>
|
||
|
<a name=".translate">(translate <i>.</i> <i>args</i>)</a></h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>Like
|
||
|
<i>parse
|
||
|
</i>above, except that only output character translations (defined by calls to
|
||
|
<i>defchar</i>)
|
||
|
are executed.<tt> </tt>
|
||
|
<h2>
|
||
|
(parse-expand <i>.</i> <i>args</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>This primitive applies the ``expansion parsing'' phase (as described in the
|
||
|
previous section) to its arguments.<tt> </tt>
|
||
|
Compared to
|
||
|
<i>parse</i>,
|
||
|
<i>parse-expand
|
||
|
</i>is only used rarely, as input lines read in the normal way are
|
||
|
scanned for string and number register references anyway.<tt> </tt>
|
||
|
The sample implementation supplied by
|
||
|
<i>unroff
|
||
|
</i>for the requests ``.ds'', ``.as'', and '\*' makes use of this primitive
|
||
|
to rescan the contents of user-defined strings upon interpolation.<tt> </tt>
|
||
|
<h2>
|
||
|
(parse-line <i>.</i> <i>args</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>This primitive parses an entire input line, which may contain a call
|
||
|
to a request or macro, as described in the previous section.<tt> </tt>
|
||
|
The line made up by the primitive's arguments is treated exactly as
|
||
|
it if were read from an input file, although it need not have a
|
||
|
terminating newline.<tt> </tt>
|
||
|
Two places where this primitive is required are the handler for
|
||
|
the request ``.so'' and the code that expands user-defined macros.<tt> </tt>
|
||
|
<h2>
|
||
|
(parse-copy-mode <i>.</i> <i>args</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>The primitive
|
||
|
<i>parse-copy-mode
|
||
|
</i>parses its arguments in a manner similar to troff ``copy mode''.<tt> </tt>
|
||
|
In this mode, escape sequences beginning with '\$' are dealt
|
||
|
with (by calling their event procedures), the sequence `\\'
|
||
|
is replaced by a single `\', and each occurrence of `\.'
|
||
|
is replaced by a period.<tt> </tt>
|
||
|
Macro bodies are parsed in copy mode during macro definition and again
|
||
|
when the macros are expanded.<tt> </tt>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>The sample implementation of user-defined macros supplied by
|
||
|
<i>unroff
|
||
|
</i>defines suitable event handlers for the usual
|
||
|
<dl><dt><dd>
|
||
|
<pre>
|
||
|
\$1 \$2 ...
|
||
|
</pre>
|
||
|
</dl>
|
||
|
escape sequences (there is no limit to the number of arguments,
|
||
|
and the groff long name convention may be used to denote an
|
||
|
argument number), and in addition for the groff extensions
|
||
|
<dl><dt><dd>
|
||
|
<pre>
|
||
|
\$0 \$* \$@
|
||
|
</pre>
|
||
|
</dl>
|
||
|
as explained in the
|
||
|
<a href="./unroff.1.html">manual page</a>
|
||
|
<i>unroff</i>(1).<tt> </tt>
|
||
|
<h2>
|
||
|
(parse-expression <i>expr</i> <i>fail</i> <i>scale</i>)
|
||
|
<br>
|
||
|
(parse-expression-rest <i>expr</i> <i>fail</i> <i>scale</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>These primitives evaluate the numeric expression specified by
|
||
|
the string argument
|
||
|
<i>expr
|
||
|
</i>and return the result as an exact number.<tt> </tt>
|
||
|
The usual troff expression syntax, operators, and scale
|
||
|
indicators are supported.<tt> </tt>
|
||
|
If an error occurs during evaluation (for instance, if
|
||
|
<i>expr
|
||
|
</i>is not a syntactically valid expression),
|
||
|
a warning message is displayed and
|
||
|
<i>fail
|
||
|
</i>(which may be an arbitrary Scheme object) is returned.<tt> </tt>
|
||
|
The character argument
|
||
|
<i>scale
|
||
|
</i>is the default scale indicator, for example `#\m', or `#\u'
|
||
|
for basic units.<tt> </tt>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>The primitive
|
||
|
<i>parse-expression-rest
|
||
|
</i>is identical to
|
||
|
<i>parse-expression</i>,
|
||
|
except that its return value is a cons cell whose car consists
|
||
|
of the result of the evaluation and whose cdr is the rest of
|
||
|
<i>expr
|
||
|
</i>starting at the character position where parsing of the
|
||
|
expression stopped.<tt> </tt>
|
||
|
In other words, the primitive evaluates the portion of
|
||
|
<i>expr
|
||
|
</i>that constitutes a valid expression, and it returns the result
|
||
|
and whatever is left over.<tt> </tt>
|
||
|
Warning messages are also suppressed, except if an overflow occurs
|
||
|
during evaluation.<tt> </tt>
|
||
|
<i>parse-expression-rest
|
||
|
</i>is useful for tasks like parsing the argument of the escape
|
||
|
sequences `\l' and `\L' where an expression is immediately
|
||
|
followed by another character.<tt> </tt>
|
||
|
Examples:
|
||
|
<dl><dt><dd>
|
||
|
<pre>
|
||
|
(parse-expression "(2+8)/5" 0 #\u) => 2
|
||
|
(parse-expression "foo" #f #\u) => #f; prints warning
|
||
|
|
||
|
(parse-expression-rest "1+1" #f #\u) => (2 . "")
|
||
|
(parse-expression-rest "(2+8)/5foo" 0 #\u) => (2 . "foo")
|
||
|
(parse-expression-rest "15\&-" 0 #\u) => (15 . "\&-")
|
||
|
</pre>
|
||
|
</dl>
|
||
|
<h2>
|
||
|
(char-expression-delimiter? <i>char</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>Returns #t if the character argument
|
||
|
<i>char
|
||
|
</i>is valid as the first character of a numeric expression (e.g. a digit),
|
||
|
otherwise #f.<tt> </tt>
|
||
|
<h2>
|
||
|
(set-scaling! <i>scale</i> <i>factor</i> <i>divisor</i>)
|
||
|
<br>
|
||
|
(get-scaling <i>scale</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>These primitives set and read the scale factor and divisor for
|
||
|
the specified scale indicator.<tt> </tt>
|
||
|
<i>scale
|
||
|
</i>is the scale indicator (a character);
|
||
|
<i>factor
|
||
|
</i>and
|
||
|
<i>divisor
|
||
|
</i>are integers.<tt> </tt>
|
||
|
<i>get-scaling
|
||
|
</i>returns the scaling for the specified scale indicator as a pair
|
||
|
of integers.<tt> </tt>
|
||
|
The factors and divisors are initially set to 1 for all scale
|
||
|
indicators; they must be assigned useful values by each back-end.<tt> </tt>
|
||
|
<p><hr>
|
||
|
Markup created by <em>unroff</em> 1.0, <tt> </tt> <tt> </tt>March 21, 1996, <tt> </tt> <tt> </tt>net@informatik.uni-bremen.de</body>
|
||
|
</html>
|