diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-07 01:32:29 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2021-03-07 01:32:29 +0300 |
commit | 3e6a54d506fb5c18ae0aec8cfe01578b40edbc9b (patch) | |
tree | 9bd63c59e7c772bfaac93e40e58b84150fd04fd3 /scanners.go | |
parent | df3a032c5268f002b84a1f9d52bfdc384d58fc98 (diff) |
Added quoted string scannerv0.0.1
Diffstat (limited to 'scanners.go')
-rw-r--r-- | scanners.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/scanners.go b/scanners.go index b5811af..efe803f 100644 --- a/scanners.go +++ b/scanners.go @@ -23,3 +23,24 @@ func ScanAlphaNum(l *Lexer) bool { l.AcceptWhile(alpha + digits) return true } + +// ScanQuotedString returns true if next input tokens is quoted string. Can be used with any type of quotes. +func ScanQuotedString(l *Lexer, quote rune) bool { + start := l.Pos + if l.Next() != quote { + l.Back() + return false + } + for { + ch := l.Next() + switch ch { + case EOF: + l.Pos = start // Return position to start + return false // Unclosed quote string? + case '\\': + l.Next() // Skip next char + case quote: + return true // Closing quote + } + } +} |