diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-11-06 21:31:46 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-11-10 00:40:16 +0900 |
commit | f89d021bbe134e3efa0d015a41e9712960cdd009 (patch) | |
tree | 28c6d49611f09dad186b0f6fc4c1a42864a2f7cb /spec/grammar/util.go | |
parent | Split SymbolTable's APIs into reader/writer (diff) | |
download | cotia-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.go | 21 |
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) +} |