ScannerClass class

From Axaptapedia

Jump to: navigation, search

[edit] Introduction

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++

[edit] Usage

  • 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)


[edit] Example

#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();
    }

download (4k) more extended example with comments handling

Personal tools