github.com/couchbaselabs/nex@v0.0.0-20230419191105-421cb5932838/test/toy.nex (about) 1 /[0-9]+/ { println("An integer:", txt()) } 2 /[0-9]+\.[0-9]*/ { println("A float:", txt()) } 3 /if|then|begin|end|procedure|function/ 4 { println("A keyword:", txt()) } 5 /[a-z][a-z0-9]*/ { println("An identifier:", txt()) } 6 /\+|-|\*|\// { println("An operator:", txt()) } 7 /[ \t\n]+/ { /* eat up whitespace */ } 8 /./ { println("Unrecognized character:", txt()) } 9 /{[^\{\}\n]*}/ { /* eat up one-line comments */ } 10 // 11 package main 12 import "os" 13 func main() { 14 lex := NewLexer(os.Stdin) 15 txt := func() string { return lex.Text() } 16 NN_FUN(lex) 17 // I changed a regex because the original appears to be wrong: 18 // "{"[\^{}}\n]*"}" /* eat up one-line comments */ 19 // 20 // The original has a few other bugs, e.g. a missing '<' before "math.h", 21 // and a missing noyywrap option prevents compilation. 22 }