Tasks related to input processing



Some processors need to insert the content of an arbitrary file at
a specific point in the input text currently being processed.
For example, consider the C preprocessor cpp , where the file inclusion
command #include "myfile" inserts the content of file myfile
at the position of that command in the input text.
The Eli Include module supports such a requirement.
It can be instantiated without generic parameters by
$/Input/Include.gnrc :inst
The Include module exports the token processor InclDirective
(see Token Processors of Lexical analysis specification),
allowing the developer to implement a file inclusion
command as a lexical token
(see Lexical analysis specification).
To implement the cpp file inclusion command as a lexical token,
we add a scanner specification
(see Specifications of Lexical analysis specification)
to a type-gla file:
$#include\040+\" (auxEOL) [InclDirective]
This scanner specification begins with the regular expression
#include\040+\" , which matches the beginning of the command
(see Regular Expressions of Lexical analysis specification).
This regular expression requires at least one space to follow the
word include , but allows more spaces to precede the string
giving the file name.
The last character of the regular expression is the delimiter of the file
name string.
The auxiliary scanner auxEOL
(see Auxiliary Scanners of Lexical analysis specification)
advances the input pointer beyond the end of
the line of text containing the command
(see Available scanners of Lexical analysis specification).
This advance is vital, since the input file can only be changed at
a line break.
The token processor InclDirective
(see Token Processors of Lexical analysis specification)
is exported by the Include module.
It first extracts mark , the last character matched by the
regular expression (in our case, mark is " ).
If mark is < , InclDirective assumes that the
form of the string is <...> ; otherwise it assumes that the
string is delimited by mark characters.
Given the above assumption, InclDirective scans the text following
the text matching the regular expression for the terminating delimiter.
When the scan reaches a space, the terminating delimiter,
or the end of the line, the file name is taken as the sequence
of scanned characters up to, but not
including, that space, terminating delimiter, or end-of-line.
The module produces a warning if the terminating delimiter is end-of-line.
Finally, InclDirective seeks the specified file and switches the
input pointer to that file, if it can be opened.
When the end of that file is reached, the input pointer returns to the file
containing the file inclusion command, at the beginning of the line
following that command.
If the specified file cannot be opened, an operating system report is
issued and further input is take from the current file.
Recall that the lexical token was specified as:
$#include\040+\" (auxEOL) [InclDirective]
This specification identifies the lexical token as a comment rather
than a basic symbol
(see Lexical analysis specification).
Because it is a comment, it can be used wherever a comment is allowed in
the source text.
It may be that the developer wishes to restrict file insertion to specific
grammatical constructs.
In that case, the lexical token should be identified as a basic symbol by
giving it a name:
Insertion: $#include\040+\" (auxEOL) [InclDirective]
The basic symbol name Insertion can then be used in the grammar just
as any basic symbol name.
Incorrectly-placed insertion points will be reported as syntax
errors, but the contents of the files specified by the insertion
commands will still be inserted at the specified points.



|