Coverage for C:\Repos\leo-editor\leo\plugins\importers\dart.py: 97%
30 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
1#@+leo-ver=5-thin
2#@+node:ekr.20141116100154.1: * @file ../plugins/importers/dart.py
3"""The @auto importer for the dart language."""
4import re
5from leo.plugins.importers import linescanner
6Importer = linescanner.Importer
7#@+others
8#@+node:ekr.20161123120245.2: ** class Dart_Importer
9class Dart_Importer(Importer):
10 """The importer for the dart lanuage."""
12 def __init__(self, importCommands, **kwargs):
13 """Dart_Importer.__init__"""
14 super().__init__(
15 importCommands,
16 language='dart',
17 state_class=Dart_ScanState,
18 strict=False,
19 )
21 #@+others
22 #@+node:ekr.20161123121021.1: *3* dart_i.clean_headline
23 dart_pattern = re.compile(r'^\s*([\w_][\w_\s]*)\(')
25 def clean_headline(self, s, p=None):
27 m = self.dart_pattern.match(s)
28 return m.group(0).strip('(').strip() if m else s.strip()
29 #@-others
30#@+node:ekr.20161123120245.6: ** class class Dart_ScanState
31class Dart_ScanState:
32 """A class representing the state of the dart line-oriented scan."""
34 def __init__(self, d=None):
35 """Dart_ScanState.__init__"""
36 if d:
37 prev = d.get('prev')
38 self.context = prev.context
39 self.curlies = prev.curlies
40 else:
41 self.context = ''
42 self.curlies = 0
44 def __repr__(self):
45 """Dart_ScanState.__repr__"""
46 return "Dart_ScanState context: %r curlies: %s" % (
47 self.context, self.curlies)
49 __str__ = __repr__
51 #@+others
52 #@+node:ekr.20161123120245.7: *3* dart_state.level
53 def level(self):
54 """Dart_ScanState.level."""
55 return self.curlies
56 #@+node:ekr.20161123120245.8: *3* dart_state.update
57 def update(self, data):
58 """
59 Dart_ScanState.update
61 Update the state using the 6-tuple returned by i.scan_line.
62 Return i = data[1]
63 """
64 context, i, delta_c, delta_p, delta_s, bs_nl = data
65 # All ScanState classes must have a context ivar.
66 self.context = context
67 self.curlies += delta_c
68 return i
69 #@-others
70#@-others
71importer_dict = {
72 'func': Dart_Importer.do_import(),
73 'extensions': ['.dart'],
74}
75#@@language python
76#@@tabwidth -4
77#@-leo