-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d49d347
commit cfce1d9
Showing
12 changed files
with
1,729 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "te" | ||
version = "0.1.0" | ||
description = "A really simple, stripped down & readable regular expression alternative for matching text" | ||
authors = ["Mara Schulke <[email protected]>"] | ||
edition = "2018" | ||
homepage = "https://github.com/mara-schulke/te" | ||
repository = "https://github.com/mara-schulke/te.git" | ||
license = "MIT" | ||
readme = "README.md" | ||
keywords = ["text-processing", "language", "dsl"] | ||
|
||
[features] | ||
lazy = ["lazy_static"] | ||
|
||
[dependencies] | ||
lazy_static = { version = "1.4.0", optional = true } | ||
|
||
[dev-dependencies] | ||
pretty_assertions = "0.6.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# The Text Expression Language | ||
|
||
This is a crate contains a parser, execution engine and specification for a super simple language to write readable and memorizable text processing expressions. | ||
|
||
This document should be used as specification for language to clarify the development of this package. | ||
|
||
## Data Types | ||
|
||
This Language holds only two data types; strings and integers. Both are used as literals in arguments of attribute statements. | ||
|
||
### str | ||
|
||
A `str` must use double quotes. So `"foo"` and `"!=$)(j0j0802"` are both valid strings. If a double quote occurs inside the string, it can be | ||
escaped using `\`. So strings with escaped double quotes look like this: `"\"Quoted Text\""`. This is actually all there is to strings. They cant contain | ||
any other escaped chars (such as new lines etc.) | ||
|
||
### int | ||
|
||
An `ìnt` is either a single `0` or `1-9` followed by `0-9` as often as wanted. There are no signed integers. | ||
|
||
## Queries | ||
|
||
Queries indicate the format of a string which gets tested against it. Currently there are 9 Attributes which are specified: | ||
|
||
| Attribute | Resolve to true if the tested string | | ||
|------------------|------------------------------------------------| | ||
| `starts <str>` | starts with the given string | | ||
| `ends <str>` | ends with the given string | | ||
| `contains <str>` | contains a substring equal to the given string | | ||
| `equals <str>` | exactly equals the given string | | ||
| `length <int>` | has the given length | | ||
| `numeric` | contains only numeric chars | | ||
| `alpha` | contains only alphabetic chars | | ||
| `alphanumeric` | contains only alphanumeric chars | | ||
| `special` | contains only special chars | | ||
|
||
## Logical Operators | ||
|
||
Currently there are only two binary logical operations: `and` and `or` | ||
|
||
| Operator | Precedence | Associativity | | ||
|----------|------------|---------------| | ||
| `and` | 2 | Right | | ||
| `or` | 1 | Right | | ||
|
||
### Examples | ||
|
||
`1 or 2` parses as `(1 or 2)` | ||
|
||
`1 and 2` parses as `(1 and 2)` | ||
|
||
`1 and 2 or 3` parses as `((1 and 2) or 3)` | ||
|
||
`1 or 2 and 3` parses as `(1 or (2 and 3))` | ||
|
||
`1 and 2 and 3` parses as `(1 and (2 and 3))` | ||
|
||
`1 or 2 or 3` parses as `(1 or (2 or 3))` | ||
|
||
`1 or 2 or 3 and 4 or 5` parses as `(1 or (2 or ((3 and 4) or 5)))))` | ||
|
||
## Groups | ||
|
||
> Currently not implemented. May come in future versions to enable more complex text processing; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::{lexer, parser}; | ||
|
||
|
||
pub type TextExpressionResult<T> = std::result::Result<T, Error>; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Error { | ||
LexicalError(lexer::Error), | ||
ParserError(parser::Error) | ||
} | ||
|
||
impl From<lexer::Error> for Error { | ||
fn from(err: lexer::Error) -> Self { | ||
Error::LexicalError(err) | ||
} | ||
} | ||
|
||
impl From<parser::Error> for Error { | ||
fn from(err: parser::Error) -> Self { | ||
Error::ParserError(err) | ||
} | ||
} |
Oops, something went wrong.