本文整理汇总了Golang中github.com/otm/lex.Lexer类的典型用法代码示例。如果您正苦于以下问题:Golang Lexer类的具体用法?Golang Lexer怎么用?Golang Lexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lexer类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LexBegin
// LexBegin is the initial lexer function
func LexBegin(lexer *lex.Lexer) lex.StateFn {
lexer.AcceptWhitespace(lex.Ignore)
if strings.HasPrefix(lexer.InputToEnd(), MinusSign) {
return LexSingleLineComment
}
return LexCode
}
示例2: lexSection
func lexSection(l *lex.Lexer) lex.StateFn {
for {
switch l.Next() {
case lex.EOF:
return l.Errorf("Unexpected EOF in section")
case '\n':
return l.Errorf("Section: Missing right bracket")
case rightBracket:
l.Backup()
l.Emit(tSection)
return lexRightBracket
}
}
}
示例3: lexKey
func lexKey(l *lex.Lexer) lex.StateFn {
for {
switch l.Next() {
case lex.EOF:
return l.Errorf("Unexpected EOF")
case equalSign:
if l.Pos > l.Start {
l.Backup()
l.Emit(tKey)
return lexEqualSign
}
return l.Errorf("Unexpected equal sign")
}
}
}
示例4: LexMultiLineComment
// LexMultiLineComment lexer
func LexMultiLineComment(lexer *lex.Lexer) lex.StateFn {
lexer.Step(2, lex.Ignore)
for {
if strings.HasPrefix(lexer.InputToEnd(), RightBracket) {
lexer.Emit(TComment)
return LexBegin(lexer)
}
lexer.Next()
if lexer.IsEOF() {
panic("EndOfFile")
}
}
}
示例5: lexStart
func lexStart(l *lex.Lexer) lex.StateFn {
l.AcceptWhitespace(lex.Ignore)
r := l.Next()
switch r {
case lex.EOF:
l.Emit(lex.TEOF)
return nil
case leftBracket:
l.Backup()
return lexLeftBracket
default:
if lex.IsAlphaNumeric(r) {
return lexKey
}
return l.Errorf("Unknown charecter: %v", string(r))
}
}
示例6: LexCode
// LexCode parsers random code
func LexCode(lexer *lex.Lexer) lex.StateFn {
for {
if strings.HasPrefix(lexer.InputToEnd(), MinusSign) {
lexer.Start = lexer.Pos
return LexSingleLineComment(lexer)
}
if strings.HasPrefix(lexer.InputToEnd(), string(lex.NewLine)) {
lexer.Next()
lexer.Start = lexer.Pos
return LexCode(lexer)
}
lexer.Next()
if lexer.IsEOF() {
lexer.Emit(lex.TEOF)
lexer.Shutdown()
return nil
}
}
}
示例7: LexSingleLineComment
// LexSingleLineComment lexer
func LexSingleLineComment(lexer *lex.Lexer) lex.StateFn {
lexer.Step(2, lex.Ignore)
if strings.HasPrefix(lexer.InputToEnd(), LeftBracket) {
return LexMultiLineComment(lexer)
}
for {
if strings.HasPrefix(lexer.InputToEnd(), string(lex.NewLine)) {
lexer.Emit(TComment)
return LexBegin(lexer)
}
lexer.Next()
if lexer.IsEOF() {
lexer.Emit(TComment)
lexer.Emit(lex.TEOF)
lexer.Shutdown()
return nil
}
}
}
示例8: lexRightBracket
func lexRightBracket(l *lex.Lexer) lex.StateFn {
l.Accept("]", lex.Emit(tRightBracket))
return lexStart
}
示例9: lexLeftBracket
func lexLeftBracket(l *lex.Lexer) lex.StateFn {
l.Accept("[", lex.Emit(tLeftBracket))
return lexSection
}
示例10: lexValue
func lexValue(l *lex.Lexer) lex.StateFn {
for {
switch l.Next() {
case lex.EOF:
if l.Pos > l.Start {
l.Backup()
l.Emit(tValue)
l.Emit(lex.TEOF)
return nil
}
return l.Errorf("Unexpected equal sign")
case '\n':
l.Backup()
l.Emit(tValue)
l.Next(lex.Ignore)
return lexStart
}
}
}
示例11: lexEqualSign
func lexEqualSign(l *lex.Lexer) lex.StateFn {
l.Accept("=", lex.Emit(tEqualSign))
return lexValue
}