diff options
author | Zhenhui Xie <xiezh0831@yahoo.co.jp> | 2020-04-07 01:16:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-06 13:16:18 -0400 |
commit | 22dc419a3e0bee5d9a7ea72900b8503e9bd014fc (patch) | |
tree | b3102feac3af53c2e0f4e818583ae6e8bf379cbb /src/formatter/spec.pest | |
parent | 3510bfe0444c2bf4e8cf3e42fdf13fde8c05568f (diff) |
improvement: add parser for format strings (#1021)
This PR implements the parser of format strings described in #624.
Diffstat (limited to 'src/formatter/spec.pest')
-rw-r--r-- | src/formatter/spec.pest | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/formatter/spec.pest b/src/formatter/spec.pest new file mode 100644 index 000000000..36be53be5 --- /dev/null +++ b/src/formatter/spec.pest @@ -0,0 +1,16 @@ +expression = _{ SOI ~ value* ~ EOI } +value = _{ text | variable | textgroup } + +variable = { "$" ~ variable_name } +variable_name = @{ char+ } +char = _{ 'a'..'z' | 'A'..'Z' | '0'..'9' | "_" } + +text = { text_inner+ } +text_inner = _{ text_inner_char | escape } +text_inner_char = { !("[" | "]" | "(" | ")" | "$" | "\\") ~ ANY } +escape = _{ "\\" ~ escaped_char } +escaped_char = { "[" | "]" | "(" | ")" | "\\" | "$" } + +textgroup = { "[" ~ format ~ "]" ~ "(" ~ style ~ ")" } +format = { (variable | text | textgroup)* } +style = { (variable | text)* } |