本文整理汇总了Golang中github.com/rwcarlsen/goledger/lex.Lexer类的典型用法代码示例。如果您正苦于以下问题:Golang Lexer类的具体用法?Golang Lexer怎么用?Golang Lexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lexer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: lexItem
func lexItem(l *lex.Lexer) lex.StateFn {
l.Push(lexMeta)
l.Push(lexAmount)
l.Push(lexAt)
l.Push(lexAmount)
l.Push(lexAccount)
return lexStatus
}
示例2: lexAt
func lexAt(l *lex.Lexer) lex.StateFn {
if n := l.AcceptRun(at); n > 2 {
l.Errorf("invalid token on line %v", l.LineNumber())
return lexSkipLine
} else if n == 1 {
l.Emit(tokAt)
} else if n == 2 {
l.Emit(tokAtAt)
}
return nil
}
示例3: lexItems
func lexItems(l *lex.Lexer) lex.StateFn {
if l.AcceptRun(indent) == 0 {
return nil
} else if string(l.Peek()) == meta {
l.Push(lexItems)
return lexMeta
}
l.Ignore()
l.Push(lexItems)
return lexItem
}
示例4: lexCommod
func lexCommod(l *lex.Lexer) lex.StateFn {
l.AcceptRun(indent)
l.Ignore()
if l.AcceptRunNot(whitespace+meta+at) > 0 {
l.Emit(tokCommod)
}
return nil
}
示例5: lexStatus
func lexStatus(l *lex.Lexer) lex.StateFn {
l.AcceptRun(indent)
l.Ignore()
if l.Accept(statuss) {
l.Emit(tokStatus)
}
return nil
}
示例6: lexNewline
func lexNewline(l *lex.Lexer) lex.StateFn {
l.AcceptRun(indent)
if l.AcceptRun(lineend) == 0 {
l.Errorf("lexer error - missing expected newline")
} else {
l.Emit(tokNewline)
}
return nil
}
示例7: lexTrans
func lexTrans(l *lex.Lexer) lex.StateFn {
l.Emit(tokBeginTrans)
l.Push(lexEndTrans)
l.Push(lexItems)
l.Push(lexMeta)
l.Push(lexPayee)
l.Push(lexStatus)
return lexDate
}
示例8: lexStart
// lexStart looks for a comment or a transaction, it emits everything
// inbetween as tokText
func lexStart(l *lex.Lexer) lex.StateFn {
switch r := l.Peek(); {
case string(r) == meta:
l.Push(lexStart)
return lexMeta
case unicode.IsDigit(r):
l.Push(lexStart)
return lexTrans
case isSpace(r) || isNewline(r):
l.Push(lexStart)
return lexBlankLine
case r == lex.EOF:
l.Emit(lex.TokEOF)
return nil
default:
l.Errorf("unexpected text on line %v", l.LineNumber())
l.Push(lexStart)
return lexSkipLine
}
}
示例9: lexText
func lexText(l *lex.Lexer) lex.StateFn {
l.AcceptRunNot(lineend + meta)
l.Emit(tokText)
return lexNewline
}
示例10: lexMeta
func lexMeta(l *lex.Lexer) lex.StateFn {
l.AcceptRun(indent)
l.Ignore()
if l.Accept(";") {
l.Emit(tokMeta)
l.AcceptRun(indent)
l.Ignore()
return lexText
}
return lexNewline
}
示例11: lexSkipLine
func lexSkipLine(l *lex.Lexer) lex.StateFn {
l.AcceptRunNot(lineend)
l.AcceptRun(lineend)
l.Ignore()
return nil
}
示例12: lexPayee
func lexPayee(l *lex.Lexer) lex.StateFn {
if l.AcceptRunNot(lineend+meta) > 0 {
l.Emit(tokPayee)
}
return nil
}
示例13: lexAmount
func lexAmount(l *lex.Lexer) lex.StateFn {
l.AcceptRun(indent)
l.Ignore()
if l.Accept("$") {
l.Emit(tokUnit)
}
l.AcceptRun(digit + ",")
l.Accept(".")
l.AcceptRun(digit)
if l.Pos > l.Start {
l.Emit(tokAmount)
}
return lexCommod
}
示例14: lexAccount
func lexAccount(l *lex.Lexer) lex.StateFn {
for {
nr := l.Next()
nnr := l.Peek()
if isSpace(nr) && isSpace(nnr) || isNewline(nr) {
l.Backup()
l.Emit(tokAccount)
l.AcceptRun(indent)
l.Ignore()
return nil
}
}
}
示例15: lexEndTrans
func lexEndTrans(l *lex.Lexer) lex.StateFn {
l.Emit(tokEndTrans)
return nil
}