filters: supporting alternative characters for quote

The regexp syntax can have some nasty characters to handle quoting
correctly, in practice. In certain scenarios a double quote works well,
but it can affect readability for certain regexps. This introduces a
quoting mode that treats `/` and `|` as a double quote to make the
quoting in regular expressions more familiar and readable.

This change is introduced in a backwards compatible manner, so existing
regexp quoting is not affected.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-12-04 17:12:41 -08:00
parent 617c63de06
commit 4dfcf60bec
5 changed files with 343 additions and 11 deletions

View File

@@ -87,7 +87,7 @@ func (s *scanner) peek() rune {
return ch
}
func (s *scanner) scan() (int, token, string) {
func (s *scanner) scan() (nextp int, tk token, text string) {
var (
ch = s.next()
pos = s.pos
@@ -101,6 +101,7 @@ chomp:
s.scanQuoted(ch)
return pos, tokenQuoted, s.input[pos:s.ppos]
case isSeparatorRune(ch):
s.value = false
return pos, tokenSeparator, s.input[pos:s.ppos]
case isOperatorRune(ch):
s.scanOperator()
@@ -241,7 +242,7 @@ func isOperatorRune(r rune) bool {
func isQuoteRune(r rune) bool {
switch r {
case '"': // maybe add single quoting?
case '/', '|', '"': // maybe add single quoting?
return true
}