-
Notifications
You must be signed in to change notification settings - Fork 184
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
58269de
commit 3d01a91
Showing
10 changed files
with
621 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
[package] | ||
name = "icu_message" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
smallvec = "1.6" | ||
|
||
[dev-dependencies] | ||
iai = "0.1" | ||
criterion = "0.3.4" | ||
|
||
[[bench]] | ||
name = "parser_iai" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "parser" | ||
harness = false |
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,44 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use icu_message::parser::Parser; | ||
|
||
fn overview_bench(c: &mut Criterion) { | ||
let source = "{Hello World}"; | ||
c.bench_function("message/parse", |b| { | ||
b.iter(|| { | ||
let parser = Parser::new(black_box(source)); | ||
let _ = parser.parse(); | ||
}) | ||
}); | ||
|
||
let source = "{Today is {$today}} a good day."; | ||
c.bench_function("message/parse_placeholder", |b| { | ||
b.iter(|| { | ||
let parser = Parser::new(black_box(source)); | ||
let _ = parser.parse(); | ||
}) | ||
}); | ||
} | ||
|
||
fn compare_bench(c: &mut Criterion) { | ||
let mut messages = vec![]; | ||
|
||
for i in 0..99 { | ||
messages.push(format!("{{Value {i}}}")); | ||
} | ||
|
||
c.bench_function("message/compare/simple", |b| { | ||
b.iter(|| { | ||
for msg in &messages { | ||
let parser = Parser::new(black_box(msg.as_str())); | ||
let _ = parser.parse(); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, overview_bench, compare_bench); | ||
criterion_main!(benches); |
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,13 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
use icu_message::parser::Parser; | ||
|
||
fn iai_parse_message() { | ||
let source = "{Hello World}"; | ||
let parser = Parser::new(source); | ||
let _ = parser.parse(); | ||
} | ||
|
||
iai::main!(iai_parse_message,); |
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,98 @@ | ||
use smallvec::SmallVec; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Message<S> { | ||
pub declarations: SmallVec<[Declaration<S>; 1]>, | ||
pub value: MessageValue<S>, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Declaration<S> { | ||
pub variable: S, | ||
pub expression: Expression<S>, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum MessageValue<S> { | ||
Pattern(Pattern<S>), | ||
Select(Box<Select<S>>), | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Select<S> { | ||
pub selector: SmallVec<[Expression<S>; 1]>, | ||
pub variants: SmallVec<[Variant<S>; 3]>, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Variant<S> { | ||
pub key: SmallVec<[VariantKey<S>; 1]>, | ||
pub pattern: Pattern<S>, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Pattern<S> { | ||
pub body: SmallVec<[PatternElement<S>; 3]>, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum PatternElement<S> { | ||
Text(S), | ||
Placeholder(Placeholder<S>), | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum Placeholder<S> { | ||
Markup { | ||
name: S, | ||
options: SmallVec<[Option<S>; 1]>, | ||
}, | ||
MarkupEnd { | ||
name: S, | ||
}, | ||
Expression(Expression<S>), | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum Expression<S> { | ||
Operand { | ||
operand: Operand<S>, | ||
annotation: std::option::Option<Annotation<S>>, | ||
}, | ||
Annotation(Annotation<S>), | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum Operand<S> { | ||
Literal(Literal<S>), | ||
Variable(S), | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Annotation<S> { | ||
function: S, | ||
options: SmallVec<[Option<S>; 1]>, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Literal<S> { | ||
pub value: S, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum VariantKey<S> { | ||
Literal(Literal<S>), | ||
Asterisk, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Option<S> { | ||
name: S, | ||
value: OptionValue<S>, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum OptionValue<S> { | ||
Literal(Literal<S>), | ||
Variable(S), | ||
} |
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,2 @@ | ||
pub mod ast; | ||
pub mod parser; |
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,11 @@ | ||
// macro_rules! get_byte { | ||
// ($s:expr, $idx:expr) => { | ||
// $s.source.as_ref().as_bytes().get($idx) | ||
// }; | ||
// } | ||
|
||
macro_rules! get_current_byte { | ||
($s:expr) => { | ||
$s.source.as_ref().as_bytes().get($s.ptr) | ||
}; | ||
} |
Oops, something went wrong.