當前位置: 首頁>>代碼示例>>Golang>>正文


Golang lex.Lexer類代碼示例

本文整理匯總了Golang中espra/lex.Lexer的典型用法代碼示例。如果您正苦於以下問題:Golang Lexer類的具體用法?Golang Lexer怎麽用?Golang Lexer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Lexer類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: LexIfExpr

func LexIfExpr(l *lex.Lexer) lex.StateFn {
	if int(l.Pos) >= len(l.Input) {
		l.Emit(lex.ItemEOF)
		return nil
	}
	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:7,代碼來源:ui.go

示例2: Number

func Number(l *lex.Lexer) lex.StateFn {
	if !l.ScanNumber() {
		return l.Errorf("bad number syntax: %q", l.Input[l.Start:l.Pos])
	}
	l.Emit(ItemNumber)
	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:7,代碼來源:ui.go

示例3: Space

func Space(l *lex.Lexer) lex.StateFn {
	for lex.IsSpace(l.Peek()) {
		l.Next()
	}
	l.Emit(ItemSpace)

	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:8,代碼來源:ui.go

示例4: LoopIdentifier

func LoopIdentifier(l *lex.Lexer) lex.StateFn {
	typ := ItemIdentifier
	for {
		r := l.Next()
		if !IsValidIdentifierChar(r) {
			l.Backup()
			break
		}
	}
	l.Emit(typ)
	return LexForExpr
}
開發者ID:tav,項目名稱:oldproto,代碼行數:12,代碼來源:ui.go

示例5: LexTextNode

func LexTextNode(l *lex.Lexer) lex.StateFn {
	for {
		r := l.Next()
		if lex.IsAlphaNumeric(l.Peek()) {
			if lex.IsSpace(r) || lex.IsEndOfLine(r) {
				l.Emit(ItemText)
			}
			i := lex.Pos(strings.IndexAny(l.Input[l.Pos:], " \t\n\r"))
			if i != -1 {
				i = l.Pos + i
			} else {
				i = lex.Pos(len(l.Input) - 1)
			}
			if strings.Contains(l.Input[l.Pos:i], ":") {
				l.Pos = i
				return LexURI
			}
		}
		l.Backup()
		if strings.HasPrefix(l.Input[l.Pos:], leftDelim) {
			if l.Pos > l.Start {
				l.Emit(ItemText)
			}
			return LeftDelim
		}
		if l.Next() == lex.EOF {
			break
		}
	}
	// Correctly reached EOF.
	if l.Pos > l.Start {
		l.Emit(ItemText)
	}
	l.Emit(lex.ItemEOF)
	return nil
}
開發者ID:tav,項目名稱:oldproto,代碼行數:36,代碼來源:ui.go

示例6: LexURI

func LexURI(l *lex.Lexer) lex.StateFn {
	l.Emit(ItemURI)
	return LexTextNode
}
開發者ID:tav,項目名稱:oldproto,代碼行數:4,代碼來源:ui.go

示例7: LexForExpr

func LexForExpr(l *lex.Lexer) lex.StateFn {
	if int(l.Pos) >= len(l.Input) {
		l.Emit(lex.ItemEOF)
		return nil
	}
	if strings.HasPrefix(l.Input[l.Pos:], "in") {
		l.Pos += lex.Pos(2)
		l.Emit(ItemIn)
		return InsideAction
	}

	// any list of space separated identifiers
	switch r := l.Next(); {
	case lex.IsSpace(r):
		for lex.IsSpace(l.Peek()) {
			l.Next()
		}
		l.Emit(ItemSpace)
		return LexForExpr
	case unicode.IsLetter(r):
		return LoopIdentifier
	default:
		return l.Errorf("Unexpected Character '%s'", string(r))
	}
}
開發者ID:tav,項目名稱:oldproto,代碼行數:25,代碼來源:ui.go

示例8: LeftDelim

// LeftDelim scans the left delimiter, which is known to be present.
func LeftDelim(l *lex.Lexer) lex.StateFn {
	l.Pos += lex.Pos(len(leftDelim))
	l.Emit(ItemLeftDelim)
	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:6,代碼來源:ui.go

示例9: RightDelim

// RightDelim scans the right delimiter, which is known to be present.
func RightDelim(l *lex.Lexer) lex.StateFn {
	l.Pos += lex.Pos(len(rightDelim))
	l.Emit(ItemRightDelim)
	return LexTextNode
}
開發者ID:tav,項目名稱:oldproto,代碼行數:6,代碼來源:ui.go

示例10: InsideAction

func InsideAction(l *lex.Lexer) lex.StateFn {

	if l.Name == "LexTextNode" && strings.HasPrefix(l.Input[l.Pos:], rightDelim) {
		if l.IntState[ActionParenDepth] > 0 {
			return l.Errorf("unmatched parentheses")
		}
		return RightDelim
	}

	switch r := l.Next(); {
	case (r == lex.EOF || lex.IsEndOfLine(r)):
		if l.Name == "LexIfExpr" {
			return LexIfExpr
		}
		if l.Name == "LexForExpr" {
			return LexForExpr
		}
		// if reach eof throw while still in action throw error
		return l.Errorf("unclosed action")
	case lex.IsSpace(r):
		return Space
	case unicode.IsLetter(r): //variable and function must begin with a letter
		return Identifier
	case r == '!':
		if unicode.IsLetter(l.Peek()) {
			return Identifier
		}
		return l.Errorf("invalid character in builtin")
	case r == '#' || r == '+':
		if unicode.IsLetter(l.Peek()) {
			return EspraURI
		}
		return l.Errorf("invalid character in URI")
	case r == '-' || unicode.IsDigit(r):
		l.Backup()
		return Number
	case r == '\'' || r == '"':
		l.Emit(ItemOpenQuote)
		return String
	case r == '(':
		l.IntState[ActionParenDepth] += 1
		l.Emit(ItemLeftParen)
	case r == ')':
		l.IntState[ActionParenDepth] -= 1
		l.Emit(ItemRightParen)
	case r == '|':
		l.Emit(ItemPipe)
	default:
		return l.Errorf("Unexpected Character '%s'", string(r))
	}
	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:52,代碼來源:ui.go

示例11: String

// Quote scans a quoted string.
func String(l *lex.Lexer) lex.StateFn {
Loop:
	for {
		switch l.Next() {
		case '\\':
			// ???
			if r := l.Next(); r != lex.EOF && r != '\n' {
				break
			}
			fallthrough
		case lex.EOF, '\n':
			return l.Errorf("unterminated quoted string")
		case '"', '\'':
			l.Backup()
			break Loop
		}
	}
	l.Emit(ItemString)
	l.Next()
	l.Emit(ItemCloseQuote)
	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:23,代碼來源:ui.go

示例12: Identifier

func Identifier(l *lex.Lexer) lex.StateFn {
	typ := ItemIdentifier
	r, _ := utf8.DecodeRuneInString(l.Input[l.Start:])
	if r == '!' {
		l.Ignore()
		typ = ItemBuiltin
	}
	for {
		// should not appear in the first identifier of an expression of sub-expression (since it must be a function)
		r = l.Next()

		if r == ':' {
			typ = ItemArgKey
			l.Backup()
			l.Emit(typ)
			l.Next()
			l.Ignore()
			return InsideAction
		}
		if !IsValidIdentifierChar(r) {
			l.Backup()
			break
		}
	}
	l.Emit(typ)
	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:27,代碼來源:ui.go

示例13: EspraURI

func EspraURI(l *lex.Lexer) lex.StateFn {
	l.Emit(ItemEspraURI)
	return InsideAction
}
開發者ID:tav,項目名稱:oldproto,代碼行數:4,代碼來源:ui.go


注:本文中的espra/lex.Lexer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。