| Crates.io | parseal |
| lib.rs | parseal |
| version | 0.2.4 |
| created_at | 2022-10-14 11:25:17.497008+00 |
| updated_at | 2022-10-27 20:35:37.330674+00 |
| description | An easy way to create your own parsers |
| homepage | |
| repository | https://github.com/TheLazyDutchman/parseal/ |
| max_upload_size | |
| id | 688142 |
| size | 91,106 |
parsing and handling of different file formats
This is a library to create parsers in a simple manner.
Say you want to parse a Point, e.g. (10, 14), the easy way to do that is like this:
// some code
#[derive(Parsable, Debug)]
struct Point {
x: Number,
y: Number
}
pub fn some_func(buffer: &mut CharStream) {
let value = Point::parse(buffer);
println!("value: {:#?}", value);
}
Note that the attributes of point are of type Number, instead of something like u32. This is because Number stores additional parsing information for the abstract syntax tree, like the span.
This is a list of the types that you can use from this library, with an explanation of each of them.
The parse function from the Parse trait uses this type, instead of a string.
The CharStream struct has some additional functionality to deal with parsing:
To create a CharStream you can do the following:
let value = "Hello, World!"
let stream = CharStream::new(value).build();
we call build here because the new function returns a CharStreamBuilder
| name | description | args |
|---|---|---|
new |
creates a CharStreamBuilder |
value: the String buffer to create the CharStream from |
set_whitespace |
sets the white space mode | type: the WhitespaceType to set the stream to |
position |
returns the current position | |
indent |
returns the current indent level (indent is only kept track of when WhitespaceType is set to Indent |
This is the struct that stores a position in a CharStream buffer.
This is the struct that stores a beginning and an end Position from a CharStream buffer.
This is the struct that is used to create a CharStream.
Any error that can be returned by parsing.
This is a list of the traits that you can use from this library.
Used for any parsable value.
| name | description | args | return type |
|---|---|---|---|
parse |
try to parse a value of the type that implements the trait | value: &mut CharStream |
Result<Self, ParseError> |
span |
get the Span of the current object |
&self |
Span |