You can see the original example here
main()
{
reader := OpenFile("/etc/nginx/mime.types")
line := 1
//Read the file from OS ensuring at least one line is ready
reader.BufferLine()
//Expects will set HasError to true if the expected word didn't match
reader.WS().Expect("types")
reader.WS().Expect("{").ExpectEOL()
while reader.BufferLine()
{
line++
if (reader.WS().AtEOL())
continue
//Eat will consume characters until it finds one of these tokens or a newline
//mime is a string slice, not a copy
mime, tok := reader.Eat("\t }")
if tok == '}'
break
while tok != ';' && reader.Ok {
ext, tok2 = reader.WS().Eat("\t ;")
tok .= tok2 //later we may allow ext, tok mut = ...
if ext.size == 0
continue
//Both mime and ext are availiable since no invalidating functions were called.
//Bufferline, WSNL and IsEOF may overwrite previous data
print("mime: $mime ext: $ext\n", 0)
}
}
reader.WS().ExpectEOF()
//Instead of checking for errors everywhere
//we can handle it at one location
if reader.HasError {
print("We did not process the file correctly")
return
}
print("Done")
}