aboutsummaryrefslogtreecommitdiff
path: root/spec/grammar/util.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-11-06 21:31:46 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-11-10 00:40:16 +0900
commitf89d021bbe134e3efa0d015a41e9712960cdd009 (patch)
tree28c6d49611f09dad186b0f6fc4c1a42864a2f7cb /spec/grammar/util.go
parentSplit SymbolTable's APIs into reader/writer (diff)
downloadcotia-f89d021bbe134e3efa0d015a41e9712960cdd009.tar.gz
cotia-f89d021bbe134e3efa0d015a41e9712960cdd009.tar.xz
Import source code of lexer generator
From: https://github.com/nihei9/maleeni
Diffstat (limited to 'spec/grammar/util.go')
-rw-r--r--spec/grammar/util.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/grammar/util.go b/spec/grammar/util.go
new file mode 100644
index 0000000..bf3f233
--- /dev/null
+++ b/spec/grammar/util.go
@@ -0,0 +1,21 @@
+package grammar
+
+import "strings"
+
+var rep = strings.NewReplacer(
+ `.`, `\.`,
+ `*`, `\*`,
+ `+`, `\+`,
+ `?`, `\?`,
+ `|`, `\|`,
+ `(`, `\(`,
+ `)`, `\)`,
+ `[`, `\[`,
+ `\`, `\\`,
+)
+
+// EscapePattern escapes the special characters.
+// For example, EscapePattern(`+`) returns `\+`.
+func EscapePattern(s string) string {
+ return rep.Replace(s)
+}