summaryrefslogtreecommitdiffstats
path: root/src/formatter/spec.pest
diff options
context:
space:
mode:
authorZhenhui Xie <xiezh0831@yahoo.co.jp>2020-04-07 01:16:18 +0800
committerGitHub <noreply@github.com>2020-04-06 13:16:18 -0400
commit22dc419a3e0bee5d9a7ea72900b8503e9bd014fc (patch)
treeb3102feac3af53c2e0f4e818583ae6e8bf379cbb /src/formatter/spec.pest
parent3510bfe0444c2bf4e8cf3e42fdf13fde8c05568f (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.pest16
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)* }