Documentation ¶
Overview ¶
Package scanner implements a scanner for N-Quads[0] source text. It takes a []byte as source which can then be tokenized through repeated calls to the Scan method.
Index ¶
Examples ¶
Constants ¶
View Source
const ( ILLEGAL // Returned when no token was recognized. EOF // Returned after all source was consumed. DOT // . DACCENT // ^^ LABEL // [1] EOL // [2] IRIREF // [3] LANGTAG // [4] STRING // [5] )
Values of type Token.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scanner ¶
type Scanner struct { Col int // Starting column of the last scanned token. Errors []error // List of accumulated errors. Fname string // File name (reported) of the scanned source. Line int // Starting line of the last scanned token. NCol int // Starting column (reported) for the next scanned token. NLine int // Starting line (reported) for the next scanned token. // contains filtered or unexported fields }
A Scanner holds the scanner's internal state while processing a given text.
func (*Scanner) Scan ¶
Scan scans the next token and returns the token and its value if applicable. The source end is indicated by EOF.
If the returned token is ILLEGAL, the literal string is the offending character or number/string/char literal.
Example ¶
const src = ` <http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> @us-EN <http://example.org/graph3> . # comments here # or on a line by themselves _:subject1 <http://an.example/predicate1> "object\u00411" "cafe\u0301 \'time" <http://example.org/graph1> . _:subject2 <http://an.example/predicate2> "object\U000000422" ^^ <http://example.com/literal> <http://example.org/graph5> . _:0 _:01 _:0 _:01 ` sc := New("test", []byte(src)) for { tok, val := sc.Scan() fmt.Printf("%s:%d:%d %v %q\n", sc.Fname, sc.Line, sc.Col, tok, val) if tok == EOF { break } } fmt.Printf("%v", sc.Errors)
Output: test:2:0 EOL "" test:3:1 IRIREF "http://one.example/subject1" test:3:31 IRIREF "http://one.example/predicate1" test:3:63 IRIREF "http://one.example/object1" test:3:92 LANGTAG "us-EN" test:3:99 IRIREF "http://example.org/graph3" test:3:127 DOT "." test:4:0 EOL "" test:5:0 EOL "" test:5:1 LABEL "subject1" test:5:12 IRIREF "http://an.example/predicate1" test:5:43 STRING "objectA1" test:5:59 STRING "café 'time" test:5:79 IRIREF "http://example.org/graph1" test:5:107 DOT "." test:6:0 EOL "" test:6:1 LABEL "subject2" test:6:12 IRIREF "http://an.example/predicate2" test:6:43 STRING "objectB2" test:6:64 DACCENT "^^" test:6:67 IRIREF "http://example.com/literal" test:6:96 IRIREF "http://example.org/graph5" test:6:124 DOT "." test:7:0 EOL "" test:7:1 LABEL "0" test:7:5 LABEL "01" test:8:0 EOL "" test:8:2 LABEL "0" test:8:6 LABEL "01" test:9:0 EOL "" test:10:1 EOF "" []
Click to show internal directories.
Click to hide internal directories.