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
//! This crate provides location for `nom` with support to grapheme clusters.
//!
//! # Examples
//! ```
//! use nom::{combinator::map, IResult};
//! use nom_grapheme_clusters::{parse::Tag, Source, Span, SpanContent};
//!
//! #[derive(Debug, Clone, PartialEq, Eq)]
//! struct ParsedAtn {
//!     span: Span,
//! }
//!
//! #[derive(Debug, Clone, PartialEq, Eq)]
//! struct ParsedSmth {
//!     span: Span,
//! }
//!
//! fn parse_smth(input: Span) -> IResult<Span, ParsedSmth> {
//!     map(Tag(&["s", "m", "t", "h"]), |span| ParsedSmth { span })(input)
//! }
//!
//! fn parse_atn(input: Span) -> IResult<Span, ParsedAtn> {
//!     map(Tag(&["a", "t", "n̩̊"]), |span| ParsedAtn { span })(input)
//! }
//!
//! # fn main() {
//! let source = Source::new("file.txt", "atn̩̊smtha");
//!
//! let span0 = source.full_span();
//! let (span1, parsed) = parse_atn(span0).unwrap();
//! assert_eq!(parsed.span.as_str(), "atn̩̊");
//! assert_eq!(parsed.span.start().position(), 0);
//! assert_eq!(parsed.span.start().line(), 0);
//! assert_eq!(parsed.span.start().column(), 0);
//! assert_eq!(parsed.span.len(), 3);
//! assert_eq!(parsed.span.end().position(), 3);
//! assert_eq!(parsed.span.end().line(), 0);
//! assert_eq!(parsed.span.end().column(), 3);
//!
//! let (span2, parsed) = parse_smth(span1).unwrap();
//! assert_eq!(parsed.span.as_str(), "smth");
//! assert_eq!(parsed.span.start().position(), 3);
//! assert_eq!(parsed.span.start().line(), 0);
//! assert_eq!(parsed.span.start().column(), 3);
//! assert_eq!(parsed.span.len(), 4);
//! assert_eq!(parsed.span.end().position(), 7);
//! assert_eq!(parsed.span.end().line(), 0);
//! assert_eq!(parsed.span.end().column(), 7);
//!
//! let result = parse_atn(span2);
//! assert!(result.is_err());
//! println!("{}", result.unwrap_err());
//! # }
//! ```

#![warn(missing_docs)]

pub mod source;
mod location;
pub mod span;
#[cfg(feature = "parse")]
pub mod parse;

pub use location::{LocatedSegment, Location};
pub use source::Source;
pub use span::{Span, SpanContent};