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
/*!
# DaisyChain
- provides a library for parsing unicode text
- aims to have a gentle and intuitive API, without sacrificing performance (it can be zero-copy)
- as library, rather than a framework, it can be used alongside and complement other parsing toolkits
Main concepts:
# Cursor
represents:
- a point in the file/string being parsed
- the concept of "selected text", which like a text-editor, is a highlighted section of text
- a sense of whether parse matching has succeeded or not
Logically , one could image a Cursor as a structure with
```unknown
usize: the index into the parsed text/the current curosr position
&str: a reference to the highlighted selected text
bool: whether matching has failed
```
`The quick brown fox jumps over the lazy dog`<br>
` =============== ^`
In the example above the cursor has position at the `o` in over, with "quick bown fox" being the selected text.
Typically methods on cursor are invoked in a chained fashion. If a matching issue arises,
subsequent methods has no effect (similar to repeatedly calling next() having reached the end of a fused rust iterator..)
```
use daisychain::prelude::*;
use daisychain::prelude::Cursor;
let _ = Cursor::from("The quick brown fox jumps over the lazy dog")
.find("quick")
.selection_start()
.word()
.word()
.word()
.selection_end()
.find("over");
```
# Parser
Parsers are "functions" that take text and produce structured data.
Different styles are encouraged.
- an implmentation of the trait FromStr which accepts a &str and produces some parsed data inside a Result
OR
- a function accepting a &str (or Cursor) and produces a Result containing a new cursor position, along with some parsed data
- parsers can be free-functions, associated-functions or closures
A composition pattern is typical, with small parsers handling constituent objects, being invoked by parsers of larger structs in turn
# Testing
For test harnesses and experimentation, Option<&str> is a simple Cursor (without the ability to select text), but is useful for test harnesses.
None is used to represent a matching issue.
For more substantial tests during development of your parsers, using a logging framework for test-harnesses is encoraged
```toml
[dev-dependencies]
env_logger = "0.9"
test-log = {version = "0.2"}
```
This will allow the action of parsing to be traced with
```sh
RUST_LOG=dc=trace cargo test mytest -- --nocapture
```
*/
// fn main() {}