+package main
+
+import (
+ "fmt"
+ "strings"
+ "unicode/utf8"
+ "unicode"
+)
+
type item struct {
typ itemType;
val string
itemDot
itemEOF
itemNumber
-}
+ itemText
+ itemLeftMeta
+ itemRightMeta
+)
-func (i item) String() {
+func (i item) String() string {
switch i.typ {
case itemEOF:
return "EOF"
type stateFn func(*lexer) stateFn;
func (l *lexer) run() {
- for state := lexText; state != nil; }
- state = state(lexer)
+ for state := lexText; state != nil; {
+ state = state(l)
}
close(l.items)
}
const leftMeta = "{{"
const rightMeta = "}}"
+const eof = utf8.RuneError
func lexText (l *lexer) stateFn {
for {
return lexInsideAction
}
+func lexRightMeta(l *lexer) stateFn {
+ l.pos += len(rightMeta)
+ l.emit(itemRightMeta)
+ return lexText
+}
+
+func isSpace(r rune) bool {
+ return r < unicode.MaxASCII && unicode.IsSpace(r)
+}
+
+func isAlphaNumeric(r rune) bool {
+ return r < unicode.MaxASCII && unicode.IsLetter(r) || unicode.IsNumber(r)
+}
+
func lexInsideAction(l *lexer) stateFn {
for {
if strings.HasPrefix(l.input[l.pos:], rightMeta) {
return l.errorf("unclosed action")
case isSpace(r):
l.ignore()
- case r == '|':
- l.emit(itemPipe)
- case r == '"':
- return lexQuote
case r == '+' || r == '-' || '0' <= r && r <= '9':
l.backup()
return lexNumber
+ /*
case isAlphaNumeric(r):
l.backup()
return lexIdentifier
+ */
}
}
}
-func (l *lexer) next() (rune int) {
+func (l *lexer) next() (r rune) {
if l.pos >= len(l.input) {
l.width = 0
return eof
}
- run, l.width = utf8.DecodeRuneInString(l.input[l.poas:])
+ r, l.width = utf8.DecodeRuneInString(l.input[l.pos:])
l.pos += l.width
- return rune
+ return r
}
func (l *lexer) ignore() {
l.pos -= l.width
}
-func (l *lexer) peek() int {
- rune := l.next()
+func (l *lexer) peek() rune {
+ r := l.next()
l.backup()
- return rune
+ return r
}
func (l *lexer) accept(valid string) bool {
}
func (l *lexer) errorf(format string, args ...interface{}) stateFn {
- stateFn {
- l.items <- item{
- itemError,
- fmt.Sprintf(format, args...),
- }
- return nil
+ l.items <- item {
+ itemError,
+ fmt.Sprintf(format, args...),
+ }
+ return nil
}
+
+func main() {
+ fmt.Println("Huita")
+}
+