package main /* #include #include #include "urlscanner.h" */ import "C" import ( "html/template" "log" "strings" ) type Link struct { Url template.URL Text template.HTML IsDir bool } func getToken(input string) []Link { var token C.int var ls []Link var l Link C.scan_string(C.CString(input)) for token = C.yylex(); token != C.MYEOF; token = C.yylex() { if token == C.TOKEN_URL { // flex reads the href attr l.Url = template.URL(C.GoString(C.yylval)) if strings.HasSuffix(C.GoString(C.yylval), "/") { l.IsDir = true } } else if token == C.TOKEN_TEXT { // flex reads the link description l.Text = template.HTML(C.GoString(C.yylval)) ls = append(ls, l) l = Link{} } else { // lexical error l = Link{} log.Printf("Lexical Error on line %d \n", C.yylineno) continue } } return ls } // sort