pyemaps 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyemaps/COPYING +798 -0
- pyemaps/CifFile/CifFile_module.py +3117 -0
- pyemaps/CifFile/StarFile.py +2496 -0
- pyemaps/CifFile/TypeContentsParser.py +82 -0
- pyemaps/CifFile/YappsStarParser_1_0.py +289 -0
- pyemaps/CifFile/YappsStarParser_1_1.py +288 -0
- pyemaps/CifFile/YappsStarParser_2_0.py +369 -0
- pyemaps/CifFile/YappsStarParser_STAR2.py +382 -0
- pyemaps/CifFile/__init__.py +7 -0
- pyemaps/CifFile/drel/__init__.py +1 -0
- pyemaps/CifFile/drel/drel_ast_yacc.py +582 -0
- pyemaps/CifFile/drel/drel_lex.py +228 -0
- pyemaps/CifFile/drel/drel_runtime.py +126 -0
- pyemaps/CifFile/drel/parsetab.py +185 -0
- pyemaps/CifFile/drel/py_from_ast.py +628 -0
- pyemaps/CifFile/parsetab.py +185 -0
- pyemaps/CifFile/yapps3_compiled_rt.py +390 -0
- pyemaps/README.md +201 -0
- pyemaps/__config__.py +91 -0
- pyemaps/__init__.py +233 -0
- pyemaps/__main__.py +219 -0
- pyemaps/__version__.py +1 -0
- pyemaps/cdata/Aluminium.xtl +4 -0
- pyemaps/cdata/AluminiumOxide.xtl +5 -0
- pyemaps/cdata/Aluminium_FCC.xtl +4 -0
- pyemaps/cdata/BariumTitanate_180k.xtl +6 -0
- pyemaps/cdata/BariumTitanate_270k.xtl +7 -0
- pyemaps/cdata/BariumTitanate_Tetra.xtl +7 -0
- pyemaps/cdata/BiMnO3.xtl +27 -0
- pyemaps/cdata/Boron_Tetra.xtl +8 -0
- pyemaps/cdata/CadmiumSelenide_Hex.xtl +5 -0
- pyemaps/cdata/CadmiumSulfide_Cubic.xtl +5 -0
- pyemaps/cdata/CadmiumSulfide_Hex.xtl +5 -0
- pyemaps/cdata/Chromium_BCC.xtl +4 -0
- pyemaps/cdata/CoSb3_Skutterudite.xtl +5 -0
- pyemaps/cdata/CopperOxide.xtl +5 -0
- pyemaps/cdata/Copper_FCC.xtl +4 -0
- pyemaps/cdata/Cu2O_Cuprite.xtl +5 -0
- pyemaps/cdata/Diamond.xtl +4 -0
- pyemaps/cdata/ErbiumPyrogermanate.xtl +9 -0
- pyemaps/cdata/FePd_Tetra.xtl +5 -0
- pyemaps/cdata/FeS2_Pyrite.xtl +15 -0
- pyemaps/cdata/GalliumAntimonide.xtl +5 -0
- pyemaps/cdata/GalliumArsenide.xtl +5 -0
- pyemaps/cdata/GalliumNitride.xtl +5 -0
- pyemaps/cdata/Germanium.xtl +4 -0
- pyemaps/cdata/Gold_FCC.xtl +4 -0
- pyemaps/cdata/IndiumArsenide.xtl +5 -0
- pyemaps/cdata/LaMnO3.xtl +7 -0
- pyemaps/cdata/LeadZirconateTitanate.xtl +8 -0
- pyemaps/cdata/Li2MnO3.xtl +13 -0
- pyemaps/cdata/NaFeO2.xtl +6 -0
- pyemaps/cdata/Nb3Sn.xtl +5 -0
- pyemaps/cdata/Pentacene.xtl +39 -0
- pyemaps/cdata/Silicon.xtl +4 -0
- pyemaps/cdata/StrontiumTitanate.xtl +6 -0
- pyemaps/cdata/TelluriumDioxide.xtl +5 -0
- pyemaps/cdata/TinDioxide_RT.xtl +5 -0
- pyemaps/cdata/TitaniumDioxide_Anatase.xtl +5 -0
- pyemaps/cdata/TitaniumDioxide_Rutile.xtl +5 -0
- pyemaps/cdata/TungstenDiselenide.xtl +5 -0
- pyemaps/cdata/VanadiumDioxide_RT.xtl +6 -0
- pyemaps/cdata/ZincOxide.xtl +5 -0
- pyemaps/cdata/Zinc_HCP.xtl +4 -0
- pyemaps/cdata/ZirconiumNitride.xtl +5 -0
- pyemaps/cdata/limno2.xtl +6 -0
- pyemaps/crystals.py +1415 -0
- pyemaps/ddiffs.py +147 -0
- pyemaps/diffract/__init__.py +70 -0
- pyemaps/diffract/bloch_dec.py +779 -0
- pyemaps/diffract/csf_dec.py +242 -0
- pyemaps/diffract/dif_dec.py +519 -0
- pyemaps/diffract/dpgen_dec.py +175 -0
- pyemaps/diffract/mxtal_dec.py +201 -0
- pyemaps/diffract/powder_dec.py +137 -0
- pyemaps/diffract/stereo_dec.py +111 -0
- pyemaps/display.py +791 -0
- pyemaps/emcontrols.py +1017 -0
- pyemaps/errors.py +266 -0
- pyemaps/fileutils.py +1001 -0
- pyemaps/kdiffs.py +1221 -0
- pyemaps/license.txt +42 -0
- pyemaps/samples/adf.py +137 -0
- pyemaps/samples/al.img +0 -0
- pyemaps/samples/al_dpgen.py +57 -0
- pyemaps/samples/al_ediom.py +94 -0
- pyemaps/samples/convert_image.py +88 -0
- pyemaps/samples/dm_diff.py +225 -0
- pyemaps/samples/mask.im3 +0 -0
- pyemaps/samples/powder.py +51 -0
- pyemaps/samples/raw.img +0 -0
- pyemaps/samples/si_bloch.py +120 -0
- pyemaps/samples/si_constructor.py +51 -0
- pyemaps/samples/si_csf.py +59 -0
- pyemaps/samples/si_dif.py +134 -0
- pyemaps/samples/si_lacbed.py +59 -0
- pyemaps/samples/si_pyemaps.py +80 -0
- pyemaps/samples/si_scm.py +156 -0
- pyemaps/samples/si_stereo.py +116 -0
- pyemaps/scattering/__init__.py +26 -0
- pyemaps/scattering/sct_dec.py +31 -0
- pyemaps/spg/__init__.py +25 -0
- pyemaps/spg/spg_dec.py +60 -0
- pyemaps/stackimg.py +1031 -0
- pyemaps/xtal.py +222 -0
- pyemaps-2.0.0.dist-info/METADATA +231 -0
- pyemaps-2.0.0.dist-info/RECORD +112 -0
- pyemaps-2.0.0.dist-info/WHEEL +5 -0
- pyemaps-2.0.0.dist-info/entry_points.txt +2 -0
- pyemaps-2.0.0.dist-info/licenses/COPYING +798 -0
- pyemaps-2.0.0.dist-info/licenses/license.txt +42 -0
- pyemaps-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
# To maximize python3/python2 compatibility
|
|
2
|
+
from __future__ import print_function
|
|
3
|
+
from __future__ import unicode_literals
|
|
4
|
+
from __future__ import division
|
|
5
|
+
from __future__ import absolute_import
|
|
6
|
+
|
|
7
|
+
from .StarFile import StarBlock,StarFile,StarList,StarDict
|
|
8
|
+
from io import StringIO
|
|
9
|
+
# An alternative specification for the Cif Parser, based on Yapps2
|
|
10
|
+
# by Amit Patel (http://theory.stanford.edu/~amitp/Yapps)
|
|
11
|
+
#
|
|
12
|
+
# helper code: we define our match tokens
|
|
13
|
+
lastval = ''
|
|
14
|
+
def monitor(location,value):
|
|
15
|
+
global lastval
|
|
16
|
+
#print 'At %s: %s' % (location,repr(value))
|
|
17
|
+
lastval = repr(value)
|
|
18
|
+
return value
|
|
19
|
+
|
|
20
|
+
# Strip extras gets rid of leading and trailing whitespace, and
|
|
21
|
+
# semicolons.
|
|
22
|
+
def stripextras(value):
|
|
23
|
+
from .StarFile import remove_line_folding, remove_line_prefix
|
|
24
|
+
# we get rid of semicolons and leading/trailing terminators etc.
|
|
25
|
+
import re
|
|
26
|
+
jj = re.compile("[\n\r\f \t\v]*")
|
|
27
|
+
semis = re.compile("[\n\r\f \t\v]*[\n\r\f]\n*;")
|
|
28
|
+
cut = semis.match(value)
|
|
29
|
+
if cut: #we have a semicolon-delimited string
|
|
30
|
+
nv = value[cut.end():len(value)-2]
|
|
31
|
+
try:
|
|
32
|
+
if nv[-1]=='\r': nv = nv[:-1]
|
|
33
|
+
except IndexError: #empty data value
|
|
34
|
+
pass
|
|
35
|
+
# apply protocols
|
|
36
|
+
nv = remove_line_prefix(nv)
|
|
37
|
+
nv = remove_line_folding(nv)
|
|
38
|
+
return nv
|
|
39
|
+
else:
|
|
40
|
+
cut = jj.match(value)
|
|
41
|
+
if cut:
|
|
42
|
+
return stripstring(value[cut.end():])
|
|
43
|
+
return value
|
|
44
|
+
|
|
45
|
+
# helper function to get rid of inverted commas etc.
|
|
46
|
+
|
|
47
|
+
def stripstring(value):
|
|
48
|
+
if value:
|
|
49
|
+
if value[0]== '\'' and value[-1]=='\'':
|
|
50
|
+
return value[1:-1]
|
|
51
|
+
if value[0]=='"' and value[-1]=='"':
|
|
52
|
+
return value[1:-1]
|
|
53
|
+
return value
|
|
54
|
+
|
|
55
|
+
# helper function to get rid of triple quotes
|
|
56
|
+
def striptriple(value):
|
|
57
|
+
if value:
|
|
58
|
+
if value[:3] == '"""' and value[-3:] == '"""':
|
|
59
|
+
return value[3:-3]
|
|
60
|
+
if value[:3] == "'''" and value[-3:] == "'''":
|
|
61
|
+
return value[3:-3]
|
|
62
|
+
return value
|
|
63
|
+
|
|
64
|
+
# helper function to populate a StarBlock given a list of names
|
|
65
|
+
# and values .
|
|
66
|
+
#
|
|
67
|
+
# Note that there may be an empty list at the very end of our itemlists,
|
|
68
|
+
# so we remove that if necessary.
|
|
69
|
+
#
|
|
70
|
+
|
|
71
|
+
def makeloop(target_block,loopdata):
|
|
72
|
+
loop_seq,itemlists = loopdata
|
|
73
|
+
if itemlists[-1] == []: itemlists.pop(-1)
|
|
74
|
+
# print('Making loop with %s' % repr(itemlists))
|
|
75
|
+
step_size = len(loop_seq)
|
|
76
|
+
for col_no in range(step_size):
|
|
77
|
+
target_block.AddItem(loop_seq[col_no], itemlists[col_no::step_size],precheck=True)
|
|
78
|
+
# now construct the loop
|
|
79
|
+
try:
|
|
80
|
+
target_block.CreateLoop(loop_seq) #will raise ValueError on problem
|
|
81
|
+
except ValueError:
|
|
82
|
+
error_string = 'Incorrect number of loop values for loop containing %s' % repr(loop_seq)
|
|
83
|
+
print(error_string, file=sys.stderr)
|
|
84
|
+
raise ValueError(error_string)
|
|
85
|
+
|
|
86
|
+
# return an object with the appropriate amount of nesting
|
|
87
|
+
def make_empty(nestlevel):
|
|
88
|
+
gd = []
|
|
89
|
+
for i in range(1,nestlevel):
|
|
90
|
+
gd = [gd]
|
|
91
|
+
return gd
|
|
92
|
+
|
|
93
|
+
# this function updates a dictionary first checking for name collisions,
|
|
94
|
+
# which imply that the CIF is invalid. We need case insensitivity for
|
|
95
|
+
# names.
|
|
96
|
+
|
|
97
|
+
# Unfortunately we cannot check loop item contents against non-loop contents
|
|
98
|
+
# in a non-messy way during parsing, as we may not have easy access to previous
|
|
99
|
+
# key value pairs in the context of our call (unlike our built-in access to all
|
|
100
|
+
# previous loops).
|
|
101
|
+
# For this reason, we don't waste time checking looped items against non-looped
|
|
102
|
+
# names during parsing of a data block. This would only match a subset of the
|
|
103
|
+
# final items. We do check against ordinary items, however.
|
|
104
|
+
#
|
|
105
|
+
# Note the following situations:
|
|
106
|
+
# (1) new_dict is empty -> we have just added a loop; do no checking
|
|
107
|
+
# (2) new_dict is not empty -> we have some new key-value pairs
|
|
108
|
+
#
|
|
109
|
+
def cif_update(old_dict,new_dict,loops):
|
|
110
|
+
old_keys = map(lambda a:a.lower(),old_dict.keys())
|
|
111
|
+
if new_dict != {}: # otherwise we have a new loop
|
|
112
|
+
#print 'Comparing %s to %s' % (repr(old_keys),repr(new_dict.keys()))
|
|
113
|
+
for new_key in new_dict.keys():
|
|
114
|
+
if new_key.lower() in old_keys:
|
|
115
|
+
raise CifError("Duplicate dataname or blockname %s in input file" % new_key)
|
|
116
|
+
old_dict[new_key] = new_dict[new_key]
|
|
117
|
+
#
|
|
118
|
+
# this takes two lines, so we couldn't fit it into a one line execution statement...
|
|
119
|
+
def order_update(order_array,new_name):
|
|
120
|
+
order_array.append(new_name)
|
|
121
|
+
return new_name
|
|
122
|
+
|
|
123
|
+
# and finally...turn a sequence into a python dict (thanks to Stackoverflow)
|
|
124
|
+
def pairwise(iterable):
|
|
125
|
+
try:
|
|
126
|
+
it = iter(iterable)
|
|
127
|
+
while 1:
|
|
128
|
+
yield next(it), next(it)
|
|
129
|
+
except StopIteration:
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
# Begin -- grammar generated by Yapps
|
|
133
|
+
import sys, re
|
|
134
|
+
from . import yapps3_compiled_rt as yappsrt
|
|
135
|
+
|
|
136
|
+
class StarParserScanner(yappsrt.Scanner):
|
|
137
|
+
def __init__(self, *args,**kwargs):
|
|
138
|
+
patterns = [
|
|
139
|
+
('":"', ':'),
|
|
140
|
+
('([ \t\n\r](?!;))|[ \t]', '([ \t\n\r](?!;))|[ \t]'),
|
|
141
|
+
('(#.*[\n\r](?!;))|(#.*)', '(#.*[\n\r](?!;))|(#.*)'),
|
|
142
|
+
('LBLOCK', '(L|l)(O|o)(O|o)(P|p)_'),
|
|
143
|
+
('GLOBAL', '(G|g)(L|l)(O|o)(B|b)(A|a)(L|l)_'),
|
|
144
|
+
('STOP', '(S|s)(T|t)(O|o)(P|p)_'),
|
|
145
|
+
('save_heading', u'(S|s)(A|a)(V|v)(E|e)_[][!%&\\(\\)*+,./:<=>?@0-9A-Za-z\\\\^`{}\\|~"#$\';_\xa0-\ud7ff\ue000-\ufdcf\ufdf0-\ufffd\U00010000-\U0001fffd\U00020000-\U0002fffd\U00030000-\U0003fffd\U00040000-\U0004fffd\U00050000-\U0005fffd\U00060000-\U0006fffd\U00070000-\U0007fffd\U00080000-\U0008fffd\U00090000-\U0009fffd\U000a0000-\U000afffd\U000b0000-\U000bfffd\U000c0000-\U000cfffd\U000d0000-\U000dfffd\U000e0000-\U000efffd\U000f0000-\U000ffffd\U00100000-\U0010fffd-]+'),
|
|
146
|
+
('save_end', '(S|s)(A|a)(V|v)(E|e)_'),
|
|
147
|
+
('data_name', u'_[][!%&\\(\\)*+,./:<=>?@0-9A-Za-z\\\\^`{}\\|~"#$\';_\xa0-\ud7ff\ue000-\ufdcf\ufdf0-\ufffd\U00010000-\U0001fffd\U00020000-\U0002fffd\U00030000-\U0003fffd\U00040000-\U0004fffd\U00050000-\U0005fffd\U00060000-\U0006fffd\U00070000-\U0007fffd\U00080000-\U0008fffd\U00090000-\U0009fffd\U000a0000-\U000afffd\U000b0000-\U000bfffd\U000c0000-\U000cfffd\U000d0000-\U000dfffd\U000e0000-\U000efffd\U000f0000-\U000ffffd\U00100000-\U0010fffd-]+'),
|
|
148
|
+
('data_heading', u'(D|d)(A|a)(T|t)(A|a)_[][!%&\\(\\)*+,./:<=>?@0-9A-Za-z\\\\^`{}\\|~"#$\';_\xa0-\ud7ff\ue000-\ufdcf\ufdf0-\ufffd\U00010000-\U0001fffd\U00020000-\U0002fffd\U00030000-\U0003fffd\U00040000-\U0004fffd\U00050000-\U0005fffd\U00060000-\U0006fffd\U00070000-\U0007fffd\U00080000-\U0008fffd\U00090000-\U0009fffd\U000a0000-\U000afffd\U000b0000-\U000bfffd\U000c0000-\U000cfffd\U000d0000-\U000dfffd\U000e0000-\U000efffd\U000f0000-\U000ffffd\U00100000-\U0010fffd-]+'),
|
|
149
|
+
('start_sc_line', '(\n|\r\n);([^\n\r])*(\r\n|\r|\n)+'),
|
|
150
|
+
('sc_line_of_text', '[^;\r\n]([^\r\n])*(\r\n|\r|\n)+'),
|
|
151
|
+
('end_sc_line', ';'),
|
|
152
|
+
('c_c_b', '\\}'),
|
|
153
|
+
('o_c_b', '\\{'),
|
|
154
|
+
('c_s_b', '\\]'),
|
|
155
|
+
('o_s_b', '\\['),
|
|
156
|
+
('dat_val_internal_sq', '\\[([^\\s\\[\\]]*)\\]'),
|
|
157
|
+
('triple_quote_data_value', '(?s)\'\'\'.*?\'\'\'|""".*?"""'),
|
|
158
|
+
('single_quote_data_value', '\'([^\n\r\x0c\'])*\'+|"([^\n\r"])*"+'),
|
|
159
|
+
('data_value_1', '((?!(((S|s)(A|a)(V|v)(E|e)_[^\\s]*)|((G|g)(L|l)(O|o)(B|b)(A|a)(L|l)_[^\\s]*)|((S|s)(T|t)(O|o)(P|p)_[^\\s]*)|((D|d)(A|a)(T|t)(A|a)_[^\\s]*)))[^\\s"#$\'_\\{\\}\\[\\]][^\\s\\{\\}\\[\\]]*)'),
|
|
160
|
+
('END', '$'),
|
|
161
|
+
]
|
|
162
|
+
yappsrt.Scanner.__init__(self,patterns,['([ \t\n\r](?!;))|[ \t]', '(#.*[\n\r](?!;))|(#.*)'],*args,**kwargs)
|
|
163
|
+
|
|
164
|
+
class StarParser(yappsrt.Parser):
|
|
165
|
+
Context = yappsrt.Context
|
|
166
|
+
def input(self, prepared, _parent=None):
|
|
167
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'input', [prepared])
|
|
168
|
+
_token = self._peek('END', 'data_heading')
|
|
169
|
+
if _token == 'data_heading':
|
|
170
|
+
dblock = self.dblock(prepared, _context)
|
|
171
|
+
allblocks = prepared; allblocks.merge_fast(dblock)
|
|
172
|
+
while self._peek('END', 'data_heading') == 'data_heading':
|
|
173
|
+
dblock = self.dblock(prepared, _context)
|
|
174
|
+
allblocks.merge_fast(dblock)
|
|
175
|
+
if self._peek() not in ['END', 'data_heading']:
|
|
176
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['END', 'data_heading']))
|
|
177
|
+
END = self._scan('END')
|
|
178
|
+
else: # == 'END'
|
|
179
|
+
END = self._scan('END')
|
|
180
|
+
allblocks = prepared
|
|
181
|
+
allblocks.unlock(); return allblocks
|
|
182
|
+
|
|
183
|
+
def dblock(self, prepared, _parent=None):
|
|
184
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'dblock', [prepared])
|
|
185
|
+
data_heading = self._scan('data_heading')
|
|
186
|
+
heading = data_heading[5:];thisbc=StarFile(characterset='unicode',standard=prepared.standard);act_heading = thisbc.NewBlock(heading,prepared.blocktype(overwrite=False));stored_block = thisbc[act_heading]
|
|
187
|
+
while self._peek('save_heading', 'save_end', 'LBLOCK', 'data_name', 'END', 'data_heading') in ['save_heading', 'LBLOCK', 'data_name']:
|
|
188
|
+
_token = self._peek('save_heading', 'LBLOCK', 'data_name')
|
|
189
|
+
if _token != 'save_heading':
|
|
190
|
+
dataseq = self.dataseq(stored_block, _context)
|
|
191
|
+
else: # == 'save_heading'
|
|
192
|
+
save_frame = self.save_frame(prepared, _context)
|
|
193
|
+
thisbc.merge_fast(save_frame,parent=stored_block)
|
|
194
|
+
if self._peek() not in ['save_heading', 'save_end', 'LBLOCK', 'data_name', 'END', 'data_heading']:
|
|
195
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['save_heading', 'save_end', 'LBLOCK', 'data_name', 'END', 'data_heading']))
|
|
196
|
+
stored_block.setmaxnamelength(stored_block.maxnamelength);return (monitor('dblock',thisbc))
|
|
197
|
+
|
|
198
|
+
def dataseq(self, starblock, _parent=None):
|
|
199
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'dataseq', [starblock])
|
|
200
|
+
data = self.data(starblock, _context)
|
|
201
|
+
while self._peek('save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading') in ['LBLOCK', 'data_name']:
|
|
202
|
+
data = self.data(starblock, _context)
|
|
203
|
+
if self._peek() not in ['save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading']:
|
|
204
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['LBLOCK', 'data_name', 'save_end', 'save_heading', 'END', 'data_heading']))
|
|
205
|
+
|
|
206
|
+
def data(self, currentblock, _parent=None):
|
|
207
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'data', [currentblock])
|
|
208
|
+
_token = self._peek('LBLOCK', 'data_name')
|
|
209
|
+
if _token == 'LBLOCK':
|
|
210
|
+
top_loop = self.top_loop(_context)
|
|
211
|
+
makeloop(currentblock,top_loop)
|
|
212
|
+
else: # == 'data_name'
|
|
213
|
+
datakvpair = self.datakvpair(_context)
|
|
214
|
+
currentblock.AddItem(datakvpair[0],datakvpair[1],precheck=False)
|
|
215
|
+
|
|
216
|
+
def datakvpair(self, _parent=None):
|
|
217
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'datakvpair', [])
|
|
218
|
+
data_name = self._scan('data_name')
|
|
219
|
+
data_value = self.data_value(_context)
|
|
220
|
+
return [data_name,data_value]
|
|
221
|
+
|
|
222
|
+
def data_value(self, _parent=None):
|
|
223
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'data_value', [])
|
|
224
|
+
_token = self._peek('data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b')
|
|
225
|
+
if _token == 'data_value_1':
|
|
226
|
+
data_value_1 = self._scan('data_value_1')
|
|
227
|
+
thisval = data_value_1
|
|
228
|
+
elif _token not in ['start_sc_line', 'o_s_b', 'o_c_b']:
|
|
229
|
+
delimited_data_value = self.delimited_data_value(_context)
|
|
230
|
+
thisval = delimited_data_value
|
|
231
|
+
elif _token == 'start_sc_line':
|
|
232
|
+
sc_lines_of_text = self.sc_lines_of_text(_context)
|
|
233
|
+
thisval = stripextras(sc_lines_of_text)
|
|
234
|
+
else: # in ['o_s_b', 'o_c_b']
|
|
235
|
+
bracket_expression = self.bracket_expression(_context)
|
|
236
|
+
thisval = bracket_expression
|
|
237
|
+
return monitor('data_value',thisval)
|
|
238
|
+
|
|
239
|
+
def delimited_data_value(self, _parent=None):
|
|
240
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'delimited_data_value', [])
|
|
241
|
+
_token = self._peek('triple_quote_data_value', 'single_quote_data_value')
|
|
242
|
+
if _token == 'triple_quote_data_value':
|
|
243
|
+
triple_quote_data_value = self._scan('triple_quote_data_value')
|
|
244
|
+
thisval = striptriple(triple_quote_data_value)
|
|
245
|
+
else: # == 'single_quote_data_value'
|
|
246
|
+
single_quote_data_value = self._scan('single_quote_data_value')
|
|
247
|
+
thisval = stripstring(single_quote_data_value)
|
|
248
|
+
return thisval
|
|
249
|
+
|
|
250
|
+
def sc_lines_of_text(self, _parent=None):
|
|
251
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'sc_lines_of_text', [])
|
|
252
|
+
start_sc_line = self._scan('start_sc_line')
|
|
253
|
+
lines = StringIO();lines.write(start_sc_line)
|
|
254
|
+
while self._peek('end_sc_line', 'sc_line_of_text') == 'sc_line_of_text':
|
|
255
|
+
sc_line_of_text = self._scan('sc_line_of_text')
|
|
256
|
+
lines.write(sc_line_of_text)
|
|
257
|
+
if self._peek() not in ['end_sc_line', 'sc_line_of_text']:
|
|
258
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['sc_line_of_text', 'end_sc_line']))
|
|
259
|
+
end_sc_line = self._scan('end_sc_line')
|
|
260
|
+
lines.write(end_sc_line);return monitor('sc_line_of_text',lines.getvalue())
|
|
261
|
+
|
|
262
|
+
def bracket_expression(self, _parent=None):
|
|
263
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'bracket_expression', [])
|
|
264
|
+
_token = self._peek('o_s_b', 'o_c_b')
|
|
265
|
+
if _token == 'o_s_b':
|
|
266
|
+
square_bracket_expr = self.square_bracket_expr(_context)
|
|
267
|
+
return square_bracket_expr
|
|
268
|
+
else: # == 'o_c_b'
|
|
269
|
+
curly_bracket_expr = self.curly_bracket_expr(_context)
|
|
270
|
+
return curly_bracket_expr
|
|
271
|
+
|
|
272
|
+
def top_loop(self, _parent=None):
|
|
273
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'top_loop', [])
|
|
274
|
+
LBLOCK = self._scan('LBLOCK')
|
|
275
|
+
loopfield = self.loopfield(_context)
|
|
276
|
+
loopvalues = self.loopvalues(_context)
|
|
277
|
+
return loopfield,loopvalues
|
|
278
|
+
|
|
279
|
+
def loopfield(self, _parent=None):
|
|
280
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'loopfield', [])
|
|
281
|
+
loop_seq=[]
|
|
282
|
+
while self._peek('data_name', 'data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b') == 'data_name':
|
|
283
|
+
data_name = self._scan('data_name')
|
|
284
|
+
loop_seq.append(data_name)
|
|
285
|
+
if self._peek() not in ['data_name', 'data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b']:
|
|
286
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['data_name', 'data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b']))
|
|
287
|
+
return loop_seq
|
|
288
|
+
|
|
289
|
+
def loopvalues(self, _parent=None):
|
|
290
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'loopvalues', [])
|
|
291
|
+
data_value = self.data_value(_context)
|
|
292
|
+
dataloop=[data_value]
|
|
293
|
+
while self._peek('data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b', 'LBLOCK', 'data_name', 'save_end', 'save_heading', 'END', 'data_heading') in ['data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b']:
|
|
294
|
+
data_value = self.data_value(_context)
|
|
295
|
+
dataloop.append(monitor('loopval',data_value))
|
|
296
|
+
if self._peek() not in ['data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b', 'LBLOCK', 'data_name', 'save_end', 'save_heading', 'END', 'data_heading']:
|
|
297
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b', 'LBLOCK', 'data_name', 'save_end', 'save_heading', 'END', 'data_heading']))
|
|
298
|
+
return dataloop
|
|
299
|
+
|
|
300
|
+
def save_frame(self, prepared, _parent=None):
|
|
301
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'save_frame', [prepared])
|
|
302
|
+
save_heading = self._scan('save_heading')
|
|
303
|
+
savehead = save_heading[5:];savebc = StarFile();newname = savebc.NewBlock(savehead,prepared.blocktype(overwrite=False));stored_block = savebc[newname]
|
|
304
|
+
while self._peek('save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading') in ['LBLOCK', 'data_name']:
|
|
305
|
+
dataseq = self.dataseq(savebc[savehead], _context)
|
|
306
|
+
if self._peek() not in ['save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading']:
|
|
307
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading']))
|
|
308
|
+
save_end = self._scan('save_end')
|
|
309
|
+
return monitor('save_frame',savebc)
|
|
310
|
+
|
|
311
|
+
def save_frame(self, prepared, _parent=None):
|
|
312
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'save_frame', [prepared])
|
|
313
|
+
save_heading = self._scan('save_heading')
|
|
314
|
+
savehead = save_heading[5:];savebc = StarFile();newname = savebc.NewBlock(savehead,prepared.blocktype(overwrite=False));stored_block = savebc[newname]
|
|
315
|
+
while self._peek('save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading') in ['LBLOCK', 'data_name']:
|
|
316
|
+
dataseq = self.dataseq(savebc[savehead], _context)
|
|
317
|
+
if self._peek() not in ['save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading']:
|
|
318
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['save_end', 'LBLOCK', 'data_name', 'save_heading', 'END', 'data_heading']))
|
|
319
|
+
save_end = self._scan('save_end')
|
|
320
|
+
return monitor('save_frame',savebc)
|
|
321
|
+
|
|
322
|
+
def square_bracket_expr(self, _parent=None):
|
|
323
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'square_bracket_expr', [])
|
|
324
|
+
o_s_b = self._scan('o_s_b')
|
|
325
|
+
this_list = []
|
|
326
|
+
while self._peek('c_s_b', 'data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b') != 'c_s_b':
|
|
327
|
+
data_value = self.data_value(_context)
|
|
328
|
+
this_list.append(data_value)
|
|
329
|
+
while self._peek('data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'c_s_b', 'o_s_b', 'o_c_b') != 'c_s_b':
|
|
330
|
+
data_value = self.data_value(_context)
|
|
331
|
+
this_list.append(data_value)
|
|
332
|
+
if self._peek() not in ['data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'c_s_b', 'o_s_b', 'o_c_b']:
|
|
333
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b', 'c_s_b']))
|
|
334
|
+
if self._peek() not in ['c_s_b', 'data_value_1', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b']:
|
|
335
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['data_value_1', 'c_s_b', 'triple_quote_data_value', 'single_quote_data_value', 'start_sc_line', 'o_s_b', 'o_c_b']))
|
|
336
|
+
c_s_b = self._scan('c_s_b')
|
|
337
|
+
return StarList(this_list)
|
|
338
|
+
|
|
339
|
+
def curly_bracket_expr(self, _parent=None):
|
|
340
|
+
_context = self.Context(_parent, self._scanner, self._pos, 'curly_bracket_expr', [])
|
|
341
|
+
o_c_b = self._scan('o_c_b')
|
|
342
|
+
table_as_list = []
|
|
343
|
+
while self._peek('c_c_b', 'triple_quote_data_value', 'single_quote_data_value') != 'c_c_b':
|
|
344
|
+
delimited_data_value = self.delimited_data_value(_context)
|
|
345
|
+
table_as_list = [delimited_data_value]
|
|
346
|
+
self._scan('":"')
|
|
347
|
+
data_value = self.data_value(_context)
|
|
348
|
+
table_as_list.append(data_value)
|
|
349
|
+
while self._peek('triple_quote_data_value', 'single_quote_data_value', 'c_c_b') != 'c_c_b':
|
|
350
|
+
delimited_data_value = self.delimited_data_value(_context)
|
|
351
|
+
table_as_list.append(delimited_data_value)
|
|
352
|
+
self._scan('":"')
|
|
353
|
+
data_value = self.data_value(_context)
|
|
354
|
+
table_as_list.append(data_value)
|
|
355
|
+
if self._peek() not in ['triple_quote_data_value', 'single_quote_data_value', 'c_c_b']:
|
|
356
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['triple_quote_data_value', 'single_quote_data_value', 'c_c_b']))
|
|
357
|
+
if self._peek() not in ['c_c_b', 'triple_quote_data_value', 'single_quote_data_value']:
|
|
358
|
+
raise yappsrt.YappsSyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['triple_quote_data_value', 'single_quote_data_value', 'c_c_b']))
|
|
359
|
+
c_c_b = self._scan('c_c_b')
|
|
360
|
+
return StarDict(pairwise(table_as_list))
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def parse(rule, text):
|
|
364
|
+
P = StarParser(StarParserScanner(text))
|
|
365
|
+
return yappsrt.wrap_error_reporter(P, rule)
|
|
366
|
+
|
|
367
|
+
# End -- grammar generated by Yapps
|
|
368
|
+
|
|
369
|
+
|