File: parser.h

package info (click to toggle)
flexc%2B%2B 2.17.01-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,180 kB
  • sloc: cpp: 6,467; makefile: 148; sh: 130; ansic: 18
file content (115 lines) | stat: -rw-r--r-- 3,557 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Generated by Bisonc++ V2.09.04 on Mon, 16 Jan 2012 21:40:37 +0100

#ifndef Parser_h_included
#define Parser_h_included

#include <string>

#include "../state/state.h"
#include "../block/block.h"
#include "../options/options.h"

// $insert baseclass
#include "parserbase.h"
// $insert scanner.h
#include "../scanner/scanner.h"

class States;
class Rules;

#undef Parser
class Parser: public ParserBase, public FlexTypes
{
    using Pair = std::pair<size_t, size_t>;

    Options &d_options;

    // $insert scannerobject
    Scanner d_scanner;
    std::string const &d_matched;   // text matched at the last lex() call.
    std::string d_rawStringContent;    // only valid when RAWSTRING was
                                        // returned 
    Block   d_block;

    bool d_nlAtEOF          = false;    // lex.cc: compensate missing final \n
    bool d_boln             = false;    // rule starts at boln
    bool d_doError          = true;     // use the error() function at ERRORs
    bool d_warnCarets       = false;    // carets in a RE
    bool d_warnDollars      = false;    // dollars in a RE
    bool d_usesLOP          = false;    // true while inside a regex using the
                                        // LOP: see lookahead.cc
    bool d_nullMatchingRules = false;
    bool d_printTokens;

    size_t d_parentheses = 0;
    size_t d_tokenCount = 0;
    size_t d_atEOF          = 0;        // counts 0-tokens in sequence

    std::string d_expect;

    Rules &d_rules;
    States &d_states;

    size_t d_nLOPstartConditions;           // startconditions index for 
                                            // the next LOP, initialized in
                                            // 'grammar'

    static int s_ignoreToken;
    static std::string s_lastMsg;

    public:
        Parser(Rules &rules, States &states);
        int parse();
        void addLopStartConditions();
        void cleanup();     // prepare Mstream tags, define accessor variables
                            // and show filenames
    private:
        FPattern eolnDollar();

        void orAction();    // sets the action of the last rule but one to 
                            // the last rule's action

        void reset();       // prepare the parser for a new regex 
                            // (resetting tokencount and warning flags)

        FPattern boln();
        FPattern dollar();
        FPattern quotes();
        FPattern lookahead(FPattern const &left, FPattern const &right);
        FPattern interval(FPattern &regex, Interval const &interval);

        FPattern escape();                                   // .ih
        FPattern str();                                      // .ih
        FPattern rawText();                                  // .ih
        FPattern rawText(std::string const &str);            // .ih

        void assignBlock();
        void noActions();

        void addRule(FPattern const &rule, bool resetMs = false);

        TextType rawString();           // returns the raw string content

        void block();
        void error();                   // called on (syntax) errors
        int lex();                      // returns the next token from the
                                        // lexical scanner. 
        void print();  

    // support functions for parse():
        void executeAction_(int ruleNr);
        void errorRecovery_();
        void nextCycle_();
        void nextToken_();
        void print_();
        void exceptionHandler(std::exception const &exc);
};

#endif