Axaptapedia is now maintained by AgileCadence For more information please click here.

ScannerClass class

From Axaptapedia
Jump to: navigation, search

Introduction[edit]

ScannerClass provides lexical parsing capabilities for X++.

You can perform such tasks as removing all comments from your code or find some keyword in your X++ source.

There is also ParserClass class providing interface to the syntax parsing for X++

Usage[edit]

  • Provide your X++ code as a constructor parameter.
  • include TokenTypes macro to handle various token types
  • call firstSymbol method to scan to the first token - return value is type of the first token
  • call nextSymbol method for further processing until it returns 0
  • subclass ScannerClass to handle comments (override comment and lineComment methods)


Example[edit]

<xpp>

   #TokenTypes
   int token;
   ScannerClass s=new  ScannerClass(
       "void /*test*/new(){int a=1.23;return \"my string\";}");
   ;
   token=s.firstSymbol();
   while(token)
   {
       info(strFmt("%1, %2: '%3', %4",
           s.line(),s.col(),
           s.string(), token==#DBL_SYM?s.realValue():0.0));
       token=s.nextSymbol();
   }

</xpp> download (4k) more extended example with comments handling