public class FileScope
extends java.lang.Object
Instances of this class serve scoping levels in a dictionary of scopes.
Preprocessor arguments are stored as mapped data. Both positional and
named arguments have names. These names are used as map keys. To avoid
key clashes between positional and named arguments, the names for
positional arguments are chosen to have a form that is never possible with
named arguments. Those names are "{N"
where N is the argument
position (from left to right). Simply using names like "N"
would be insufficient as those can be redefined like this:
{file &1=value}
etc. So, whenever a reference like
{1}
is encountered, it is mapped into the key
"{1"
.
At the time of the instance construction, the special Progress references
{*}
and {&*}
are also derived.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
allKeyArgs
All named arguments for Progress'
{&*} reference. |
private java.lang.String |
allPosArgs
All positional arguments for Progress'
{*} reference. |
private java.util.Map<java.lang.String,java.lang.String> |
args
Progress arguments to this file.
|
private java.nio.charset.Charset |
charset
The charset used for reading input streams.
|
private java.lang.String |
deferred
Text to be pushed back onto the stream after this scope is over.
|
private boolean |
explicitInput
Track which c'tor was used.
|
private java.lang.String |
fallbackName
Name of the file found during the fallback search.
|
private java.lang.String |
fileName
Name of the file to preprocess, exactly as specified.
|
private java.io.Reader |
input
Reader connected to this file.
|
(package private) int |
savedColumn
Saved column counter.
|
(package private) int |
savedLine
Saved line counter.
|
private boolean |
usedAllNamed
true when {&*} reference is used. |
private boolean |
usedAllPos
true when {*} reference is used. |
private java.util.Set<java.lang.String> |
usedArgs
Names of referenced arguments.
|
Constructor and Description |
---|
FileScope(java.lang.String fname,
java.util.Map<java.lang.String,java.lang.String> args,
Options options)
Constructor for an input file with arguments.
|
FileScope(java.lang.String fname,
java.io.Reader input)
Wrap an existing input stream for a scope that needs no arguments.
|
Modifier and Type | Method and Description |
---|---|
boolean |
attemptFallback(Environment env)
Attempt a fallback process to find the file and then open the input
source using the found filename.
|
void |
close()
Closes the input reader.
|
int |
copyNamedArguments(ScopedSymbolDictionary dictionary)
Copies named Progress arguments into the specified dictionary
as symbols.
|
private java.io.File |
findCaseInsensitively(java.lang.String filename,
Environment env)
Find a file on the file system using a case insensitive matching
algorithm.
|
java.lang.String |
getAllNamedArguments()
Returns a string representing all named Progress arguments
matching the Progress'
{&*} reference. |
java.lang.String |
getAllPositionalArguments()
Returns a string representing all positional Progress arguments
matching the Progress'
{*} reference. |
java.util.Map<java.lang.String,java.lang.String> |
getArguments()
Returns Progress arguments.
|
java.lang.String |
getDeferredPushback()
Obtain any text that must be pushed back onto the stream after this
scope is complete.
|
java.lang.String |
getFallbackName()
Returns the filename that was found during the fallback attempt.
|
java.io.File |
getFile()
Returns the embedded File object.
|
java.lang.String |
getFileName()
Returns the filename as was specified at creation.
|
private java.io.Reader |
getFileReader(java.lang.String fileName)
Creates a file reader instance with the current charset.
|
int |
getSavedColumn()
Gets the saved column counter.
|
int |
getSavedLine()
Gets the saved line counter.
|
java.io.Reader |
getStream()
Returns the opened stream.
|
boolean |
isAllNamedUsed()
Returns "all named arguments used" flag.
|
boolean |
isAllPosUsed()
Returns "all positional arguments used" flag.
|
boolean |
isArgUsed(java.lang.String name)
Checks if the argument was used.
|
private void |
normalizeArguments(java.util.Map<java.lang.String,java.lang.String> args)
Normalizes the naming of arguments in the given map and store them.
|
boolean |
open(java.lang.String[] paths,
Environment env)
Opens the input source using the previously specified file.
|
void |
setAllNamedUsed()
Marks all named arguments as used.
|
void |
setAllPosUsed()
Marks all positional arguments as used.
|
void |
setArgUsed(java.lang.String name)
Marks argument as used.
|
void |
setCharset(java.nio.charset.Charset charset)
Sets the charset used for reading input streams.
|
void |
setDeferredPushback(java.lang.String deferred)
Set any text that must be pushed back onto the stream after this
scope is complete.
|
void |
setSavedColumn(int savedColumn)
Saves the column counter.
|
void |
setSavedLine(int savedLine)
Saves the line counter.
|
java.lang.String |
toString()
Converts this object into a string.
|
int savedLine
int savedColumn
private java.lang.String fileName
{0}
argument reference.private java.io.Reader input
private java.util.Map<java.lang.String,java.lang.String> args
private java.lang.String allPosArgs
{*}
reference.private java.lang.String allKeyArgs
{&*}
reference.private java.util.Set<java.lang.String> usedArgs
private boolean usedAllPos
true
when {*} reference is used.private boolean usedAllNamed
true
when {&*} reference is used.private java.lang.String deferred
private java.lang.String fallbackName
private boolean explicitInput
private java.nio.charset.Charset charset
public FileScope(java.lang.String fname, java.io.Reader input)
Typically this is only used for the top level source file.
fname
- File name of this scope.input
- The reader to use as the input source.public FileScope(java.lang.String fname, java.util.Map<java.lang.String,java.lang.String> args, Options options)
File separators of fname
are replaced to match the
Java runtime's file separators. To recognize file separators of the
original fname
value, the passed in options
is inspected.
Positional arguments are those named in a special way so the names
never clash: "{N"
where N is the relative position from
left to right (starting at 1).
Named arguments have their regular names as specified in the source code of an include file reference.
The first argument in the sequence defines the form of the whole list.
If its name is "{1"
, the list is considered positional,
otherwise it is named.
A positional list is normalized to only have "{N"
names.
A named list is normalized to only have the original regular names plus
newly assigned positional names in the form "{N"
. This
enables named arguments to be referenced by a positional reference,
which is valid in Progress.
To guarantee that the order of the arguments as they appear in the
{*}
and {&*}
references is preserved, the
passed parameter must be an instance of LinkedHashMap
.
fname
- Source file to be preprocessed. Any UNIX
style
("/"
) file separator characters will be replaced
with the platform-specific separator character IF DIFFERENT.args
- Arguments.options
- The preprocessor options, must not be null
.public java.lang.String getFileName()
public java.lang.String getFallbackName()
null
if no fallback was attempted or if the
fallback attempt was not successfull.public java.io.File getFile()
File
object for this Progress source file.public java.io.Reader getStream()
null
if closed or never opened.public java.util.Map<java.lang.String,java.lang.String> getArguments()
Map
.
null
if no arguments were given.public int copyNamedArguments(ScopedSymbolDictionary dictionary)
dictionary
- symbol dictionary to which the named Progress arguments are
to be copiedpublic java.lang.String getAllPositionalArguments()
{*}
reference.public java.lang.String getAllNamedArguments()
{&*}
reference.public boolean open(java.lang.String[] paths, Environment env)
paths
- array of strings specifying paths to search for the file
or null
.env
- Preprocessor environment.true
if open succeeded.public boolean attemptFallback(Environment env)
open()
method fails. Only a unique match will be accepted.
The search algorithm walks all files under the basepath and if one and
only one file is found that ends with the filename we are searching
for, then that match is accepted.env
- Preprocessor environment.true
if open succeeded.public void close()
public void setSavedLine(int savedLine)
savedLine
- line number to be saved. Normally stores the current
line number within this file while an include file
reference is being processed.public int getSavedLine()
public void setSavedColumn(int savedColumn)
savedColumn
- column number to be saved. Normally stores the current
column number within this file while an include file
reference is being processed.public int getSavedColumn()
public void setArgUsed(java.lang.String name)
name
- argument namepublic boolean isArgUsed(java.lang.String name)
name
- argument nametrue
if the argument was usedpublic void setAllPosUsed()
public boolean isAllPosUsed()
public void setAllNamedUsed()
public boolean isAllNamedUsed()
public java.lang.String getDeferredPushback()
public void setDeferredPushback(java.lang.String deferred)
deferred
- Deferred pushback text.public void setCharset(java.nio.charset.Charset charset)
charset
- If null, the default JVM charset will be set to the instance.public java.lang.String toString()
toString
in class java.lang.Object
private java.io.File findCaseInsensitively(java.lang.String filename, Environment env)
filename
- Name of file to be found; case of file name and qualifying
path need not match the case of matching file(s) on the file
system.env
- Preprocessor environment (used to emit error/warning messages).filename
, or null
if no match
is found.private void normalizeArguments(java.util.Map<java.lang.String,java.lang.String> args)
A positional list is normalized to only have names in the form
"{N"
. Consider this include reference:
{ti.i p1 p2 &a="c" p3 &b=d p4}
In this example, the result would be normalized this way:
Name Value ------- ------- {1 p1 {2 p2 {3 a="c" {4 p3 {5 b="d" {6 p4
The corresponding {*}
reference would be
"p1 p2 c p3 d p4"
and {&*}
is empty.
A named list is normalized to only have the original regular
names plus one newly assigned corresponding "{N"
name for
each argument (including any duplicate named argument). This allows the
argument values to be referenced by either their names or by their
relative position such as {&1}
for the first named
argument. Note that duplicate named arguments (arguments where the
specified name appears more than once in the same argument list) are
handled as follows:
For example:
{ti.i &a="c" p1 p2 p3 &b=d p4}
This would produce:
Name Value ------- ------- a c b d {1 c {2 d
The corresponding {&*}
reference is
"&a=c &b=d"
and {*}
reference is
"c d"
.
To guarantee that the order of the arguments as they appear in the
{*}
and {&*}
references is preserved, the
passed parameter must be an instance of LinkedHashMap
.
args
- Include file arguments list. This list will store either named
or positional arguments. Positional arguments are those named
so the names never clash: "{N" where n is the argument number.
Named arguments have their explicitly provided name without
the ampersand. It is not valid to have both except in the
special case where there is a duplicate named argument. In
that case there will be a positional argument placeholder so
that the full positional argument list and the all arguments
list will contain the value of the duplicated name even though
the matching named argument never had its value overridden.
The first argument in the sequence defines the form of the
whole list. If its name is {1, the list is considered
positional, otherwise named.private java.io.Reader getFileReader(java.lang.String fileName) throws java.io.FileNotFoundException
fileName
- The file name.java.io.FileNotFoundException