FreeCAD

Форк
0
/
tokrules.py 
141 строка · 3.6 Кб
1
# -*- coding: utf8 -*-
2

3
#***************************************************************************
4
#*   Copyright (c) 2012 Keith Sloan <keith@sloan-home.co.uk>               *
5
#*                                                                         *
6
#*   This program is free software; you can redistribute it and/or modify  *
7
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
8
#*   as published by the Free Software Foundation; either version 2 of     *
9
#*   the License, or (at your option) any later version.                   *
10
#*   for detail see the LICENCE text file.                                 *
11
#*                                                                         *
12
#*   This program is distributed in the hope that it will be useful,       *
13
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
#*   GNU Library General Public License for more details.                  *
16
#*                                                                         *
17
#*   You should have received a copy of the GNU Library General Public     *
18
#*   License along with this program; if not, write to the Free Software   *
19
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
#*   USA                                                                   *
21
#*                                                                         *
22
#***************************************************************************
23
__title__ = "FreeCAD OpenSCAD Workbench - CSG importer Version 0.5c"
24
__author__ = "Keith Sloan <keith@sloan-home.co.uk>"
25
__url__ = ["http://www.sloan-home.co.uk/ImportCSG"]
26

27
# Reserved words
28
reserved = (
29
    'group',
30
    'sphere',
31
    'cylinder',
32
    'cube',
33
    'multmatrix',
34
    'intersection',
35
    'difference',
36
    'union',
37
    'rotate_extrude',
38
    'linear_extrude',
39
    'true',
40
    'false',
41
    'circle',
42
    'square',
43
    'text',
44
    'polygon',
45
    'paths',
46
    'points',
47
    'undef',
48
    'polyhedron',
49
    'triangles',
50
    'faces',
51
    'render',
52
    'surface',
53
    'subdiv',
54
    'glide',
55
    'hull',
56
    'minkowski',
57
    'projection',
58
    'import',
59
    'color',
60
    'offset',
61
    'resize',
62
    )
63

64
# List of token names.   This is always required
65
tokens = reserved + (
66
   'WORD',
67
   'NUMBER',
68
   'LPAREN',
69
   'RPAREN',
70
   'OBRACE',
71
   'EBRACE',
72
   'OSQUARE',
73
   'ESQUARE',
74
   'COMMA',
75
   'SEMICOL',
76
   'EQ',
77
   'STRING',
78
   'ID',
79
   'DOT',
80
   'MODIFIERBACK',
81
   'MODIFIERDEBUG',
82
   'MODIFIERROOT',
83
   'MODIFIERDISABLE'
84
)
85

86
# Regular expression rules for simple tokens
87
t_WORD    = r'[$]?[a-zA-Z_]+[0-9]*'
88
t_NUMBER  = r'[-]?[0-9]*[\.]*[0-9]+([eE][+-]?[0-9]+)*'
89
t_LPAREN  = r'\('
90
t_RPAREN  = r'\)'
91
t_OBRACE  = r'{'
92
t_EBRACE  = r'\}'
93
t_OSQUARE = r'\['
94
t_ESQUARE = r'\]'
95
t_COMMA   = r','
96
t_SEMICOL = r';'
97
t_EQ      = r'='
98
t_DOT     = r'\.'
99
t_STRING  = r'"[^"]*"'
100
#t_STRING  = r'["]+[a-zA-Z.]+["]+'
101
t_MODIFIERBACK    = r'%'
102
t_MODIFIERDEBUG   = r'\#'
103
t_MODIFIERROOT    = r'!'
104
t_MODIFIERDISABLE = r'\*'
105
# Deal with Reserved words
106
reserved_map = { }
107
for r in reserved:
108
    reserved_map[r.lower()] = r
109

110

111
# Deal with Comments
112
def t_comment1(t):
113
    r'//[^\r\n]*((\r\n)|<<EOF>>)'
114
    pass
115

116

117
def t_comment2(t):
118
    r'//[^\n]*((\n)|<<EOF>>)'
119
    pass
120

121

122
def t_ID(t):
123
    r'[$]?[a-zA-Z_]+[0-9]*'
124
    t.type = reserved_map.get(t.value, "ID")
125
    return t
126

127

128
# Define a rule so we can track line numbers
129
def t_newline(t):
130
    r'\n+'
131
    t.lexer.lineno += len(t.value)
132

133

134
# A string containing ignored characters (spaces and tabs)
135
t_ignore = " \t\r"
136

137

138
# Error handling rule
139
def t_error(t):
140
    print("Illegal character '%s'" % t.value[0])
141
    t.lexer.skip(1)
142

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.