summaryrefslogtreecommitdiff
path: root/new/sch_sweet_parser.h
blob: d5424f936e828d626e9193abab91052f6770f1ba (plain)
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
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 2010 KiCad Developers, see change_log.txt for contributors.
 *
 * This program 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 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

#ifndef SCH_SWEET_PARSER_H_
#define SCH_SWEET_PARSER_H_

#include <utf8.h>
#include <sweet_lexer.h>


typedef int     STROKE;

namespace SCH {

class LIB_TABLE;
class PART;
class POINT;


// GRAPHICS
class POLY_LINE;
class RECTANGLE;
class CIRCLE;
class ARC;
class BEZIER;
class GR_TEXT;
class PIN;
class FONT;
class PROPERTY;

struct PINTEXT;
struct TEXT_EFFECTS;


/**
 * Class SWEET_PARSER
 * scans a Sweet string as input and stuffs a PART.
 * <p>
 * Most functions in this class throw IO_ERROR and PARSE_ERROR.  The IO_ERROR can
 * happen if there is difficulty reading the input stream.
 */
class SWEET_PARSER : public SWEET_LEXER
{
    LIB_TABLE*      libs;
    int             contains;       // separate from PART::contains until done
                                    // so we can see what we inherited from base PART

    // all these private functions rely on libs having been set via the public API, Parse( PART*)

    void parseExtends( PART* me );

    void parsePolyLine( POLY_LINE* me );
    void parseBezier( BEZIER* me );
    void parseRectangle( RECTANGLE* me );
    void parseCircle( CIRCLE* me );
    void parseArc( ARC* me );
    void parseText( GR_TEXT* me );
    void parseAt( POINT* pos, float* angle );
    void parseBool( bool* aBool );
    void parseFont( FONT* me );
    void parsePinText( PINTEXT* me );
    void parseTextEffects( TEXT_EFFECTS* me );
    void parseKeywords( PART* me );
    void parseAlternates( PART* me );
    void parsePropertyDel( PART* me );

    void parsePin( PIN* me );
    void parsePinDel( PART* me );
    void parsePinSwap( PART* me );
    void parsePinRenum( PART* me );
    void parsePinRename( PART* me );
    void parsePinMerge( PART* me );
    void parseStroke( STROKE* me );

public:

    /**
     * Constructor SWEET_PARSER
     * takes aSweet string and gets ready to parse it.
     * @param aSweet is the full description of a PART.
     * @param aSource is used in error reporting and describes where the Sweet
     *  string came from in any appropriate way.
     */
    SWEET_PARSER( const STRING& aSweet, const wxString& aSource = wxEmptyString ) :
        SWEET_LEXER( aSweet, aSource ),
        libs( 0 ),
        contains( 0 )
    {
    }

    SWEET_PARSER( LINE_READER* aLineReader ) :
        SWEET_LEXER( aLineReader ),
        libs( 0 ),
        contains( 0 )
    {
    }

    /**
     * Function Parse
     * stuffs @a aPart with data from this SWEET_LEXER, which has its own
     * sweet string source.
     * @param aPart is what is to be stuffed.
     * @param aTable is the view of the LIBs in play.
     */
    void Parse( PART* aPart, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_ERROR );
};

} // namespace SCH

#endif  // SCH_SWEET_PARSER_H_