add in URI and xml

This commit is contained in:
Able 2023-05-03 03:39:34 -05:00
parent ecb1c2a3cc
commit 56c847df6c
6 changed files with 136 additions and 10 deletions

68
Cargo.lock generated
View file

@ -224,7 +224,30 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1" checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1"
dependencies = [ dependencies = [
"logos-derive", "logos-derive 0.12.1",
]
[[package]]
name = "logos"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1"
dependencies = [
"logos-derive 0.13.0",
]
[[package]]
name = "logos-codegen"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68"
dependencies = [
"beef",
"fnv",
"proc-macro2",
"quote",
"regex-syntax",
"syn 2.0.15",
] ]
[[package]] [[package]]
@ -238,7 +261,16 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex-syntax", "regex-syntax",
"syn", "syn 1.0.105",
]
[[package]]
name = "logos-derive"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e"
dependencies = [
"logos-codegen",
] ]
[[package]] [[package]]
@ -282,9 +314,9 @@ version = "0.1.0"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.47" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -311,9 +343,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.21" version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -360,7 +392,7 @@ checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -406,6 +438,17 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "syn"
version = "2.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "system_config" name = "system_config"
version = "0.1.0" version = "0.1.0"
@ -448,7 +491,7 @@ checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.105",
] ]
[[package]] [[package]]
@ -536,6 +579,13 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]]
name = "uri"
version = "0.1.0"
dependencies = [
"logos 0.13.0",
]
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -574,7 +624,7 @@ dependencies = [
name = "wat2wasm" name = "wat2wasm"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"logos", "logos 0.12.1",
] ]
[[package]] [[package]]

View file

@ -29,6 +29,7 @@ members = [
"libraries/tar", "libraries/tar",
"libraries/time", "libraries/time",
"libraries/trash_manifest", "libraries/trash_manifest",
"libraries/uri",
"libraries/versioning", "libraries/versioning",
"programs/ari_client", "programs/ari_client",

9
libraries/uri/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "uri"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
logos = "0.13.0"

48
libraries/uri/src/lib.rs Normal file
View file

@ -0,0 +1,48 @@
use logos::{Lexer, Logos};
#[derive(Logos, Debug, PartialEq)]
#[logos(skip r"[ \t\n\f]+")] // Ignore this regex pattern between tokens
pub enum Token {
// Tokens can be literal strings, of any length.
#[regex("[a-zA-Z0-9]+:/?/?", scheme_parse)]
Scheme(String),
#[regex(r#"[a-zA-Z0-9.]+"#, |lex| lex.slice().parse().ok(), priority = 10)]
Authority(String),
#[regex(":[0-9]+", port)]
Port(u16),
#[regex(r#"[a-zA-Z0-9./\-=_!-+]+"#, |lex| lex.slice().parse().ok(), priority = 1)]
Path(String),
#[regex(r#"\?[a-zA-Z0-9./\-!-+=]+"#, fragment)]
Query(String),
#[regex("#[a-zA-Z0-9./]+", fragment)]
Fragment(String),
}
fn port(lex: &mut Lexer<Token>) -> Option<u16> {
let slice = lex.slice();
// println!("{}", slice);
let n: u16 = slice[1..slice.len()].parse().ok()?;
Some(n)
}
pub fn scheme_parse(lex: &mut Lexer<Token>) -> Option<String> {
let slice: &str = lex.slice();
// println!("{}", slice);
let mut slice: String = slice.to_string();
// slice.pop();
Some(slice)
}
pub fn fragment(lex: &mut Lexer<Token>) -> Option<String> {
let slice: &str = lex.slice();
let mut slice: String = slice.to_string();
slice.remove(0);
Some(slice)
}

12
libraries/uri/src/main.rs Normal file
View file

@ -0,0 +1,12 @@
use logos::Logos;
use uri::Token;
fn main() {
let lex = Token::lexer("http://ablecorp.us:112?hello#ABC");
let lex = Token::lexer("tel:+1-816-555-1212");
let lex = Token::lexer("https://www.amazon.com/Apple-EarPods-3-5mm-Headphone-Plug/dp/B06X16Z7DZ/ref=sr_1_3?crid=1L0TPYCPI8BU5&keywords=wired+ear+buds&qid=1683087424&sprefix=wired+ear+buds%2Caps%2C117&sr=8-3");
for br in lex {
println!("{:?}", br);
}
}

View file

@ -1,6 +1,6 @@
#![no_std] #![no_std]
use core::fmt::{Debug, Display}; use core::fmt::{self, Debug, Display};
#[macro_use] #[macro_use]
extern crate alloc; extern crate alloc;
@ -16,6 +16,12 @@ pub struct Attribute {
name: String, name: String,
value: String, value: String,
} }
impl fmt::Display for Attribute {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}={}", self.name, self.value)?;
Ok(())
}
}
impl Attribute { impl Attribute {
fn to_string(&self) -> String { fn to_string(&self) -> String {