Skip to content

Commit

Permalink
Inline code for the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
mara-schulke committed Sep 9, 2023
1 parent d49d347 commit cfce1d9
Show file tree
Hide file tree
Showing 12 changed files with 1,729 additions and 5 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,3 @@ numeric and length 8
This Syntax might not cover all use cases. It's not meant to do that. If you
find yourself reaching the limits of this language you might want to use more
advanced tools (such as awk, grep, sed..)

---

The code for the language itself lives in a seperate
[repository](https://github.com/schulke-214/te).
10 changes: 10 additions & 0 deletions te/.gitignore
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
20 changes: 20 additions & 0 deletions te/Cargo.toml
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"
64 changes: 64 additions & 0 deletions te/README.md
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 added te/SPECIFICATION.md
Empty file.
22 changes: 22 additions & 0 deletions te/src/error.rs
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)
}
}
Loading

0 comments on commit cfce1d9

Please sign in to comment.