chore: reorg
This commit is contained in:
142
__lang/sana/Cargo.lock
generated
Normal file
142
__lang/sana/Cargo.lock
generated
Normal file
@@ -0,0 +1,142 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
|
||||
|
||||
[[package]]
|
||||
name = "sana"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"sana 0.1.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sana"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1bcb53af0f0f5c074896f3671e05d8a2b9d415a3fdbc67b06d9d9fa6851ad3f"
|
||||
dependencies = [
|
||||
"sana_core",
|
||||
"sana_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sana_core"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96cf25ed53fd9e9a8eb50f4aab0abb00732c3fb06dd27b2cbed5d5c58ed1f8e8"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"regex-syntax",
|
||||
"utf8-ranges",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sana_derive"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "368c39149d0fb782c959f82d17d1f1feb96d3cc4fe07ba723b55aad52f77f998"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex-syntax",
|
||||
"sana_core",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "utf8-ranges"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||
11
__lang/sana/Cargo.toml
Normal file
11
__lang/sana/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "sana"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
sana = "0.1.1"
|
||||
|
||||
63
__lang/sana/src/main.rs
Normal file
63
__lang/sana/src/main.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use sana::{ Sana, Spanned };
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Sana)]
|
||||
#[backend(rust)] // optional. can be either rust or vm. default is rust
|
||||
enum Token {
|
||||
#[regex("[a-zA-Z_][a-zA-Z0-9_]*")]
|
||||
Ident,
|
||||
#[regex("[0-9]+")]
|
||||
Integer,
|
||||
|
||||
#[token("let", priority = 1)]
|
||||
Let,
|
||||
#[token("=")]
|
||||
Equals,
|
||||
#[regex(";")]
|
||||
Semicolon,
|
||||
|
||||
#[regex("[ \t\r\n]")]
|
||||
Whitespace,
|
||||
#[error]
|
||||
Error,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut lexer = Token::lexer("let answer = 42;");
|
||||
|
||||
assert_eq!(
|
||||
lexer.next(),
|
||||
Some(Spanned { value: Token::Let, start: 0, end: 3 })
|
||||
);
|
||||
assert_eq!(lexer.next(),
|
||||
Some(Spanned { value: Token::Whitespace, start: 3, end: 4 })
|
||||
);
|
||||
assert_eq!(lexer.next(),
|
||||
Some(Spanned { value: Token::Ident, start: 4, end: 10 })
|
||||
);
|
||||
assert_eq!(lexer.next(),
|
||||
Some(Spanned { value: Token::Whitespace, start: 10, end: 11 })
|
||||
);
|
||||
assert_eq!(
|
||||
lexer.next(),
|
||||
Some(Spanned { value: Token::Equals, start: 11, end: 12 })
|
||||
);
|
||||
assert_eq!(
|
||||
lexer.next(),
|
||||
Some(Spanned { value: Token::Whitespace, start: 12, end: 13 })
|
||||
);
|
||||
assert_eq!(
|
||||
lexer.next(),
|
||||
Some(Spanned { value: Token::Integer, start: 13, end: 15 })
|
||||
);
|
||||
assert_eq!(
|
||||
lexer.next(),
|
||||
Some(Spanned { value: Token::Semicolon, start: 15, end: 16 })
|
||||
);
|
||||
|
||||
// No tokens left
|
||||
assert_eq!(
|
||||
lexer.next(),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user