Skip to content

Commit 1ebc555

Browse files
committed
formatted source code with https://github.com/dart-lang/dart_style
1 parent b1f2f37 commit 1ebc555

30 files changed

+272
-308
lines changed

lib/xml/builder.dart

+13-17
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ part of xml;
44
* A builder to create XML trees with code.
55
*/
66
class XmlBuilder {
7-
8-
final List<_XmlNodeBuilder> _stack = new List.from([new _XmlDocumentBuilder()]);
7+
final List<_XmlNodeBuilder> _stack =
8+
new List.from([new _XmlDocumentBuilder()]);
99

1010
/**
1111
* Adds a [XmlText] node with the provided [text].
@@ -95,11 +95,9 @@ class XmlBuilder {
9595
* });
9696
*
9797
*/
98-
void element(String name, {
99-
String namespace: null,
98+
void element(String name, {String namespace: null,
10099
Map<String, String> namespaces: const {},
101-
Map<String, String> attributes: const {},
102-
nest: null}) {
100+
Map<String, String> attributes: const {}, nest: null}) {
103101
var element = new _XmlElementBuilder();
104102
_stack.add(element);
105103
namespaces.forEach(this.namespace);
@@ -127,7 +125,8 @@ class XmlBuilder {
127125
*
128126
*/
129127
void attribute(String name, value, {String namespace}) {
130-
_stack.last.attributes.add(new XmlAttribute(_buildName(name, namespace), value.toString()));
128+
_stack.last.attributes
129+
.add(new XmlAttribute(_buildName(name, namespace), value.toString()));
131130
}
132131

133132
/**
@@ -140,7 +139,8 @@ class XmlBuilder {
140139
throw new ArgumentError('The "$prefix" prefix cannot be bound.');
141140
}
142141
if (_stack.last.namespaces.containsValue(prefix)) {
143-
throw new ArgumentError('The "$prefix" prefix conflicts with existing binding.');
142+
throw new ArgumentError(
143+
'The "$prefix" prefix conflicts with existing binding.');
144144
}
145145
var name = prefix == null || prefix.isEmpty
146146
? new XmlName(_XMLNS)
@@ -164,8 +164,8 @@ class XmlBuilder {
164164
// Internal method to lookup an namespace prefix.
165165
String _lookup(String uri) {
166166
var builder = _stack.lastWhere(
167-
(builder) => builder.namespaces.containsKey(uri),
168-
orElse: () => throw new ArgumentError('Undefined namespace: $uri'));
167+
(builder) => builder.namespaces.containsKey(uri),
168+
orElse: () => throw new ArgumentError('Undefined namespace: $uri'));
169169
return builder.namespaces[uri];
170170
}
171171

@@ -179,7 +179,6 @@ class XmlBuilder {
179179
text(value.toString());
180180
}
181181
}
182-
183182
}
184183

185184
abstract class _XmlNodeBuilder {
@@ -190,25 +189,23 @@ abstract class _XmlNodeBuilder {
190189
}
191190

192191
class _XmlDocumentBuilder extends _XmlNodeBuilder {
193-
194192
@override
195-
final Map<String, String> namespaces = const { _XML_URI: _XML };
193+
final Map<String, String> namespaces = const {_XML_URI: _XML};
196194

197195
@override
198196
List<XmlAttribute> get attributes {
199-
throw new ArgumentError('Unable to define attributes at the document level.');
197+
throw new ArgumentError(
198+
'Unable to define attributes at the document level.');
200199
}
201200

202201
@override
203202
final List<XmlNode> children = new List();
204203

205204
@override
206205
XmlNode build() => new XmlDocument(children);
207-
208206
}
209207

210208
class _XmlElementBuilder extends _XmlNodeBuilder {
211-
212209
@override
213210
final Map<String, String> namespaces = new Map();
214211

@@ -222,5 +219,4 @@ class _XmlElementBuilder extends _XmlNodeBuilder {
222219

223220
@override
224221
XmlNode build() => new XmlElement(name, attributes, children);
225-
226222
}

lib/xml/grammar.dart

+38-41
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ part of xml;
66
abstract class XmlGrammarDefinition extends GrammarDefinition {
77

88
// name patterns
9-
static const NAME_START_CHARS = ':A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF'
9+
static const NAME_START_CHARS =
10+
':A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF'
1011
'\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001\uD7FF'
1112
'\uF900-\uFDCF\uFDF0-\uFFFD';
12-
static const NAME_CHARS = '-.0-9\u00B7\u0300-\u036F\u203F-\u2040$NAME_START_CHARS';
13+
static const NAME_CHARS =
14+
'-.0-9\u00B7\u0300-\u036F\u203F-\u2040$NAME_START_CHARS';
1315
static const CHAR_DATA = '^<';
1416

1517
// basic tokens
@@ -52,19 +54,15 @@ abstract class XmlGrammarDefinition extends GrammarDefinition {
5254
.seq(ref(space).optional())
5355
.seq(ref(attributeValue))
5456
.map((each) => createAttribute(each[0], each[4]));
55-
attributeValue() => ref(attributeValueDouble)
56-
.or(ref(attributeValueSingle))
57-
.pick(1);
57+
attributeValue() =>
58+
ref(attributeValueDouble).or(ref(attributeValueSingle)).pick(1);
5859
attributeValueDouble() => char(DOUBLE_QUOTE)
5960
.seq(new _XmlCharacterDataParser(DOUBLE_QUOTE, 0))
6061
.seq(char(DOUBLE_QUOTE));
6162
attributeValueSingle() => char(SINGLE_QUOTE)
6263
.seq(new _XmlCharacterDataParser(SINGLE_QUOTE, 0))
6364
.seq(char(SINGLE_QUOTE));
64-
attributes() => ref(space)
65-
.seq(ref(attribute))
66-
.pick(1)
67-
.star();
65+
attributes() => ref(space).seq(ref(attribute)).pick(1).star();
6866
comment() => string(OPEN_COMMENT)
6967
.seq(any().starLazy(string(CLOSE_COMMENT)).flatten())
7068
.seq(string(CLOSE_COMMENT))
@@ -82,65 +80,64 @@ abstract class XmlGrammarDefinition extends GrammarDefinition {
8280
doctype() => string(OPEN_DOCTYPE)
8381
.seq(ref(space))
8482
.seq(ref(nameToken)
85-
.or(ref(attributeValue))
86-
.or(any().starLazy(char(OPEN_DOCTYPE_BLOCK))
87-
.seq(char(OPEN_DOCTYPE_BLOCK))
88-
.seq(any().starLazy(char(CLOSE_DOCTYPE_BLOCK)))
89-
.seq(char(CLOSE_DOCTYPE_BLOCK)))
90-
.separatedBy(ref(space))
91-
.flatten())
83+
.or(ref(attributeValue))
84+
.or(any()
85+
.starLazy(char(OPEN_DOCTYPE_BLOCK))
86+
.seq(char(OPEN_DOCTYPE_BLOCK))
87+
.seq(any().starLazy(char(CLOSE_DOCTYPE_BLOCK)))
88+
.seq(char(CLOSE_DOCTYPE_BLOCK)))
89+
.separatedBy(ref(space))
90+
.flatten())
9291
.seq(ref(space).optional())
9392
.seq(char(CLOSE_DOCTYPE))
9493
.map((each) => createDoctype(each[2]));
95-
document() => ref(processing).optional()
94+
document() => ref(processing)
95+
.optional()
9696
.seq(ref(misc))
9797
.seq(ref(doctype).optional())
9898
.seq(ref(misc))
9999
.seq(ref(element))
100100
.seq(ref(misc))
101-
.map((each) => createDocument([each[0], each[2], each[4]].where((each) => each != null)));
101+
.map((each) => createDocument(
102+
[each[0], each[2], each[4]].where((each) => each != null)));
102103
element() => char(OPEN_ELEMENT)
103104
.seq(ref(qualified))
104105
.seq(ref(attributes))
105106
.seq(ref(space).optional())
106-
.seq(string(CLOSE_END_ELEMENT)
107-
.or(char(CLOSE_ELEMENT)
107+
.seq(string(CLOSE_END_ELEMENT).or(char(CLOSE_ELEMENT)
108108
.seq(ref(content))
109109
.seq(string(OPEN_END_ELEMENT))
110110
.seq(ref(qualified))
111111
.seq(ref(space).optional())
112112
.seq(char(CLOSE_ELEMENT))))
113113
.map((list) {
114-
if (list[4] == CLOSE_END_ELEMENT) {
115-
return createElement(list[1], list[2], []);
116-
} else {
117-
if (list[1] == list[4][3]) {
118-
return createElement(list[1], list[2], list[4][1]);
119-
} else {
120-
throw new ArgumentError('Expected </${list[1]}>, but found </${list[4][3]}>');
121-
}
122-
}
123-
});
114+
if (list[4] == CLOSE_END_ELEMENT) {
115+
return createElement(list[1], list[2], []);
116+
} else {
117+
if (list[1] == list[4][3]) {
118+
return createElement(list[1], list[2], list[4][1]);
119+
} else {
120+
throw new ArgumentError(
121+
'Expected </${list[1]}>, but found </${list[4][3]}>');
122+
}
123+
}
124+
});
124125
processing() => string(OPEN_PROCESSING)
125126
.seq(ref(nameToken))
126127
.seq(ref(space)
127-
.seq(any().starLazy(string(CLOSE_PROCESSING)).flatten())
128-
.pick(1).optional(''))
128+
.seq(any().starLazy(string(CLOSE_PROCESSING)).flatten())
129+
.pick(1)
130+
.optional(''))
129131
.seq(string(CLOSE_PROCESSING))
130132
.map((each) => createProcessing(each[1], each[2]));
131133
qualified() => ref(nameToken).map(createQualified);
132134

133-
characterData() => new _XmlCharacterDataParser(OPEN_ELEMENT, 1).map(createText);
134-
misc() => ref(space)
135-
.or(ref(comment))
136-
.or(ref(processing))
137-
.star();
135+
characterData() =>
136+
new _XmlCharacterDataParser(OPEN_ELEMENT, 1).map(createText);
137+
misc() => ref(space).or(ref(comment)).or(ref(processing)).star();
138138
space() => whitespace().plus();
139139

140-
nameToken() => ref(nameStartChar)
141-
.seq(ref(nameChar).star())
142-
.flatten();
140+
nameToken() => ref(nameStartChar).seq(ref(nameChar).star()).flatten();
143141
nameStartChar() => pattern(NAME_START_CHARS, 'Expected name');
144142
nameChar() => pattern(NAME_CHARS);
145-
146143
}

lib/xml/iterators/ancestors.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ part of xml;
44
* Iterable to walk over the ancestors of a node.
55
*/
66
class _XmlAncestorsIterable extends IterableBase<XmlNode> {
7-
87
final XmlNode start;
98

109
_XmlAncestorsIterable(this.start);
1110

1211
@override
1312
Iterator<XmlNode> get iterator => new _XmlAncestorsIterator(start);
14-
1513
}
1614

1715
/**
1816
* Iterator to walk over the ancestors of a node.
1917
*/
2018
class _XmlAncestorsIterator extends Iterator<XmlNode> {
21-
2219
_XmlAncestorsIterator(this.current);
2320

2421
@override
@@ -31,5 +28,4 @@ class _XmlAncestorsIterator extends Iterator<XmlNode> {
3128
}
3229
return current != null;
3330
}
34-
35-
}
31+
}

lib/xml/iterators/descendants.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ part of xml;
44
* Iterable to walk over the descendants of a node.
55
*/
66
class _XmlDescendantsIterable extends IterableBase<XmlNode> {
7-
87
final XmlNode start;
98

109
_XmlDescendantsIterable(this.start);
1110

1211
@override
1312
Iterator<XmlNode> get iterator => new _XmlDescendantsIterator(start);
14-
1513
}
1614

1715
/**
1816
* Iterator to walk over the descendants of a node.
1917
*/
2018
class _XmlDescendantsIterator extends Iterator<XmlNode> {
21-
2219
final List<XmlNode> todo = new List();
2320

2421
_XmlDescendantsIterator(XmlNode start) {
@@ -44,5 +41,4 @@ class _XmlDescendantsIterator extends Iterator<XmlNode> {
4441
return true;
4542
}
4643
}
47-
48-
}
44+
}

lib/xml/iterators/following.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@ part of xml;
44
* Iterable to walk over the followers of a node.
55
*/
66
class _XmlFollowingIterable extends IterableBase<XmlNode> {
7-
87
final XmlNode start;
98

109
_XmlFollowingIterable(this.start);
1110

1211
@override
1312
Iterator<XmlNode> get iterator => new _XmlFollowingIterator(start);
14-
1513
}
1614

1715
/**
1816
* Iterator to walk over the followers of a node.
1917
*/
2018
class _XmlFollowingIterator extends Iterator<XmlNode> {
21-
2219
final List<XmlNode> todo = new List();
2320

2421
_XmlFollowingIterator(XmlNode start) {
2522
var following = new List();
26-
for (var parent = start.parent, child = start; parent != null;
27-
parent = parent.parent, child = child.parent) {
23+
for (var parent = start.parent,
24+
child = start;
25+
parent != null;
26+
parent = parent.parent,
27+
child = child.parent) {
2828
var attributes_index = parent.attributes.indexOf(child);
2929
if (attributes_index != -1) {
3030
following.addAll(parent.attributes.sublist(attributes_index + 1));
@@ -56,5 +56,4 @@ class _XmlFollowingIterator extends Iterator<XmlNode> {
5656
return true;
5757
}
5858
}
59-
6059
}

lib/xml/iterators/preceding.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@ part of xml;
44
* Iterable to walk over the precedents of a node.
55
*/
66
class _XmlPrecedingIterable extends IterableBase<XmlNode> {
7-
87
final XmlNode start;
98

109
_XmlPrecedingIterable(this.start);
1110

1211
@override
1312
Iterator<XmlNode> get iterator => new _XmlPrecedingIterator(start);
14-
1513
}
1614

1715
/**
1816
* Iterator to walk over the precedents of a node.
1917
*/
2018
class _XmlPrecedingIterator extends Iterator<XmlNode> {
21-
2219
final XmlNode start;
2320
final List<XmlNode> todo = new List();
2421

@@ -46,5 +43,4 @@ class _XmlPrecedingIterator extends Iterator<XmlNode> {
4643
return true;
4744
}
4845
}
49-
50-
}
46+
}

lib/xml/nodes/attribute.dart

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ part of xml;
44
* XML attribute node.
55
*/
66
class XmlAttribute extends XmlNode implements XmlNamed {
7-
87
@override
98
final XmlName name;
109

@@ -26,5 +25,4 @@ class XmlAttribute extends XmlNode implements XmlNamed {
2625

2726
@override
2827
accept(XmlVisitor visitor) => visitor.visitAttribute(this);
29-
3028
}

0 commit comments

Comments
 (0)