Skip to content

Commit 5542d34

Browse files
committed
WIP
1 parent 3378757 commit 5542d34

6 files changed

Lines changed: 51 additions & 2 deletions

File tree

babelapi/babel/lexer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,17 @@ def test(self, data):
129129
'STRING',
130130
)
131131

132+
tokens += (
133+
'ASTERIX',
134+
)
135+
132136
# Regular expression rules for simple tokens
133137
t_LPAR = r'\('
134138
t_RPAR = r'\)'
135139
t_EQ = r'='
136140
t_COMMA = r','
137141
t_PIPE = r'\|'
142+
t_ASTERIX = r'\*'
138143

139144
KEYWORDS = [
140145
'alias',

babelapi/babel/parser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def __repr__(self):
6363
self.name,
6464
)
6565

66+
class BabelCatchAllSymbol(object):
67+
def __init__(self, name):
68+
self.name = name
69+
def __str__(self):
70+
return self.__repr__()
71+
def __repr__(self):
72+
return 'BabelCatchAllSymbol({!r})'.format(
73+
self.name,
74+
)
75+
6676
class BabelNamespace(object):
6777
def __init__(self, name):
6878
self.name = name
@@ -413,6 +423,10 @@ def p_statement_field_symbol(self, p):
413423
else:
414424
p[0].set_doc(p[4])
415425

426+
def p_statement_field_catchall(self, p):
427+
"""field : ASTERIX ID NEWLINE"""
428+
p[0] = BabelCatchAllSymbol(p[2])
429+
416430
def p_statement_example(self, p):
417431
"""example : KEYWORD ID STRING NEWLINE INDENT example_field_list DEDENT
418432
| KEYWORD ID empty NEWLINE INDENT example_field_list DEDENT"""

babelapi/babel/tower.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
)
3131
from babelapi.babel.parser import (
3232
BabelAlias,
33+
BabelCatchAllSymbol,
3334
BabelInclude,
3435
BabelNamespace,
3536
BabelRouteDef,
@@ -132,8 +133,11 @@ def _create_type(self, env, item):
132133
% item.composite_type)
133134
api_type_fields = []
134135
for babel_field in item.fields:
135-
api_type_field = self._create_field(env, babel_field)
136-
api_type_fields.append(api_type_field)
136+
if isinstance(babel_field, BabelCatchAllSymbol):
137+
pass
138+
else:
139+
api_type_field = self._create_field(env, babel_field)
140+
api_type_fields.append(api_type_field)
137141
api_type = composite_type_obj(item.name, item.doc, api_type_fields, super_type)
138142
for example_label, (example_text, example) in item.examples.items():
139143
api_type.add_example(example_label, example_text, dict(example))
@@ -150,6 +154,8 @@ def _create_field(self, env, babel_field):
150154
"""
151155
if isinstance(babel_field, BabelSymbol):
152156
api_type_field = SymbolField(babel_field.name, babel_field.doc)
157+
#elif isinstance(babel_field, BabelCatchAllSymbol):
158+
# pass
153159
elif babel_field.data_type_name not in env:
154160
raise Exception('Symbol %r is undefined' % babel_field.data_type_name)
155161
else:

babelapi/data_type.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ class Union(CompositeType):
505505

506506
composite_type = 'union'
507507

508+
def __init__(self, name, doc, fields, super_type=None, open_field=None):
509+
super(CompositeType, self).__init__(name, doc, fields, super_type=super_type)
510+
self.open_field = open_field
511+
508512
def check(self, val):
509513
if isinstance(val, dict):
510514
assert isinstance(val, dict), 'val must be a dict'

example/api/dbx-core/files.babel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ union ConflictReason
9898
"Conflict with a file."
9999
autorename_failed
100100
"Could not autorename."
101+
*unknown
101102

102103
struct ConflictError
103104
reason ConflictReason

example/generator/dropbox-python-sdk/base_files.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,26 +492,31 @@ class ConflictReason(object):
492492
Folder = object()
493493
File = object()
494494
AutorenameFailed = object()
495+
Unknown = object()
495496

496497
def __init__(self,
497498
folder=None,
498499
file=None,
499500
autorename_failed=None,
501+
unknown=None,
500502
**kwargs):
501503
"""
502504
Only one argument can be set.
503505
504506
:param bool folder: Conflict with a folder.
505507
:param bool file: Conflict with a file.
506508
:param bool autorename_failed: Could not autorename.
509+
:type unknown: bool
507510
"""
508511
assert_only_one(folder=folder,
509512
file=file,
510513
autorename_failed=autorename_failed,
514+
unknown=unknown,
511515
**kwargs)
512516
self.folder = None
513517
self.file = None
514518
self.autorename_failed = None
519+
self.unknown = None
515520

516521
if folder is not None:
517522
assert isinstance(folder, bool), 'folder must be of type bool'
@@ -528,6 +533,11 @@ def __init__(self,
528533
self.autorename_failed = autorename_failed
529534
self._tag = 'autorename_failed'
530535

536+
if unknown is not None:
537+
assert isinstance(unknown, bool), 'unknown must be of type bool'
538+
self.unknown = unknown
539+
self._tag = 'unknown'
540+
531541
def is_folder(self):
532542
return self._tag == 'folder'
533543

@@ -537,6 +547,9 @@ def is_file(self):
537547
def is_autorename_failed(self):
538548
return self._tag == 'autorename_failed'
539549

550+
def is_unknown(self):
551+
return self._tag == 'unknown'
552+
540553
@classmethod
541554
def from_json(self, obj):
542555
obj = copy.copy(obj)
@@ -547,6 +560,8 @@ def from_json(self, obj):
547560
return obj
548561
if obj == 'autorename_failed':
549562
return obj
563+
if obj == 'unknown':
564+
return obj
550565
return ConflictReason(**obj)
551566

552567
def to_json(self):
@@ -556,6 +571,8 @@ def to_json(self):
556571
return self._tag
557572
if self._tag == 'autorename_failed':
558573
return self._tag
574+
if self._tag == 'unknown':
575+
return self._tag
559576

560577
def __repr__(self):
561578
return 'ConflictReason(%r)' % self._tag
@@ -574,6 +591,8 @@ def __init__(self,
574591
self.reason = ConflictReason(file=True)
575592
if reason == ConflictReason.AutorenameFailed:
576593
self.reason = ConflictReason(autorename_failed=True)
594+
if reason == ConflictReason.Unknown:
595+
self.reason = ConflictReason(unknown=True)
577596

578597
@classmethod
579598
def from_json(cls, obj):

0 commit comments

Comments
 (0)