CParser


This module has been removed in release 14.0.0. Use Script module instead.

This class parses string into tokens.

You can find more information in comments below.

/*
    USAGE: 
        I. Scenario: 
            1. CParser parser; // Create parser 
            2. parser.SetJson(); // Set one of predefined modes 
            3. Use Parse() method to parse next token until nullptr is returned 
        II. Scenario: 
            1. CParser parser; // Create parser 
            2. Set language definition using setSymXXX() methods 
            3. Use setEscape(), setParseBin(), setParseOct(), setParseHex(), and setParseNumber() to set parsing functions if needed. You may use a number of predefined one(like ParseIntegerBinAsm) 
            4. Set whether parsing should be case sensitive or not using setCaseSensitive() method 
            6. Add required operators using AddOperator() method 
            7. Use Parse() method to parse next token until nullptr is returned 
            Note: steps 2-6 can be used in any order or ommited if default properties as good. You also may set mode and change properties after it 
    */
    class CParser
    {
    public:
        FEscape getEscape(); // Return assigned escape symbols parsing functions. Default nullptr 
        FParseInteger getParseBin(); // Return assigned binary numbers parsing function. Default nullptr 
        FParseInteger getParseOct(); // Return assigned octal numbers parsing function. Default nullptr 
        FParseInteger getParseHex(); // Return assigned hexadecimal numbers parsing function. Default nullptr 
        FParseNumber getParseNumber(); // Return assigned floating point and integer numbers parsing function. Default nullptr 
        bool isCaseSensitive() const; // Return whether parsing should be case sensitive or insensitive 
        const String &getSymSpace() const; // Return space symbols list 
        const String &getSymNewLine() const; // Return new line symbols list 
        const String &getSymIdentifier() const; // Return symbols allowed in identifiers 
        const String &getSymIdentifierNoStart() const; // Return symbols identifiers should not start from 
        const String &getSymIdentifierNoAll() const; // Return symbols which shouldn't be the only ones in identifiers 
        int getOperatorCount() const; // Return added operator count 
        const TOKEN_OPERATOR *getOperator(const int index); // Return operator by index 
    
        bool setEscape(FEscape value); // Set escape symbols parsing function 
        bool setParseBin(FParseInteger value); // Set binary numbers parsing function 
        bool setParseOct(FParseInteger value); // Set octal numbers parsing function 
        bool setParseHex(FParseInteger value); // Set hexadecimal numbers parsing function 
        bool setParseNumber(FParseNumber value); // Set floating point and integer numbers parsing function 
        bool setCaseSensitive(const bool value); // Set whether parsing should be case sensitive or insensitive 
        bool setSymSpace(const String &value); // Set space symbols list 
        bool setSymNewLine(const String &value); // Set new line symbols list 
        bool setSymIdentifier(const String &value); // Set symbols allowed in identifiers 
        bool setSymIdentifierNoStart(const String &value); // Set symbols identifiers should not start from 
        bool setSymIdentifierNoAll(const String &value); // Set symbols which shouldn't be the only ones in identifiers 
    
        CParser(); // Constructor 
    
        void SetPascal(); // Set all settings to parse Pascal-like language source code 
        void SetPhp(); // Set all settings to parse PHP-like language source code 
        void SetCpp(); // Set all settings to parse C++-like language source code 
        void SetAsm(); // Set all settings to parse Assembler-like language source code 
        void SetJson(); // Set all settings to parse JSON format source code 
        void SetXml(); // Set all settings to parse XML format source code 
    
        bool AddOperator(const TOKEN_OPERATOR &value); // Add operator 
        bool DeleteOperator(const int index); // Delete operator by index 
        bool DeleteOperators(); // Delete all operators 
    
        /*
        Parse token 
        @param s String to be parsed 
        @param min Minimum position in string to be used. Usually 0 
        @param max Maximum position in string to be used. Usually s.length() - 1 
        @param index [in, out] Token parsing position 
        @return token if found or nullptr if index out of range [min, max] 
        */
        TOKEN *Parse(const String &s, const int min, const int max, int &index);
    
        /*
        Parse string from min to max 
        @param s String to be parsed 
        @param min Minimum position in string to be used. Usually 0 
        @param max Maximum position in string to be used. Usually s.length() - 1 
        @param skip_not_operators Whether to add or don't operators with flag ofNotOperator(spaces and new lines) to list 
        @return array of found tokens 
        */
        Tokens ParseAll(const String &s, const int min, const int max, const bool skip_not_operators);
    
        // Binary number parsing functions 
        static bool ParseIntegerBinAsm(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, long long &result); // Format: 1111111b 
        static bool ParseIntegerBinCpp(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, long long &result); // Format: 0b1111111 
    
        // Octal numbers parsing functions 
        static bool ParseIntegerOctAsm(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, long long &result); // Format: 7777o 
        static bool ParseIntegerOctCpp(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, long long &result); // Format: 07777 
    
        // Hexadecimal numbers parsing functions 
        static bool ParseIntegerHexAsm(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, long long &result); // Format: 0FFFF 
        static bool ParseIntegerHexCpp(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, long long &result); // Format: 0xFFFF 
        static bool ParseIntegerHexPascal(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, long long &result); // Format: $FFFF 
    
        // Floating point and integer numbers parsing function 
        static bool ParseNumber(const PARSER_OPTIONS &options, FGetChar get, const String &s, const int min, const int max, int &index, bool &is_int, long long &i, double &f); // Format: 1.2e-3 
    
        // Escape symbols parsing function 
        static int EscapeCpp(const String &s, const int max, const int index, FGetChar get_char); // C-like: \uXXXX & \x 
    };
Namespace: nitisa::scripting
Include: Nitisa/Modules/Scripting/Parser.h