Documentation ¶
Index ¶
- Constants
- Variables
- func NewArgumentCharStream(args []string, options ...ArgumentOption) common.CharStream
- func NewChainingCharStream(streams []common.CharStream) common.CharStream
- func NewListCharStream(chars []common.Char, err error) common.CharStream
- func NewMemoizingCharStream(src common.CharStream) common.CharStream
- func NewScanner(r io.Reader, loc common.Location, options ...ScannerOption) common.CharStream
- type ArgumentOption
- type LineDis
- type LineStyle
- type MockLineStyle
- type ScannerOption
Constants ¶
const DefaultTabStop = 8
DefaultTabStop is the default tab stop for the scanner.
Variables ¶
var DOSLineStyle = &dosLineStyle{}
DOSLineStyle is a style for handling the use of carriage return and newline line endings, also known as DOS line endings.
var (
ErrBadEncoding = kent.NewWarning("Invalid UTF-8 encoding")
)
Simple errors that may be generated within the package.
var MacLineStyle = &macLineStyle{}
MacLineStyle is a style for handling the use of bare carriage return line endings, also known as Mac classic line endings.
var NoLineStyle = &noLineStyle{}
NoLineStyle is a style for handling the case when no newlines in the source should be recognized. All carriage returns and newlines will be substituted with spaces.
var UNIXLineStyle = &unixLineStyle{}
UNIXLineStyle is a style for handling the use of bare newline line endings, also known as UNIX line endings.
var UnknownLineStyle = &unknownLineStyle{}
UnknownLineStyle is a style for handling files where the line ending style is not yet known. It guesses the line ending style from the first line ending encountered, then switches to the appropriate line ending style.
Functions ¶
func NewArgumentCharStream ¶
func NewArgumentCharStream(args []string, options ...ArgumentOption) common.CharStream
NewArgumentCharStream constructs and returns a common.Charstream implementation that returns characters drawn from a provided list of argument strings. This is intended for use with arguments taken from the command line, but could be useful in other contexts as well. The strings are logically joined by spaces; to use a different joiner, pass that as an option.
func NewChainingCharStream ¶
func NewChainingCharStream(streams []common.CharStream) common.CharStream
NewChainingCharStream constructs and returns a common.CharStream implementation that returns characters from each of the provided character streams in turn. When one character stream returns EOF, that EOF is skipped and the chaining character stream begins drawing characters from the next one. If any character stream returns an error, that error is returned immediately.
func NewListCharStream ¶
func NewListCharStream(chars []common.Char, err error) common.CharStream
NewListCharStream constructs and returns a common.CharStream implementation that returns characters from a list of characters. The last character should be a common.EOF; this character will be returned with the error passed in. This character stream is intended for testing, in cases where a MockCharStream is not a good fit.
func NewMemoizingCharStream ¶
func NewMemoizingCharStream(src common.CharStream) common.CharStream
NewMemoizingCharStream constructs and returns a common.CharStream implementation that wraps another and simply returns all the characters it returns. After the EOF character is returned--which is passed through unchanged--the character stream is replayed over and over. If the source character stream returns an error, that error is reported immediately.
func NewScanner ¶
func NewScanner(r io.Reader, loc common.Location, options ...ScannerOption) common.CharStream
NewScanner constructs a new instance of the Scanner. It returns a common.CharStream object.
Types ¶
type ArgumentOption ¶
type ArgumentOption func(*argOptions)
ArgumentOption is an option that may be passed to the NewArgumentCharStream function.
func ArgumentJoiner ¶
func ArgumentJoiner(joiner string) ArgumentOption
ArgumentJoiner specifies an alternate argument joiner; this character sequence appears between each argument. The default is a single space; pass this as an option to specify a different joiner.
func ArgumentReporter ¶
func ArgumentReporter(rep kent.Reporter) ArgumentOption
ArgumentReporter specifies a kent.Reporter to use for reporting encoding errors. By default, encoding errors are not reported.
type LineStyle ¶
type LineStyle interface { // Handle checks to see if a line ending sequence has been // encountered. It returns a LineDis value, which indicates // the disposition of the character; and a LineStyle object to // use next time around. Handle(chs []rune) (LineDis, LineStyle) }
LineStyle represents a line ending style. This controls how lines are handled when read from the source input stream, and is used for maintaining the location that is then attached to runes.
type MockLineStyle ¶
MockLineStyle is a mock implementation of the LineStyle interface.
type ScannerOption ¶
type ScannerOption func(s *scanner)
ScannerOption is a scanner option that may be passed to the NewScanner function.
func LineEndings ¶
func LineEndings(ls LineStyle) ScannerOption
LineEndings is a scanner option that may be used to set the preferred line ending style. A line ending style is an instance of LineStyle that controls how the scanner recognizes newlines. The scanner always converts line endings into single newlines.
func Reporter ¶
func Reporter(rep kent.Reporter) ScannerOption
Reporter is a scanner option that may be used to specify a kent.Reporter to use for reporting encoding errors. By default, encoding errors are not reported.
func TabStop ¶
func TabStop(ts int) ScannerOption
TabStop is a scanner option that may be used to specify a different tab stop setting than the default of 8.