Adding the challenge 0301
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package db0301
|
||||
|
||||
type Parser struct {
|
||||
buf string
|
||||
pos int
|
||||
}
|
||||
|
||||
func NewParser(s string) Parser {
|
||||
return Parser{buf: s, pos: 0}
|
||||
}
|
||||
|
||||
func isSpace(ch byte) bool {
|
||||
switch ch {
|
||||
case '\t', '\n', '\v', '\f', '\r', ' ':
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
func isAlpha(ch byte) bool {
|
||||
return 'a' <= (ch|32) && (ch|32) <= 'z'
|
||||
}
|
||||
func isDigit(ch byte) bool {
|
||||
return '0' <= ch && ch <= '9'
|
||||
}
|
||||
func isNameStart(ch byte) bool {
|
||||
return isAlpha(ch) || ch == '_'
|
||||
}
|
||||
func isNameContinue(ch byte) bool {
|
||||
return isAlpha(ch) || isDigit(ch) || ch == '_'
|
||||
}
|
||||
func isSeparator(ch byte) bool {
|
||||
return ch < 128 && !isNameContinue(ch)
|
||||
}
|
||||
|
||||
func (p *Parser) skipSpaces() {
|
||||
for p.pos < len(p.buf) && isSpace(p.buf[p.pos]) {
|
||||
p.pos += 1
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) tryKeyword(kw string) bool
|
||||
|
||||
func (p *Parser) tryName() (string, bool)
|
||||
|
||||
func (p *Parser) isEnd() bool {
|
||||
p.skipSpaces()
|
||||
return p.pos >= len(p.buf)
|
||||
}
|
||||
|
||||
// QzBQWVJJOUhU https://trialofcode.org/
|
||||
Reference in New Issue
Block a user