|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.joanju.ProparseLdr
public class ProparseLdr
Primary JNI interface to proparse.dll. Is a "Singleton". Create a reference to this in order to refer to the parser and its API.
Method Summary | |
---|---|
int |
attrGetI(int handle,
int key)
Returns the integer value of a node attribute. |
java.lang.String |
attrGetS(int handle,
java.lang.String key)
Returns the string value of a node attribute. |
int |
attrSet(int handle,
int key,
int val)
Sets a node's attribute. |
java.lang.String |
attrStringGet(int handle,
int key)
Returns the string value of an integer-keyed node attribute. |
int |
attrStringSet(int handle,
int key,
java.lang.String val)
Sets a string attribute on a node. |
int |
cleanup()
Not currently used. |
java.lang.String |
configGet(java.lang.String flag)
Returns a configuration value. |
int |
configSet(java.lang.String flag,
java.lang.String val)
Sets a configuration value. |
int |
copyHandle(int fromHandle,
int toHandle)
Copies a pointer to a node, the result being that toHandle now points to the same node as fromHandle. |
int |
dictAdd(java.lang.String theText,
java.lang.String theType)
Adds a user string literal to the user node types dictionary. |
int |
dictDelete(java.lang.String theText)
Removes a string literal from the user node types dictionary. |
java.lang.String |
diff(java.lang.String file1,
java.lang.String file2)
Trivially finds differences between two files. |
int |
errorClear()
Resets Proparse's error status to zero and clears out the warning/error text. |
int |
errorGetIsCurrent()
Use this function to find out if the current error status is current. |
int |
errorGetStatus()
Get the parser's error status. |
java.lang.String |
errorGetText()
If there is an error condition in Proparse, then this returns the error message. |
java.lang.String[] |
getFilenameArray()
Deprecated. May,2006. The new "filename-list" node attribute is used when the tree is loaded into JPNode, and the filename array is stored in the ProgramRootNode object. |
int |
getHandle()
Get a node handle. |
java.lang.String |
getIndexFilename(int index)
Deprecated. See the new "filename-list" node attribute in Proparse. |
static ProparseLdr |
getInstance()
This class is a "singleton" |
int |
getNodeColumn(int handle)
Get the column position of a node's original text. |
int |
getNodeFileIndex(int handle)
Get the file index for a given node. |
java.lang.String |
getNodeFilename(int handle)
If the node represents an actual source code token, then this function returns the name of the source file where the token was found. |
int |
getNodeLine(int handle)
If the node represents an actual source code token, then this function returns the line number within the source file where the token was found. |
java.lang.String |
getNodeText(int handle)
Returns the original source code for the given node's token. |
java.lang.String |
getNodeType(int handle)
Returns the type of the given node's token. |
int |
getNodeTypeI(int handle)
Returns the integer type of the given node's token. |
java.lang.String |
getTokenTypeName(int tokenTypeNumber)
Returns the token type name of the given token type number. |
int |
getTokenTypeNumber(java.lang.String tokenTypeName)
Returns the token type number of the given token type name. |
java.lang.String |
getVersion()
Returns the version of proparse.dll. |
int |
hiddenAddToFront(int theHandle,
java.lang.String newType,
java.lang.String newText)
Creates a new hidden token with type newType and text newText ,
and makes this token the first hidden token of theHandle . |
int |
hiddenDelete(int theHandle)
Deletes the current hidden token of theHandle . |
int |
hiddenGetBefore(int handle)
Sets the current hidden token to be the hidden token that comes before the node referred to by the input handle. |
int |
hiddenGetColumn()
This function returns the column position within the source file where the current hidden token was found. |
java.lang.String |
hiddenGetFilename()
Returns the name of the source file where the current hidden token came from. |
int |
hiddenGetFirst(int handle)
Sets the current hidden token to be the first hidden token that comes before the node referred to by the input handle. |
int |
hiddenGetLine()
Returns the line number within the source file where the current hidden token came from. |
int |
hiddenGetNext()
Finds the next hidden token after the current hidden token, then sets the current hidden token to be that newly found one. |
int |
hiddenGetPrevious()
Finds the hidden token previous to the current hidden token, then sets the current hidden token to be that newly found one. |
java.lang.String |
hiddenGetText()
Returns the text of the current hidden token. |
java.lang.String |
hiddenGetType()
Returns the type of the current hidden token, for example "WS" for whitespace, or "COMMENT". |
int |
hiddenInsertAfter(java.lang.String newType,
java.lang.String newText)
Creates a new hidden token of the given type and text and inserts it after the current hidden token. |
int |
hiddenSetText(java.lang.String newText)
Sets the text of the current hidden token to newText . |
int |
hiddenSetType(java.lang.String newType)
Sets the type of the current hidden token to newType . |
int |
init()
Not currently used. |
int |
isSameNode(int handle1,
int handle2)
Compares the node for handle1 with the node for handle2 ,
and returns 1 if the handles refer to the same node or returns 0 if they don't. |
int |
isValidNode(int handle)
Checks the node for theHandle , and returns true if the handle refers
to a valid node or returns false if the node isn't valid. |
java.lang.String |
iwdiff(java.lang.String file1,
java.lang.String file2)
Used by testrun2.p to check that the output from compile with
preprocess is the same as the output from the parser. |
static java.lang.String |
loadUsing(java.lang.String fullpath)
Try to load proparse.dll using a fully qualified path/filename. |
int |
nodeCreate(int intoHandle,
java.lang.String newType,
java.lang.String newText)
Creates a new node of type newType , with text newText ,
and places the handle of this new node into the intoHandle . |
int |
nodeCreateI(int intoHandle,
int newType,
java.lang.String newText)
Creates a new node of integer type newType (which does not have to
be a valid node type), with text newText , and places the handle
of this new node into the intoHandle . |
java.lang.String |
nodeFirstChild(int ofHandle,
int intoHandle)
A handle to the first child of ofHandle is stored in
intoHandle . |
int |
nodeFirstChildI(int ofHandle,
int intoHandle)
A handle to the first child of ofHandle is stored in
intoHandle . |
java.lang.String |
nodeNextSibling(int ofHandle,
int intoHandle)
A handle to the next sibling of ofHandle is stored in
intoHandle . |
int |
nodeNextSiblingI(int ofHandle,
int intoHandle)
A handle to the next sibling of ofHandle is stored in
intoHandle . |
java.lang.String |
nodeParent(int ofHandle,
int intoHandle)
A handle to the parent of ofHandle is stored in
intoHandle . |
java.lang.String |
nodePrevSibling(int ofHandle,
int intoHandle)
A handle to the previous sibling of ofHandle is stored in
intoHandle . |
java.lang.String |
nodeStateHead(int ofHandle,
int intoHandle)
A handle to the statement head node of ofHandle is stored in
intoHandle . |
java.lang.String |
nodeTop(int handle)
Stores a reference to the topmost node in the node handle intoHandle . |
int |
parse(java.lang.String filename)
Parses the program file specified by filename . |
int |
parseCreate(java.lang.String parseType,
java.lang.String fileName)
Causes Proparse to scan filename and create a scanner result set. |
int |
parseDelete(int parseNum)
Deletes the parse number parseNum created by
parserParseCreate . |
int |
parseGetTop(int parseNum,
int nodeHandle)
Finds the top (first) node from parse (or scan) result parseNum
and causes handle intoHandle to refer to that node. |
int |
queryClear(java.lang.String queryName)
Clears the named query. |
int |
queryCreate(int theNode,
java.lang.String theQueryName,
java.lang.String theType)
Creates a named query. |
int |
queryGetResult(java.lang.String theQueryName,
int resultNum,
int intoHandle)
Sets the handle intoHandle to point to the node referred to
by result number resultNum in the query queryName . |
int |
releaseHandle(int theHandle)
Releases a node handle for re-use. |
int |
schemaAddDb(java.lang.String name)
Adds a name to Proparse's list of database names. |
int |
schemaAddTable(java.lang.String name)
Adds a table name to the last added database name. |
int |
schemaAliasCreate(java.lang.String aliasname,
java.lang.String dbname)
If your program requires a database alias to exist before it will compile, then you must use this function to tell Proparse about your database alias before that program can be parsed. |
int |
schemaAliasDelete(java.lang.String aliasname)
Use this function to delete an alias that you created with parserSchemaAliasCreate . |
int |
schemaClear()
Use this function if you want to clear the old schema names out of Proparse and load a new list of schema names into Proparse. |
int |
schemaOldLoad()
Not used. |
int |
setNodeFirstChild(int parentHandle,
int childHandle)
Sets the childHandle node to be the first child node
of the parentHandle , displacing the former
first child node. |
int |
setNodeNextSibling(int ofHandle,
int sibHandle)
Sets the sibHandle node to be the next sibling node
of the ofHandle , displacing the former next sibling node. |
int |
setNodeText(int theNode,
java.lang.String theText)
Sets the ofHandle node's text in the tree to the newText . |
int |
setNodeType(int theNode,
java.lang.String theType)
Sets the node's type in the tree to theType . |
int |
setNodeTypeI(int theNode,
int theType)
Sets the node's type. |
int |
writeNode(int theNode,
java.lang.String filename)
Given an input node handle, parserWriteNode
writes the text from that node and all of its
child nodes, out to the text file filename . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static ProparseLdr getInstance()
public static java.lang.String loadUsing(java.lang.String fullpath)
public java.lang.String[] getFilenameArray()
ParseUnit.getFileIndex()
public int attrGetI(int handle, int key)
handle
- key
- The integer representation of the attribute key.
public java.lang.String attrGetS(int handle, java.lang.String key)
public int attrSet(int handle, int key, int val)
handle
- The node's handle.key
- The attribute key.val
- The attribute value.
public java.lang.String attrStringGet(int handle, int key)
parserAttrStringSet
public int attrStringSet(int handle, int key, java.lang.String val)
parserAttrStringGet
public int cleanup()
public java.lang.String configGet(java.lang.String flag)
public int configSet(java.lang.String flag, java.lang.String val)
public int copyHandle(int fromHandle, int toHandle)
public int dictAdd(java.lang.String theText, java.lang.String theType)
theText
- The string literal to add.theType
- Must be a valid Proparse node type.
public int dictDelete(java.lang.String theText)
theText
- The string literal to remove.
public java.lang.String diff(java.lang.String file1, java.lang.String file2)
public int errorClear()
public int errorGetIsCurrent()
public int errorGetStatus()
public java.lang.String errorGetText()
public int getHandle()
public java.lang.String getIndexFilename(int index)
index
- The file index
getNodeFileIndex(int)
,
getNodeFilename(int)
public int getNodeColumn(int handle)
public int getNodeFileIndex(int handle)
handle
- The node handle
getNodeFilename(int)
public java.lang.String getNodeFilename(int handle)
public int getNodeLine(int handle)
public java.lang.String getNodeText(int handle)
public java.lang.String getNodeType(int handle)
public int getNodeTypeI(int handle)
parserSetNodeTypeI
public java.lang.String getTokenTypeName(int tokenTypeNumber)
parserGetTokenTypeNumber
public int getTokenTypeNumber(java.lang.String tokenTypeName)
parserGetTokenTypeName
public java.lang.String getVersion()
public int hiddenAddToFront(int theHandle, java.lang.String newType, java.lang.String newText)
newType
and text newText
,
and makes this token the first hidden token of theHandle
.
It also becomes the current hidden token.
See also Modifying Hidden Tokens in the User Guide.
theHandle
- newType
- newText
-
public int hiddenDelete(int theHandle)
theHandle
.
If there is a "next" hidden token, it becomes the current hidden token.
Otherwise, if there is a "previous" hidden token,
it becomes the current hidden token.
If this was the last hidden token of theHandle
,
there is no current hidden token.
See also Modifying Hidden Tokens in the User's Guide.
public int hiddenGetBefore(int handle)
public int hiddenGetColumn()
public java.lang.String hiddenGetFilename()
public int hiddenGetFirst(int handle)
public int hiddenGetLine()
public int hiddenGetNext()
public int hiddenGetPrevious()
public java.lang.String hiddenGetText()
public java.lang.String hiddenGetType()
public int hiddenInsertAfter(java.lang.String newType, java.lang.String newText)
public int hiddenSetText(java.lang.String newText)
newText
.
See also Modifying Hidden Tokens.
public int hiddenSetType(java.lang.String newType)
newType
.
Valid values are "WS" for whitespace, or "COMMENT". Returns true on success.
See also parserHiddenGetType and Modifying Hidden Tokens in the User Guide.
public int init()
public int isSameNode(int handle1, int handle2)
handle1
with the node for handle2
,
and returns 1 if the handles refer to the same node or returns 0 if they don't.
Returns negative number on error.
public int isValidNode(int handle)
theHandle
, and returns true if the handle refers
to a valid node or returns false if the node isn't valid.
public java.lang.String iwdiff(java.lang.String file1, java.lang.String file2)
testrun2.p
to check that the output from compile with
preprocess is the same as the output from the parser.
Originally named as "Ignore Whitespace diff",
it does less ignoring whitespace now,
and does much more to compensate for the way that Progress's preprocessor
writes out preprocessed code.
file1
- The COMPILE..PREPROCESS outputfile2
- The output from Proparse (usually just from
the writenode
function)
public int nodeCreate(int intoHandle, java.lang.String newType, java.lang.String newText)
newType
, with text newText
,
and places the handle of this new node into the intoHandle
.
See also "Tree Manipulation and Code Refactoring"
and its subsection
"Creating Nodes" (in the User Guide)
for further information, including how to find valid node types for this function.
public int nodeCreateI(int intoHandle, int newType, java.lang.String newText)
newType
(which does not have to
be a valid node type), with text newText
, and places the handle
of this new node into the intoHandle
.
See also "Tree Manipulation and Code Refactoring"
and its subsection
"Creating Nodes" (in the User Guide)
for further information, including how to find valid node types for this function.
public java.lang.String nodeFirstChild(int ofHandle, int intoHandle)
ofHandle
is stored in
intoHandle
.
If there is no first child, intoHandle
is not changed.
The same handle may be used for
both ofHandle
and intoHandle
, with the effect
of moving the handle from one node to the next.
""
if ofHandle
has no first child, otherwise, the found node's type is returned.public int nodeFirstChildI(int ofHandle, int intoHandle)
ofHandle
is stored in
intoHandle
.
If there is no first child, intoHandle
is not changed.
The same handle may be used for both ofHandle
and
intoHandle
, with the effect of moving the handle from one node to the next.
ofHandle
has no first child, otherwise, the found node's integer node type is returned.public java.lang.String nodeNextSibling(int ofHandle, int intoHandle)
ofHandle
is stored in
intoHandle
.
If there is no next sibling, intoHandle
is not changed.
The same handle may be used for
both ofHandle
and intoHandle
, with the effect
of moving the handle from one node to the next.
""
if ofHandle
has no next sibling, otherwise, the found node's type is returned.public int nodeNextSiblingI(int ofHandle, int intoHandle)
ofHandle
is stored in
intoHandle
.
If there is no next sibling, intoHandle
is not changed.
The same handle may be used for
both ofHandle
and intoHandle
, with the effect
of moving the handle from one node to the next.
ofHandle
has no next sibling, otherwise, the found node's type is returned.public java.lang.String nodeParent(int ofHandle, int intoHandle)
ofHandle
is stored in
intoHandle
.
If there is no parent, intoHandle
is not changed.
The same handle may be used for
both ofHandle
and intoHandle
, with the effect
of moving the handle from one node to the next.
""
if ofHandle
has no parent, otherwise, the found node's type is returned.public java.lang.String nodePrevSibling(int ofHandle, int intoHandle)
ofHandle
is stored in
intoHandle
.
If there is no previous sibling, intoHandle
is not changed.
The same handle may be used for
both ofHandle
and intoHandle
, with the effect
of moving the handle from one node to the next.
""
if ofHandle
has no previous sibling, otherwise, the found node's type is returned.public java.lang.String nodeStateHead(int ofHandle, int intoHandle)
ofHandle
is stored in
intoHandle
.
If there is no statement head node, intoHandle
is not changed.
The same handle may be used for
both ofHandle
and intoHandle
, with the effect
of moving the handle from one node to the next.
parserNodeStateHead
may be used iteratively to move up/out through
nested blocks, all the way up to the outermost block.
For example, given the program
DO: DISPLAY "Hi!". END.
and starting at the QSTRING "Hi!" node,
the first call to parserNodeStateHead
would find the DISPLAY node.
The second call would find the DO node. A third call would not find another
statement head - blank would be returned, and intoHandle
would
not be changed.
""
if ofHandle
has no statement head node, otherwise, the found node's type is returned.public java.lang.String nodeTop(int handle)
intoHandle
.
The topmost node is always a special node of type Program_root
.
Unlike most nodes, the Program_root
node does not represent any
actual token from your program's source code.
"Program_root"
on success, or
""
on failure (i.e. if there is no syntax tree).public int parse(java.lang.String filename)
filename
.
If the parse failed, there will not be any syntax tree available to work with.
Your application is responsible for getting and dealing with the text of the
error message.
filename
-
public int parseCreate(java.lang.String parseType, java.lang.String fileName)
filename
and create a scanner result set.
parseType
- The only valid value for is "scan"
".fileName
- The name of the source file to "scan".
parserParseGetTop
and parserParseDelete
.public int parseDelete(int parseNum)
parseNum
created by
parserParseCreate
.
Also deletes all queries related to that scan result,
as well as all handles to nodes in that scan result.
public int parseGetTop(int parseNum, int nodeHandle)
parseNum
and causes handle intoHandle
to refer to that node.
public int queryClear(java.lang.String queryName)
public int queryCreate(int theNode, java.lang.String theQueryName, java.lang.String theType)
fromNode
node handle, evaluating
that node and all of its child nodes. A list of node references is created within
Proparse, one node reference for each node that is of the input
nodeType
. This function returns the number of results (the number
of node references that were added to the list). You reference this result
list with the function parserQueryGetResult
.
If a previous query of the same name exists, it is cleared out first.
parserQueryCreate(topNode, "myQuery", "first_where_line=" + STRING(myLine)).
first_where_line=
are only sensible and only
supported for scanner results.
theNode
- The topmost node to start from.theQueryName
- Your unique name for the query.theType
- The type of node to search for,
or "" for an "unfiltered" query (all nodes, flattened).
public int queryGetResult(java.lang.String theQueryName, int resultNum, int intoHandle)
intoHandle
to point to the node referred to
by result number resultNum
in the query queryName
.
theQueryName
- The name of a
query created with the function parserQueryCreate
.resultNum
- An integer between one and the number of results for that query.intoHandle
- A valid node handle, created with the function
parserGetHandle
.
public int releaseHandle(int theHandle)
public int schemaAddDb(java.lang.String name)
public int schemaAddTable(java.lang.String name)
public int schemaAliasCreate(java.lang.String aliasname, java.lang.String dbname)
public int schemaAliasDelete(java.lang.String aliasname)
parserSchemaAliasCreate
.
To delete all aliases, use an empty string as this function's argument (i.e.
parserSchemaAliasDelete("")
).
public int schemaClear()
public int schemaOldLoad()
public int setNodeFirstChild(int parentHandle, int childHandle)
childHandle
node to be the first child node
of the parentHandle
, displacing the former
first child node. Returns true on success.
Use 0 for childHandle
to indicate that there are no children.
This function doesn't change the relationships between the child
node and its own children, its siblings, or its
hidden nodes.
See also Tree Manipulation and Code Refactoring
subsection Moving Nodes in the User Guide.
public int setNodeNextSibling(int ofHandle, int sibHandle)
sibHandle
node to be the next sibling node
of the ofHandle
, displacing the former next sibling node.
Use 0 for sibHandle
to indicate that there is no next sibling.
This function doesn't change the relationships between the sibling
node and its own children, its own siblings, or its
hidden nodes.
See also Tree Manipulation and Code Refactoring
subsection Moving Nodes in the User Guide.
public int setNodeText(int theNode, java.lang.String theText)
ofHandle
node's text in the tree to the newText
.
For example, if the node type is "SUBSTRING", the
original source code that the node is related to may have been "substr".
Use of this function allows the value in the original source code
to be modified (when Proparse's tree is written out), for example to "SUBSTR".
public int setNodeType(int theNode, java.lang.String theType)
theType
.
For example, if the node type is "FIRST",
the node type may be changed to "LAST".
See also Tree Manipulation and Code Refactoring in the User Guide.
public int setNodeTypeI(int theNode, int theType)
public int writeNode(int theNode, java.lang.String filename)
parserWriteNode
writes the text from that node and all of its
child nodes, out to the text file filename
.
parserWriteNode
takes care of ensuring that operators
are written out with infix notation
rather than the operator prefix notation that you would normally see when
walking a tree. (i.e.: displays: 1 + 2 instead of: + 1 2).
See Syntax Trees for more
information about operator prefix notation from syntax trees.
parserWriteNode
writes code that looks similar to the
original source code by displaying the whitespace (hidden token) prior to
each node. See Hidden Tokens.
parserWriteNode
is a handy way to write out
nodes found in ad hoc queries.
For example, see examples/query_length.p.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |