File: parser.hh

package info (click to toggle)
packup 0.6-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 832 kB
  • sloc: cpp: 10,857; makefile: 111; sh: 6
file content (173 lines) | stat: -rw-r--r-- 5,656 bytes parent folder | download | duplicates (5)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/******************************************************************************\
 *    This file is part of packup.                                            *
 *                                                                            *
 *    packup is free software: you can redistribute it and/or modify          *
 *    it under the terms of the GNU General Public License as published by    *
 *    the Free Software Foundation, either version 3 of the License, or       *
 *    (at your option) any later version.                                     *
 *                                                                            *
 *    packup is distributed in the hope that it will be useful,               *
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *    GNU General Public License for more details.                            *
 *                                                                            *
 *    You should have received a copy of the GNU General Public License       *
 *    along with packup.  If not, see <http://www.gnu.org/licenses/>.         *            
\******************************************************************************/           
/* 
 * File:   parser_functions.h
 * Author: mikolas
 *
 * Created on August 10, 2010, 6:12 PM
 * Copyright (C) 2011, Mikolas Janota
 */

#ifndef PARSER_FUNCTIONS_H
#define	PARSER_FUNCTIONS_H

#ifdef PARS_DBG
#define PDBG(t) t
#else
#define PDBG(t)
#endif


#include <string>
#include <vector>
#include <assert.h>
#include <iostream>
#include <stdio.h>
#include "common_types.hh"
#include "collections.hh"
#include "PackageVersions.hh"
#include "package_version.hh"

using namespace version_operators;

using std::string;
using std::vector;
using std::cout;
using std::cerr;
using std::endl;
using std::exception;

class ReadException : public exception {
public:
    ReadException(char* str) : s(str) {};
    ~ReadException() throw()  { delete[] s; }
    const char* what() const throw() { return s; }    
private:
    char* s;
};



class Parser {
public:
    virtual ~Parser() {};
    /** Processing of a new package started.*/
    virtual void start_package() = 0;

    /** Processing of a package stopped.*/
    virtual void close_package() = 0;

    /**The version of currently processed package was read.*/
    virtual void end_processed_package_version() = 0;

    /** The package universe has been fully read.*/
    virtual void close_universe() = 0;

    /**The whole input was read.*/
    virtual void close_input () = 0;

    //Package stanza
    virtual void package_provides() = 0;
    virtual void package_conflicts() = 0; // A list of conflicting versions was read.
    virtual void package_depends() = 0;
    virtual void package_recommends() = 0;
    virtual void package_keep() = 0;
    virtual void package_installed(bool installed_value) = 0;

    //Request stanzas
    virtual void request_install() = 0;
    virtual void request_remove() = 0;
    virtual void upgrade() = 0;

    void package_versions_list_empty() {read_package_versions_list.clear();}

    void package_versions_list_first() {
        read_package_versions_list.clear();
        read_package_versions_list.push_back(read_package_versions);
    }

    void package_versions_list_next()
    {read_package_versions_list.push_back(read_package_versions);}

    void action_package_name(char* cname);
    
    void action_version_operator(Operator op) {read_operator=op;}

    Version action_version(char* version_string) {
        PDBG(cerr << "Version:" << (version_string) << endl;)
        const int r = sscanf(version_string, "%d", &read_version);
        if (r < 1) {
            static const char* ms = "Invalid version number: ";
            char* const message = new char [strlen(version_string)+strlen(ms)+1];
            strcpy(message, ms);
            strcat(message, version_string);
            delete[] version_string;
            throw ReadException(message);
        }
        delete[] version_string;        
        return read_version;
    }

    void action_package_versions() {
        read_package_versions = PackageVersions(
                read_package_name,
                read_operator,
                read_operator==VERSIONS_NONE?  0 : read_version);
    }
    
    void action_feature (){
        assert (read_operator==VERSIONS_EQUALS ||read_operator==VERSIONS_NONE);
        read_feature = PackageVersion (read_package_name,read_operator==VERSIONS_NONE?  0 : read_version);
    };

    void action_first_disjunction();
    void action_next_disjunction();
    void action_first_literal();
    void action_next_literal();
    void action_CNF_true();
    void action_CNF_false();

    void action_first_feature() {
        read_feature_list.clear ();
        read_feature_list.push_back(read_feature);
    }
    void action_next_feature(){
        read_feature_list.push_back(read_feature);
    }
    void action_empty_feature_list()
    {read_feature_list.clear();}

    void action_keep_value (KeepValue value){read_keep_value = value;}
protected:
    string read_package_name;
    Version read_version;
    Operator read_operator;
    KeepValue read_keep_value;
    vector <string> package_names;
    vector <string> feature_names;
    PackageVersions read_package_versions;
    PackageVersion read_feature;
    PackageVersionList read_feature_list;
    PackageVersionsCNF read_CNF;
    VersionsList* read_clause;
   
    VersionsList read_package_versions_list;
    Str2Str package_names_set;
};

#endif	/* PARSER_FUNCTIONS_H */