-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.py
executable file
·1651 lines (1365 loc) · 67.6 KB
/
Parser.py
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# *********************************************
# Created by Krzysztof Fryzlewicz, Marek Lipert
# Ihnat Moisieiev
# of Spinney
# www.spinney.io
#
# All commercial rights to this software belong to
# Highsoft AS
# www.highcharts.com
import json
import sys
import os
import re
import copy
from bs4 import BeautifulSoup, SoupStrainer
reload(sys)
sys.setdefaultencoding('utf-8')
structure = dict()
files = list()
bridge = set()
options = list()
classes = dict()
comments = dict()
types = dict()
unknown_types_tree = set()
series_description = ""
series_data_description = ""
class_methods = dict()
filelicense = "/**\n* (c) 2009-2024 Highsoft AS\n*\n* License: www.highcharts.com/license\n" \
"* For commercial usage, a valid license is required. To purchase a license for Highcharts iOS, please see our website: https://shop.highsoft.com/\n" \
"* In case of questions, please contact sales@highsoft.com\n*/\n\n"
class HIChartsClass:
def __init__(self, name, data_type, description, demo, values, defaults, products, extends, exclude, info, parent):
self.name = name
self.data_type = data_type
self.description = description
self.demo = demo
self.values = values
self.defaults = defaults
self.products = products
self.extends = extends
self.exclude = exclude
self.properties = list()
self.not_highcharts_properties = list()
self.comment = None
self.checkedExtends = False
self.info = info
self.parent = parent
self.kind = ""
if self.description:
self.comment = clean_comment(self.description)
if self.values:
self.comment += "\n**Accepted values:** `{0}`.\n".format(self.values)
if self.defaults:
self.comment += "\n**Defaults to** `{0}`.\n".format(self.defaults)
if self.demo:
self.comment += "\n**Try it**\n\n{0}".format(self.demo)
self.comment += "*/\n"
def update(self, data_type, description, demo, values, defaults, products, extends, exclude):
if self.data_type is None:
self.data_type = data_type
if self.description is None:
self.description = description
if self.demo is None:
self.demo = demo
if self.values is None:
self.values = values
if self.defaults is None:
self.defaults = defaults
if self.products is None:
self.products = products
if self.extends is None:
self.extends = extends
if self.exclude is None:
self.exclude = exclude
if self.description:
self.comment = clean_comment(self.description)
if self.values:
self.comment += "\n**Accepted values:** `{0}`.\n".format(self.values)
if self.defaults:
self.comment += "\n**Defaults to** `{0}`.\n".format(self.defaults)
if self.demo:
self.comment += "\n**Try it**\n\n{0}".format(self.demo)
self.comment += "*/\n"
def add_property(self, variable):
self.properties.append(variable)
def remove_property(self, variable):
self.properties.remove(variable)
def add_not_highcharts_property(self, variable):
self.not_highcharts_properties.append(get_last(variable))
def clean_comment(comment):
comment = comment.replace('\n', ' ').replace(' ', ' ').replace('. ', '. ').replace('(//code.highcharts.com/', '(https://code.highcharts.com/').replace('[code.highcharts.com/', '[https://code.highcharts.com/')
comment = re.sub('(\(|\[)[\w\.*/ *: *\-*]+[\.\-/_]\s+[\w\.*/ *: *\- *]+(\)|\])', lambda s: s.group(0).replace(' ', ''), comment)
comment = re.sub('\[(.+?)\]\((.+?)\)', lambda s: s.group(0) if s.group(2).startswith("http") else s.group(0).replace(s.group(0), '`{}`'.format(s.group(1))), comment)
comment = re.sub('\((.+?)\)\[(.+?)\]', r'[\1](\2)', comment)
comment = comment.replace('`<', '__x__').replace('>`', '__y__')
soup = BeautifulSoup(comment, 'html.parser')
comment = soup.get_text().replace('__x__', '`<').replace('__y__', '>`')
comment = "/**\n{0}\n".format(comment)
return comment
class Node:
def __init__(self, name, parent, info):
self.name = name
self.info = info
self.children = list()
self.parent = parent
def add_child(self, child):
self.children.append(child)
def update(self, parent, info):
self.parent = parent
self.info = info
hc_types = {
"Number": 'NSNumber',
"Boolean": 'NSNumber /* Bool */',
"Color": 'HIColor',
"String": 'NSString',
"Object": 'id',
"Function": 'HIFunction',
"Array<Number>": 'NSArray<NSNumber *>',
"Array<Object>": 'NSArray',
"Array": 'NSArray',
"Array<String>": 'NSArray<NSString *>',
"Boolean|Object": 'id /* Bool, id */',
"String|Number": 'id /* NSString, NSNumber */',
"Array<Array>": 'NSArray<NSArray *>',
"CSSObject": 'NSDictionary /* <NSString, NSString> */',
"Array<Color>": 'NSArray<HIColor *>',
"Array<Object|Array|Number>": 'NSArray /* <id, NSNumber, NSArray> */',
"Array<String|Number>": 'NSArray /* <NSString, NSNumber> */',
"Array<Object|Number>": 'NSArray /* <id, NSNumber> */',
"Array<Object|Array>": 'NSArray',
"Number|String": 'id /* NSNumber, NSString */',
"String|HTMLElement": 'NSString',
"Array<Array<Mixed>>": 'NSArray<NSArray *>',
"String|Object": 'id /* NSString, id */',
"Mixed": 'id',
"Number|Boolean": 'NSNumber',
"": 'id',
"Boolean|String": 'id /* Bool, NSString */',
# nowe typy
"Object|Boolean": 'id /* id, Bool */',
"String|Array.<String>": 'NSArray<NSString *>',
"Array.<String>": 'NSArray<NSString *>',
"function": 'HIFunction',
"Array.<Object>": 'NSArray',
"Array.<Number>": 'NSArray<NSNumber *>',
"Array.<Array>": 'NSArray<NSArray *>',
"Array.<Color>": 'NSArray<HIColor *>',
"Array.<Object|Array|Number>": 'NSArray /* <id, NSNumber, NSArray> */',
"Array.<String|Number>": 'NSArray /* <NSString, NSNumber> */',
"Array.<Object|Number>": 'NSArray /* <id, NSNumber> */',
"Array.<Object|Array>": 'NSArray /* <id, NSArray> */',
"Array.<Array<Mixed>>": 'NSArray<NSArray *>',
"Array.<(Object|Number)>": 'NSArray /* <id, NSNumber> */',
"Array.<(String|Number)>": 'NSArray /* <NSString, NSNumber> */',
"Array.<(Object|Array)>": 'NSArray /* <id, NSArray> */',
"String|undefined": 'NSString',
"Array.<String>|Array.<Object>": 'NSArray /* <NSString, id> */',
"String|Number|function": 'id /* NSString, NSNumber, Function */',
"Array.<(Object|Array|Number)>": 'NSArray /* <id, NSNumber, NSArray> */',
"String|null": 'NSString',
"Array.<Array.<Mixed>>": 'NSArray<NSArray *>',
"function|null": 'HIFunction',
#6.0.6
"Undefined|Number": 'NSNumber',
#6.1.0
"Bool": 'NSNumber /* Bool */',
#6.1.1
"AnimationOptions|Boolean": 'HIAnimationOptionsObject',
"Boolean|AnimationOptions": 'HIAnimationOptionsObject',
"Array.<number>": 'NSArray<NSNumber *>',
# 6.1.2
"number": 'NSNumber',
"string": 'NSString',
"boolean": 'NSNumber /* Bool */',
"*" : 'id',
"Array.<*>": 'NSArray',
"Array.<Array.<(string|Array.<number>)>>":'NSArray<NSArray *>',
"Array.<string>": 'NSArray<NSString *>',
"null|number|string": 'id /* NSNumber, NSString */',
"object": 'id',
"Number|String|function": 'id /* NSNumber, NSString, Function */',
"Array.<Object>|Array.<String>": 'NSArray /* <id, NSString> */',
"null|number": 'NSNumber',
"Array.<number>|number": 'NSArray<NSNumber *>',
"Boolean|Number": 'NSNumber',
"number|string": 'id /* NSNumber, NSString */',
#6.1.4
"boolean|*": 'id /* Bool, id */',
"number|string|null": 'id /* NSNumber, NSString */',
"boolean|string": 'id /* Bool, NSString */',
"number|null": 'NSNumber',
"number|Array.<number>": 'NSArray<NSNumber *>',
"string|number" : 'id /* NSString, NSNumber */',
#6.2.0
"Array.<(number|string|null)>": 'NSArray /* <NSNumber, NSString> */',
"string|null": 'NSString',
"Array.<Array.<number, string>>": 'NSArray<NSArray *> /* <NSNumber, NSString> */',
# tree_namespace
"number|undefined": 'NSNumber',
"Array.<(number|string)>": 'NSArray /* <NSNumber, NSString> */',
"false": 'NSNumber /* Bool */',
"undefined" : 'id',
"null" : 'id',
"Object|undefined": 'id',
"Array.<Point>": 'NSArray',
"string|Array.<(number|string)>": 'NSArray /* <NSNumber, NSString> */',
"Highcharts.Dictionary.<function()>": 'NSDictionary',
"Highcharts.Dictionary.<(boolean|number|string)>": 'NSDictionary',
"Highcharts.Dictionary.<string>": 'NSDictionary /* <NSString, NSString> */',
# tree
"Highcharts.Options": 'NSDictionary',
"boolean|Highcharts.ShadowOptionsObject": 'HIShadowOptionsObject',
"boolean|Highcharts.CSSObject": 'HICSSObject',
#color fixes
"Highcharts.ColorString": 'HIColor',
"Highcharts.ColorString|null": 'HIColor',
#7.0.0
"string|global.HTMLElement": 'NSString',
"Array.<Highcharts.Dictionary.<number>>": 'NSArray',
"Array.<Array.<*>>": 'NSArray<NSArray *>',
"string|Highcharts.GradientColorObject|Highcharts.PatternObject": 'HIColor',
"Highcharts.FormatterCallbackFunction.<Highcharts.TooltipFormatterContextObject>": 'HIFunction',
"Highcharts.Dictionary.<*>": 'NSDictionary',
"Array.<Array.<string, (Array.<number>|null)>>": 'NSArray<NSArray *>',
"string|Highcharts.GradientColorObject": 'HIColor',
"Array.<(string|number)>": 'NSArray /* <NSString, NSNumber> */',
"Highcharts.FormatterCallbackFunction.<Highcharts.SeriesDataLabelsFormatterContextObject>": 'HIFunction',
"Annotation.ControlPoint.Options": 'id',
"Highcharts.FormatterCallbackFunction.<object>": 'HIFunction',
"boolean|null": 'NSNumber /* Bool */',
"false|number": 'NSNumber',
"String|function": 'NSString',
"*|Array.<*>": 'NSArray',
"function|undefined": 'HIFunction',
"string|undefined": 'NSString',
# tree-namespace
"Array.<Array.<number, string>>|undefined": 'NSArray<NSArray *>',
"string|*": 'NSString',
"Array.<*>|undefined": 'NSArray',
"boolean|undefined": 'NSNumber /* Bool */',
"Array.<number>|undefined": 'NSArray<NSNumber *>',
"object|undefined": 'id',
"boolean|*|undefined": 'NSNumber /* Bool */',
"string|Array.<(number|string)>|undefined": 'NSArray /* <NSNumber, NSString> */',
"Array<number>": 'NSArray<NSNumber *>',
"boolean|Array.<*>|undefined": 'id',
"Array.<function()>|undefined": 'NSArray<HIFunction *>',
"*|undefined": 'id',
"Highcharts.Dictionary.<number>": 'NSDictionary',
"Object|*": 'id',
#7.0.1
"Highcharts.FormatterCallbackFunction.<Highcharts.AxisLabelsFormatterContextObject>": 'HIFunction',
"Highcharts.FormatterCallbackFunction.<Highcharts.Point>": 'HIFunction',
"string|Highcharts.HTMLDOMElement": 'NSString',
#7.0.2
"Array.<(string|Highcharts.GradientColorObject|Highcharts.PatternObject)>": 'NSArray<HIColor *>',
"string|function": 'NSString',
#7.1.1
"undefined|number": 'NSNumber',
"Highcharts.ScreenReaderFormatterCallbackFunction.<Highcharts.Chart>": 'HIFunction',
"Highcharts.ScreenReaderFormatterCallbackFunction.<Highcharts.Series>": 'HIFunction',
"Highcharts.ScreenReaderFormatterCallbackFunction.<Highcharts.Point>": 'HIFunction',
"boolean|number": 'NSNumber',
"Array.<number>|false": 'NSArray<NSNumber *>',
"Highcharts.FormatterCallbackFunction.<Highcharts.SankeyNodeObject>": 'HIFunction',
"Highcharts.FormatterCallbackFunction.<Highcharts.StackItemObject>": 'HIFunction',
"null|*": '*',
#7.1.2
"string|number|function": 'id /* NSString, NSNumber, Function */',
"Highcharts.EventCallbackFunction.<Highcharts.Annotation>": 'HIFunction',
"Highcharts.FormatterCallbackFunction.<Highcharts.BubbleLegendFormatterContextObject>": 'HIFunction',
#namespace
"string|function|undefined": 'NSString',
"Highcharts.FormatterCallbackFunction.<Highcharts.SankeyNodeObject>|undefined": 'HIFunction',
"string|boolean|undefined": 'NSString',
"string|Highcharts.CSSObject|undefined": 'HICSSObject',
"string|Highcharts.GradientColorObject|Highcharts.PatternObject|undefined": 'HIColor',
"boolean|Highcharts.ShadowOptionsObject|undefined": 'HIShadowOptionsObject',
"boolean|Highcharts.AnimationOptionsObject|undefined": 'HIAnimationOptionsObject',
"string|Highcharts.SVGAttributes": 'HISVGAttributes',
#7.1.3
"Array.<Array.<number|string|null>>": 'NSArray<NSArray *>',
"Highcharts.FormatterCallbackFunction.<(Point|Series)>": 'HIFunction',
"Array.<(number|string|null), (number|string|null)>": 'NSArray /* <NSNumber, NSString> */',
"Highcharts.EventCallbackFunction.<Highcharts.PlotLineOrBand>": 'HIFunction',
"Highcharts.FormatterCallbackFunction.<Highcharts.PlotLineOrBand>": 'HIFunction',
"string|null|undefined": 'NSString',
#7.2.0
"number|string|boolean": 'id /* NSNumber, NSString */',
#8.0.0
"Array.<(*)>": 'NSArray',
#8.0.4
"Array.<(string|*)>": 'NSArray',
#8.1.1
"Array.<Array.<Highcharts.SVGPathCommand, number?, number?, number?, number?, number?, number?, number?>>": 'NSArray',
"string|Array.<Array.<string, number?, number?, number?, number?, number?, number?, number?>>|undefined": 'NSArray',
"Highcharts.FormatterCallbackFunction.<Series>": 'HIFunction',
#8.2.0
"string|Array.<(Array.<string>|Array.<string, number>|Array.<string, number, number>|Array.<string, number, number, number, number>|Array.<string, number, number, number, number, number, number>|Array.<string, number, number, number, number, number, number, number>)>|undefined": 'NSArray /* <NSString, NSNumber> */',
"Array.<Array.<number, string|Highcharts.GradientColorObject|Highcharts.PatternObject>>": 'NSArray',
#11.1.0
"'default'|'curved'|'straight'": 'NSString',
"Highcharts.SeriesPieDataLabelsOptionsObject": 'id',
"function|object": 'id',
"number|string|Highcharts.BorderRadiusOptionsObject": 'HIBorderRadiusOptionsObject',
"string|Highcharts.SynthPatchOptionsObject": 'HISynthPatchOptionsObject',
"DataLabelTextPathOptions": 'HIDataLabelTextPathOptions',
"OrganizationDataLabelsFormatterCallbackFunction": 'HIFunction',
"Array.<string|Highcharts.AnnotationMockPointOptionsObject|function>": 'NSArray<HIAnnotationMockPointOptionsObject *>',
"string|Highcharts.AnnotationMockPointOptionsObject|function": 'HIAnnotationMockPointOptionsObject',
"Highcharts.AnnotationsOptions": 'HIAnnotationsOptions',
"boolean|object": 'id',
"Array.<string>|undefined": 'NSArray<NSString *>',
"string|number|function|object": 'id',
"string|Highcharts.SVGAttributes|undefined": 'HISVGAttributes',
"Highcharts.DataLabelsOptions": 'HIDataLabelsOptions',
"Highcharts.PointMarkerOptionsObject": 'HIPointMarkerOptionsObject',
"Array.<(Array.<string>|Array.<string, number>|Array.<string, number, number>|Array.<string, number, number, number, number>|Array.<string, number, number, number, number, number, number>|Array.<string, number, number, number, number, number, number, number>)>": 'NSArray',
"Array.<('string'|'number'|'float'|'date')>": 'NSArray',
"'from'|'gradient'|'to'": 'NSString',
"number|'auto'": 'id /* NSNumber, NSString */',
"'top'|'center'|'bottom'": 'NSString',
#11.4.0
"'left'|'right'": 'NSString',
#11.4.3
"function|*": 'HIFunction',
"string|number|function|*": 'id',
#12.0.2
"string|Highcharts.DateTimeFormatOptions": 'HIDateTimeFormatOptions',
"Highcharts.Dictionary.<(string|Highcharts.DateTimeFormatOptions)>": 'NSDictionary',
"Array.<(string|Highcharts.DateTimeFormatOptions)>": 'NSArray'
}
def get_type(x):
return hc_types[str(x)]
def upper_first(x):
r = x[0].upper() + x[1:]
return r
def get_last(x):
last = ''
n = x.split(".")
last = n[len(n) - 1]
if last == 'description':
last = 'definition'
return last
def removeDuplicates(listofElements):
uniqueList = []
for elem in listofElements:
if elem not in uniqueList:
uniqueList.append(elem)
return uniqueList
def create_name(source):
name = source.split(".")[-1]
return name
def create_h_file(name):
source = structure[name]
h = None
if source.properties:
h = format_to_h(name, source)
if h:
filename = "HIChartsClasses/HI{0}.h".format(upper_first(create_name(name)))
files.append(upper_first(create_name(name)))
with open(filename, "w") as h_file:
h_file.write(h)
def create_m_file(name):
source = structure[name]
m = None
if source.properties:
m = format_to_m(name, source)
if m:
filename = "HIChartsClasses/HI{0}.m".format(upper_first(create_name(name)))
with open(filename, "w") as m_file:
m_file.write(m)
def added_new_properties(class_name, source):
isUpdated = False
isFirstMatch = True
if class_name in classes:
isFirstMatch = False
class_properties = classes[class_name]
for property in source.properties:
isExists = False
for class_property in class_properties:
if get_last(property.name) == get_last(class_property.name):
isExists = True
if not class_property.properties and property.properties:
class_property.properties = property.properties
isUpdated = True
if class_property.data_type is None and property.data_type is not None:
class_property.data_type = property.data_type
isUpdated = True
if not isExists:
class_properties.append(property)
isUpdated = True
classes[class_name] = class_properties
else:
classes[class_name] = source.properties
if not isUpdated and not isFirstMatch:
return False
return True
def field_in_parent(field, source):
in_parent = False
if source.extends:
if source.extends == "series":
extends_name = "plotOptions.series"
for i in structure[extends_name].properties:
if get_last(field.name) == get_last(i.name):
in_parent = True
for i in structure[source.extends].properties:
if get_last(field.name) == get_last(i.name):
in_parent = True
return in_parent
def format_to_h(name, source):
imports = ""
import_hi_set = set()
import_hi_string = ""
description = None
htext = ""
class_name = "HI" + upper_first(create_name(name))
if source.extends == 'series':
description = series_description.replace('#series_name#', get_last(name)) # markdown description dla poszczegolnych serii dla dokumentacji iOS
elif class_name in comments:
description = comments[class_name]
elif source.comment:
description = source.comment
x = name.split(".")
if len(x) == 2 and x[0] == "plotOptions":
pass
else:
comments[class_name] = source.comment
htext += description if description else "/**\n */\n"
if not added_new_properties(class_name, source):
return None
if source.extends is not None:
imports += "#import \"{0}.h\"\n".format("HI" + upper_first(source.extends))
htext += "@interface {0}: {1}\n\n".format(class_name, "HI" + upper_first(source.extends))
else:
htext += "@interface {0}: HIChartsJSONSerializable\n\n".format(class_name)
bridge.add("#import \"{0}.h\"\n".format(class_name))
for field in classes[class_name]:
if field_in_parent(field, source):
continue
if field.comment:
htext += "{0}".format(field.comment) if field.name != 'series.data' else series_data_description
if field.data_type:
if "id" in str(get_type(field.data_type)) and "NSArray" not in str(get_type(field.data_type)) and not \
structure[
field.name].properties:
type = "{0}".format(get_type(field.data_type))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0} {1};\n".format(type, get_last(field.name))
elif "NSArray" in str(get_type(field.data_type)) and field.name.endswith(">.data"):
type = "{0} *".format(get_type(field.data_type))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n".format(type, get_last(field.name))
elif "NSArray" in str(get_type(field.data_type)) and structure[field.name].properties and 'HI' not in get_type(field.data_type):
type = "{0} <{1} *> *".format(get_type(field.data_type), "HI" + upper_first(
create_name(
field.name)))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n".format(type, get_last(field.name))
imports += "#import \"{0}.h\"\n".format("HI" + upper_first(create_name(field.name)))
elif "NSArray" in str(get_type(field.data_type)):
type = "{0} *".format(get_type(field.data_type))
types[field.name] = type
hi_match = re.search(r'<(HI[A-Z]{1}[a-zA-Z]+) \*>', type)
if hi_match:
import_hi_set.add(hi_match.group(1))
htext += "@property(nonatomic, readwrite) {0}{1};\n".format(type, get_last(field.name))
elif field.data_type == "Object" or field.data_type == "object":
if structure[field.name].properties:
type = "{0} *".format("HI" + upper_first(create_name(field.name)))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n".format(type, get_last(field.name))
imports += "#import \"{0}.h\"\n".format("HI" + upper_first(create_name(field.name)))
else:
type = "id"
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0} {1};\n".format(type, get_last(field.name))
else:
if structure[field.name].properties and 'HI' not in get_type(field.data_type):
type = "{0} *".format("HI" + upper_first(create_name(field.name)))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n".format(type, get_last(field.name))
imports += "#import \"{0}.h\"\n".format("HI" + upper_first(create_name(field.name)))
else:
type = "{0} *".format(get_type(field.data_type))
types[field.name] = type
if 'HI' in type:
import_hi_set.add(get_type(field.data_type))
htext += "@property(nonatomic, readwrite) {0}{1};\n".format(type, get_last(field.name))
else:
if not field.data_type and not structure[field.name].properties:
type = "id"
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0} {1};\n".format(type, get_last(field.name))
elif structure[field.name].properties:
name = create_name(field.name)
type = "{0} *".format("HI" + upper_first(name))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n".format(type, get_last(field.name))
imports += "#import \"{0}.h\"\n".format("HI" + upper_first(name))
htext += "\n-(NSDictionary *)getParams;\n"
htext = htext.replace('*default;', '*defaults;')
if class_name == 'HILang':
htext = prepare_lang_class(htext) # iOS Lang class
elif class_name + '.h' in class_methods:
htext += '\n' + class_methods[class_name + '.h'] + '\n'
htext += "\n@end\n"
if class_name + '.txt' in class_methods:
class_methods_imports = class_methods[class_name + '.txt'].splitlines()
import_hi_set.update(class_methods_imports)
for match in import_hi_set:
import_hi_string += "#import \"" + match + ".h\"\n"
if 'HIColor' in import_hi_set:
import_hi_set.remove('HIColor')
if 'HIFunction' in import_hi_set:
import_hi_set.remove('HIFunction')
if imports == "" and len(import_hi_set) == 0:
imports += "#import \"HIChartsJSONSerializable.h\"\n"
imports += import_hi_string
imports += "\n\n"
return filelicense + imports + htext
def prepare_lang_class(text): # iOS Lang class
text = text.replace('*/\n@property(nonatomic, readwrite) NSString *downloadCSV;',
'\n**Defaults to** `Share CSV`.\n*/\n@property(nonatomic, readwrite) NSString *downloadCSV;')
text = text.replace('`Download PNG image`', '`Share image`')
text = text.replace('`Download PDF document`', '`Share PDF`')
text = text.replace('`Download JPEG image`', '`Share image`')
text = text.replace('NSString *contextButtonTitle;',
'NSString *contextButtonTitle;\n/**\nExporting module only. The text for the disabling menu button.\n\n**Defaults to** `Cancel`.\n*/\n@property(nonatomic, readwrite) NSString *cancelButtonTitle;')
return text
def create_setter(field):
setter_attribute = re.sub(r'\bdefault\b', 'defaults', get_last(field.name))
if field.name not in types:
types[field.name] = get_type(field.data_type)
setter_type = re.sub('\s/(.?)+/', '', types[field.name])
setter_text = "-(void)set{0}:({1}){2}".format(upper_first(setter_attribute), setter_type, setter_attribute) + " {\n"
if 'NSArray' in setter_type:
setter_text += "\t{0}oldValue = _{1};\n".format(setter_type, setter_attribute) + \
"\t_{0} = {0};\n".format(setter_attribute) + \
"\t[self updateArrayObject:oldValue newValue:{0} propertyName:@\"{0}\"];\n".format(setter_attribute)
elif 'HI' in setter_type:
setter_text += "\t{0}oldValue = _{1};\n".format(setter_type, setter_attribute) + \
"\t_{0} = {0};\n".format(setter_attribute) + \
"\t[self updateHIObject:oldValue newValue:{0} propertyName:@\"{0}\"];\n".format(setter_attribute)
# "\tif(self.{0})".format(setter_attribute) + " {\n" + \
# "\t\t[self removeObserver:self forKeyPath:@\"{0}.isUpdated\"];".format(setter_attribute) + "\n\t}\n" + \
else:
setter_text += "\t{0}oldValue = _{1};\n".format(re.sub(r'\bid\b', 'id ', setter_type), setter_attribute) + \
"\t_{0} = {0};\n".format(setter_attribute) + \
"\t[self updateNSObject:oldValue newValue:{0} propertyName:@\"{0}\"];\n".format(setter_attribute)
setter_text += "}"
return setter_text
def format_to_m(name, source):
class_name = "HI" + upper_first(create_name(name))
copyParamName = "copy" + upper_first(create_name(name))
mtext = "#import \"HIChartsJSONSerializableSubclass.h\"\n"
mtext += "#import \"{0}.h\"\n\n".format(class_name)
mtext += "@implementation {0}\n\n".format(class_name)
if source.extends:
mtext += "-(instancetype)init {\n\tif (self = [super init]) {" + \
"\n\t\tself.type = @\"{0}\";".format(create_name(name)) + \
"\n\t\treturn self;\n\t} else {\n\t\treturn nil;\n\t}\n}\n"
else:
mtext += "-(instancetype)init {\n\treturn [super init];\n}\n"
copyWithZones = "\n-(id)copyWithZone:(NSZone *)zone {\n\t[super copyWithZone:zone];" + "\n\t{0} *{1} = [[{0} allocWithZone: zone] init];\n".format(class_name, copyParamName)
getParams = "\n-(NSDictionary *)getParams\n{\n\tNSMutableDictionary *params =" \
" [NSMutableDictionary dictionaryWithDictionary: "
setters_text = "\n# pragma mark - Setters\n"
if source.extends:
getParams += "[super getParams]];\n"
else:
getParams += "@{}];\n"
if class_name + '.m' in class_methods:
getParams += "\tparams[@\"_wrapperID\"] = self.uuid;\n"
for field in classes[class_name]:
variableName = re.sub(r'\bdefault\b', 'defaults', get_last(field.name))
copyWithZones += "\t{0}.{1} = [self.{1} copyWithZone: zone];\n".format(copyParamName, variableName)
if field_in_parent(field, source):
pass
else:
getParams += "\tif (self.{0})".format(variableName) + " {\n"
if structure[field.name].data_type:
data_type = structure[field.name].data_type
if get_type(data_type) == 'HIFunction':
getParams += "\t\tparams[@\"{0}\"] = [self.{1} getFunction];\n".format(re.sub(r'\bdefaults\b', 'default', variableName),
variableName)
elif get_type(data_type) == 'HIColor':
getParams += "\t\tparams[@\"{0}\"] = [self.{1} getData];\n".format(re.sub(r'\bdefaults\b', 'default', variableName),
variableName)
elif get_type(data_type) == 'NSArray<HIColor *>':
getParams += "\t\tNSMutableArray *array = [[NSMutableArray alloc] init];\n"
getParams += "\t\tfor (HIColor *obj in self.{0})".format(variableName) + " {\n"
getParams += "\t\t\t[array addObject:[obj getData]];\n".format(variableName)
getParams += "\t\t}\n"
getParams += "\t\tparams[@\"{0}\"] = array;\n".format(re.sub(r'\bdefaults\b', 'default', variableName))
elif 'NSArray' in str(get_type(data_type)):
getParams += "\t\tNSMutableArray *array = [[NSMutableArray alloc] init];\n"
getParams += "\t\tfor (id obj in self.{0})".format(variableName) + " {\n"
getParams += "\t\t\tif ([obj isKindOfClass: [HIChartsJSONSerializable class]])".format(
variableName) + " {\n"
getParams += "\t\t\t\t[array addObject:[(HIChartsJSONSerializable *)obj getParams]];\n".format(
variableName)
getParams += "\t\t\t}\n"
getParams += "\t\t\telse {\n\t\t\t\t[array addObject: obj];\n"
getParams += "\t\t\t}\n"
getParams += "\t\t}\n"
getParams += "\t\tparams[@\"{0}\"] = array;\n".format(re.sub(r'\bdefaults\b', 'default', variableName))
elif structure[field.name].properties or 'HI' in get_type(field.data_type):
getParams += "\t\tparams[@\"{0}\"] = [self.{1} getParams];\n".format(re.sub(r'\bdefaults\b', 'default', variableName),
variableName)
else:
getParams += "\t\tparams[@\"{0}\"] = self.{1};\n".format(re.sub(r'\bdefaults\b', 'default', variableName), variableName)
elif structure[field.name].properties:
getParams += "\t\tparams[@\"{0}\"] = [self.{1} getParams];\n".format(re.sub(r'\bdefaults\b', 'default', variableName),
variableName)
getParams += "\t}\n"
setters_text += "\n" + create_setter(field) + "\n"
copyWithZones += "\treturn {};\n".format(copyParamName)
copyWithZones += "}\n"
getParams += "\treturn params;\n"
getParams += "}\n"
mtext += copyWithZones
mtext += getParams
if setters_text != "\n# pragma mark - Setters\n":
mtext += setters_text
if class_name + '.m' in class_methods:
mtext += '\n' + class_methods[class_name + '.m'] + '\n'
mtext += "\n@end"
return mtext
def create_options_files():
imports = "#import \"HIColor.h\"\n"
description = "/**\n */\n"
htext = "@interface HIOptions: HIChartsJSONSerializable\n\n"
mtext = "#import \"HIChartsJSONSerializableSubclass.h\"\n"
mtext += "#import \"HIOptions.h\"\n\n@implementation HIOptions\n\n"
mtext += "-(instancetype)init {\n\tif (self = [super init]) {\n" \
"\t\tHICredits *credits = [[HICredits alloc]init];\n" \
"\t\tcredits.enabled = @true;\n" \
"\t\tcredits.text = @\"Highcharts iOS\";\n" \
"\t\tcredits.href = @\"http://www.highcharts.com/blog/mobile/\";\n" \
"\t\tself.credits = credits;\n" \
"\t\treturn self;\n" \
"\t}\n" \
"\treturn nil;\n" \
"}\n\n"
mtext += "-(NSDictionary *)getParams {\n\tNSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary: @{}];\n"
setters_text = "\n# pragma mark - Setters\n"
for field in options:
if field.name != 'global' and field.name != 'lang':
if field.comment:
htext += "{0}".format(field.comment) if field.name != 'series' else "/**\nSeries options for specific data and the data itself. In TypeScript you have to cast the series options to specific series types, to get all possible options for a series.\n*/\n"
if upper_first((create_name(field.name))) in files:
imports += "#import \"HI{0}.h\"\n".format(upper_first(create_name(field.name)))
if structure[field.name].data_type:
if "id" in str(get_type(field.data_type)) and "NSArray" not in str(get_type(field.data_type)):
if structure[field.name].properties:
type = "{0} *".format("HI" + upper_first(create_name(field.name)))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n\n".format(type, get_last(field.name))
else:
type = "{0} ".format(get_type(field.data_type))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n\n".format(type, get_last(field.name))
elif "NSArray" in str(get_type(field.data_type)) and field.properties:
type = "{0}<{1} *> *".format(get_type(field.data_type), "HI" + upper_first(create_name(field.name)))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n\n".format(type, get_last(field.name))
else:
type = "{0} *".format(get_type(field.data_type))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n\n".format(type, get_last(field.name))
else:
type = "{0} *".format("HI" + upper_first(create_name(field.name)))
types[field.name] = type
htext += "@property(nonatomic, readwrite) {0}{1};\n\n".format(type, get_last(field.name))
htext += "/**\n* Additional options that are not listed above but are accepted by API\n*/\n"
htext += "@property(nonatomic, readwrite) NSDictionary *additionalOptions;\n"
htext += "\n-(NSDictionary *)getParams;\n"
copyWithZones = "\n-(id)copyWithZone:(NSZone *)zone {\n\t[super copyWithZone:zone];" + "\n\tHIOptions *copyOptions = [[HIOptions allocWithZone: zone] init];\n"
for field in options:
if field.name != 'global' and field.name != "lang":
mtext += "\tif (self.{0})".format(get_last(field.name)) + " {\n"
copyWithZones += "\tcopyOptions.{0} = [self.{0} copyWithZone: zone];\n".format(get_last(field.name))
if field.data_type:
if get_type(field.data_type) == 'HIColor':
mtext += "\t\tparams[@\"{0}\"] = [self.{1} getData];\n".format(get_last(field.name),
get_last(field.name))
elif get_type(field.data_type) == 'HIFunction':
mtext += "\t\tparams[@\"{0}\"] = [self.{1} getFunction];\n".format(get_last(field.name),
get_last(field.name))
elif get_type(field.data_type) == 'NSArray<HIColor *>':
mtext += "\t\tNSMutableArray *array = [[NSMutableArray alloc] init];\n"
mtext += "\t\tfor (HIColor *obj in self.{0})".format(get_last(field.name)) + " {\n"
mtext += "\t\t\t[array addObject:[obj getData]];\n".format(
get_last(field.name))
mtext += "\t\t}\n"
mtext += "\t\tparams[@\"{0}\"] = array;\n".format(get_last(field.name))
elif "NSArray" in str(get_type(field.data_type)):
mtext += "\t\tNSMutableArray *array = [[NSMutableArray alloc] init];\n"
mtext += "\t\tfor (id obj in self.{0})".format(get_last(field.name)) + " {\n"
mtext += "\t\t\tif ([obj isKindOfClass: [HIChartsJSONSerializable class]])".format(
get_last(field.name)) + " {\n"
mtext += "\t\t\t\t[array addObject:[(HIChartsJSONSerializable *)obj getParams]];\n".format(
get_last(field.name))
mtext += "\t\t\t}\n"
mtext += "\t\t\telse {\n\t\t\t\t[array addObject: obj];\n"
mtext += "\t\t\t}\n"
mtext += "\t\t}\n"
mtext += "\t\tparams[@\"{0}\"] = array;\n".format(get_last(field.name))
elif structure[field.name].properties:
mtext += "\t\tparams[@\"{0}\"] = [self.{1} getParams];\n".format(get_last(field.name),
get_last(field.name))
else:
mtext += "\t\tparams[@\"{0}\"] = self.{1};\n".format(get_last(field.name), get_last(field.name))
elif structure[field.name].properties:
mtext += "\t\tparams[@\"{0}\"] = [self.{1} getParams];\n".format(get_last(field.name), get_last(field.name))
mtext += "\t}\n"
setters_text += "\n" + create_setter(field) + "\n"
mtext += "\tif (self.additionalOptions) {\n\t\t[params addEntriesFromDictionary: self.additionalOptions];\n\t}\n\n"
setters_text += "\n-(void)set{0}:({1}){2}".format("AdditionalOptions", "NSDictionary *", "additionalOptions") + " {\n" + \
"\tNSDictionary *oldValue = _{0};\n".format("additionalOptions") + \
"\t_{0} = {0};\n".format("additionalOptions") + \
"\t[self updateNSObject:oldValue newValue:{0} propertyName:@\"{0}\"];\n".format("additionalOptions") + \
"}\n"
# "\t[self updateNSObject:@\"{0}\"];\n".format("additionalOptions") + \
copyWithZones += "\treturn copyOptions;\n}\n"
mtext += "\treturn params;\n"
mtext += "}\n"
mtext += copyWithZones
mtext += setters_text
mtext += "\n@end"
imports += "\n\n"
htext += "\n@end\n"
with open("HIChartsClasses/HIOptions.h", "w") as o:
o.write(imports + description + htext)
with open("HIChartsClasses/HIOptions.m", "w") as m:
m.write(mtext)
def create_bridge_file():
text = ""
for field in bridge:
text += field
text += "#import \"HIColor.h\"\n"
text += "#import \"HIFunction.h\"\n"
text += "#import \"HIOptions.h\"\n"
with open("HIBridge.h", "w") as b:
b.write(text)
def create_files_for_main_class(field):
main = create_name(field)
class_name = "HI" + upper_first(main)
if main in structure and class_name not in classes:
create_h_file(main)
create_m_file(main)
def create_files():
if not os.path.exists("HIChartsClasses"):
os.makedirs("HIChartsClasses")
for field in structure:
create_files_for_main_class(field)
create_h_file(field)
create_m_file(field)
create_options_files()
create_bridge_file()
def print_structure():
for c in structure:
# text = "name: {0}, type: {1}, group: {3}, extends: {2}, props: ".format(c, structure[c].data_type, structure[c].extends, structure[c].group)
text = "name: {0}, type: {1}, props: ".format(c, structure[c].data_type)
for p in structure[c].properties:
text += "{0} | ".format(p.name)
print text
def get_documentation_name(name, isProperties, doubleLast = True):
ret = str(name)
ret = ret.replace("description", "definition")
x = ret.split(".")
if len(x) > 1:
ret = x[0]
if len(x) > 2:
for i in range(1, len(x) - 1):
ret += "-{0}".format(x[i])
if doubleLast:
if isProperties:
ret += "-{0}".format(x[len(x) - 1])
else:
ret += "--{0}".format(x[len(x) - 1])
else:
ret += "-{0}".format(x[len(x) - 1])
else:
ret = x[0]
return ret
def add_entry_to_documentation(documentation, field, source):
entry = dict()
name = get_last(field)
returnType = ""
isParent = False
isProperties = False
doclet = None
if "doclet" in source.info:
doclet = source.info["doclet"]
if source.properties:
isParent = True
returnType = "HI" + upper_first(create_name(field))
elif source.data_type:
returnType = get_type(source.data_type)
parent = None
if source.parent:
parent = source.parent
if source.properties:
isProperties = source.properties
entry["_id"] = get_documentation_name(field, isProperties)
entry["fullname"] = field.replace("description", "definition")
entry["title"] = name.replace("description", "definition")
if source.description and source.description != "":
entry["description"] = source.description
if source.demo:
demo = ""
lines = source.demo.splitlines()
for line in lines:
items = line.split(" : ")
for item in items:
if "https://" in item:
demo += "{}{}{}".format("<a href=\"", item, "\">")
else:
demo += "{}{}".format(item.rstrip(), "</a>\n")
entry["demo"] = demo
if source.defaults:
entry["defaults"] = source.defaults
if source.values:
entry["values"] = source.values
if doclet and "since" in doclet:
entry["since"] = doclet["since"]
entry["deprecated"] = doclet["deprecated"] if doclet and "deprecated" in doclet else False
if doclet and "see" in doclet:
seeAlso = ""
for see in doclet["see"]:
m = re.search('\[(.+)\]\((.+)\)', see)
if m:
if seeAlso != "":
seeAlso += ", <a href=\"{}\">{}</a>".format(m.group(2), m.group(1))
else:
seeAlso += "<p><a href=\"{}\">{}</a>".format(m.group(2), m.group(1))
else:
seeAlso += "<p>{}".format(see)
if seeAlso != "":
seeAlso += "</p>\n"
entry["seeAlso"] = seeAlso
if returnType != "":
entry["returnType"] = returnType
entry["isParent"] = isParent
if parent:
entry["parent"] = parent
documentation.append(entry)
def add_to_documentation(documentation, field, parent):
add_entry_to_documentation(documentation, field, structure[parent])
if structure[parent].properties:
for property in structure[parent].properties:
if field != "series":
children = "{0}.{1}".format(field, get_last(property.name))
add_to_documentation(documentation, children, property.name)
def generate_documentation():
documentation = list()
for field in structure:
add_to_documentation(documentation, field, field)
entry = dict()