Skip to content

Commit 895cca0

Browse files
committed
Fix parsing of table.el-style dividers
See amake/orgro#177
1 parent 4a35175 commit 895cca0

3 files changed

Lines changed: 63 additions & 5 deletions

File tree

lib/src/org/grammar.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,13 @@ class OrgContentGrammarDefinition extends GrammarDefinition {
591591
.flatten(message: 'Trailing line content expected') &
592592
ref0(lineTrailing).flatten(message: 'Trailing line content expected');
593593

594+
// This grammar can actually be customized in table.el; see
595+
// `table-cell-*-char(s)`. See `table-recognize` for where they are combined
596+
// for parsing purposes.
594597
Parser tableDotElDivider() =>
595598
ref0(indent).flatten(message: 'Table.el divider indent expected') &
596-
(string('+-') & anyOf('+-').starString())
599+
// At least three characters required
600+
(string('+-') & anyOf('+-').plusString())
597601
.flatten(message: 'Table divider expected') &
598602
ref0(lineTrailing).flatten(message: 'Trailing line content expected');
599603

test/org/grammar/content_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@ bazinga''');
3939
]
4040
]);
4141
});
42+
group('markup', () {
43+
test('markup edge case', () {
44+
// https://github.com/amake/orgro/issues/177
45+
final result = parser.parse('''+- Some text here+
46+
- Some text here''');
47+
expect(result.value, [
48+
[
49+
'',
50+
[
51+
['+', '- Some text here', '+'],
52+
'\n'
53+
],
54+
''
55+
],
56+
[
57+
[
58+
[
59+
'',
60+
'-',
61+
[
62+
' ',
63+
null,
64+
null,
65+
['Some text here']
66+
]
67+
]
68+
],
69+
''
70+
]
71+
]);
72+
});
73+
});
4274
group('link', () {
4375
test('bare HTTP URL', () {
4476
final result = parser.parse('a http://example.com b');

test/org/grammar/table_test.dart

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import 'package:petitparser/petitparser.dart';
33
import 'package:test/test.dart';
44

55
void main() {
6+
final grammar = OrgContentGrammarDefinition();
7+
final parser = grammar.buildFrom(grammar.table()).end();
68
test('table', () {
7-
final grammar = OrgContentGrammarDefinition();
8-
final parser = grammar.buildFrom(grammar.table()).end();
99
final result = parser.parse(''' | foo | bar | baz |
1010
|-----+-----+-----|
1111
| 1 | 2 | 3 |
@@ -39,8 +39,6 @@ void main() {
3939
});
4040
test('table containing plus', () {
4141
// https://github.com/amake/orgro/issues/175
42-
final grammar = OrgContentGrammarDefinition();
43-
final parser = grammar.buildFrom(grammar.table()).end();
4442
final result = parser.parse(''' |-------+------|
4543
| +Text | Text |
4644
|-------+------|
@@ -74,4 +72,28 @@ void main() {
7472
''
7573
]);
7674
});
75+
test('minimal table', () {
76+
final result = parser.parse('+-+');
77+
expect(result.value, [
78+
[
79+
['', '+-+', '']
80+
],
81+
''
82+
]);
83+
});
84+
test('minimal table 2', () {
85+
// This doesn't look valid but `table-recognize` accepts it.
86+
final result = parser.parse('+--');
87+
expect(result.value, [
88+
[
89+
['', '+--', '']
90+
],
91+
''
92+
]);
93+
});
94+
test('invalid', () {
95+
// https://github.com/amake/orgro/issues/177
96+
final result = parser.parse('''+- Some text here+''');
97+
expect(result, isA<Failure>());
98+
});
7799
}

0 commit comments

Comments
 (0)