Using XppScanner for lexical code parsing
Views (2127)
The XppScanner class allows to parse X++ code in the way compiler does it. The simplest way to use it is to traverse all symbols in the given source code using iteration methods – firstSymbol() and nextSymbol(). The integer values returned by these methods are enumerated in the TokenTypes macro. For example, to check if there is “ttsbegin” statement in the code the following job can be used:
public static boolean checkTTSBegin(str _source)
{
#TokenTypes
XppScanner xppScanner = new XppScanner(_source);
int symbol;
for (symbol = xppScanner.firstSymbol(); symbol; symbol = xppScanner.nextSymbol())
{
if (symbol == #TTSBEGIN_SYM)
{
return true;
}
}
return false;
}
PS. For this particular task you can, of course, use XppScanner.find() method.
public static boolean checkTTSBegin(str _source)
{
#TokenTypes
XppScanner xppScanner = new XppScanner(_source);
int symbol;
for (symbol = xppScanner.firstSymbol(); symbol; symbol = xppScanner.nextSymbol())
{
if (symbol == #TTSBEGIN_SYM)
{
return true;
}
}
return false;
}
PS. For this particular task you can, of course, use XppScanner.find() method.
This was originally posted here.
*This post is locked for comments