Documentation ¶
Index ¶
- Variables
- func Parse(reader io.Reader) (*al.AcrossLite, error)
- type Handler
- type ParsingState
- func HandleDone(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleInit(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleLookingForAuthor(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleLookingForCopyright(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleLookingForGrid(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleLookingForSize(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleLookingForTitle(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingAcross(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingAuthor(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingCopyright(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingDown(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingGrid(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingNotepad(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingSize(pal *al.AcrossLite, line string) (ParsingState, error)
- func HandleReadingTitle(pal *al.AcrossLite, line string) (ParsingState, error)
Constants ¶
This section is empty.
Variables ¶
var StateMap = map[ParsingState]Handler{ INIT: HandleInit, LOOKING_FOR_TITLE: HandleLookingForTitle, READING_TITLE: HandleReadingTitle, LOOKING_FOR_AUTHOR: HandleLookingForAuthor, READING_AUTHOR: HandleReadingAuthor, LOOKING_FOR_COPYRIGHT: HandleLookingForCopyright, READING_COPYRIGHT: HandleReadingCopyright, LOOKING_FOR_SIZE: HandleLookingForSize, READING_SIZE: HandleReadingSize, LOOKING_FOR_GRID: HandleLookingForGrid, READING_GRID: HandleReadingGrid, READING_ACROSS: HandleReadingAcross, READING_DOWN: HandleReadingDown, READING_NOTEPAD: HandleReadingNotepad, DONE: HandleDone, }
Define the map of parsing states to handler functions
Functions ¶
Types ¶
type Handler ¶
type Handler func(*al.AcrossLite, string) (ParsingState, error)
Signature of a function that handles a string in a particular state
type ParsingState ¶
type ParsingState byte
The parsing states of the finite state machine. These are used in determining the next state after each line is handled. There is a map of parsing states to handler functions in AcrossLiteImporter.
const ( UNKNOWN ParsingState = iota INIT LOOKING_FOR_TITLE READING_TITLE LOOKING_FOR_AUTHOR READING_AUTHOR LOOKING_FOR_COPYRIGHT READING_COPYRIGHT LOOKING_FOR_SIZE READING_SIZE LOOKING_FOR_GRID READING_GRID READING_ACROSS READING_DOWN READING_NOTEPAD DONE )
func HandleDone ¶
func HandleDone(pal *al.AcrossLite, line string) (ParsingState, error)
HandleDone is a no-op that continues in the DONE state.
func HandleInit ¶
func HandleInit(pal *al.AcrossLite, line string) (ParsingState, error)
HandleInit looks for the valid beginning of an AcrossLite text file, which is <ACROSS PUZZLE>.
func HandleLookingForAuthor ¶
func HandleLookingForAuthor(pal *al.AcrossLite, line string) (ParsingState, error)
HandleLookingForAuthor looks at the next line in the file and ensures that it is <AUTHOR>.
func HandleLookingForCopyright ¶
func HandleLookingForCopyright(pal *al.AcrossLite, line string) (ParsingState, error)
HandleLookingForCopyright verifies that the current line in the data is <COPYRIGHT>.
func HandleLookingForGrid ¶
func HandleLookingForGrid(pal *al.AcrossLite, line string) (ParsingState, error)
HandleLookingForGrid verifies that the current line in the data is <GRID>.
func HandleLookingForSize ¶
func HandleLookingForSize(pal *al.AcrossLite, line string) (ParsingState, error)
HandleLookingForSize verifies that the current line in the data is <SIZE>.
func HandleLookingForTitle ¶
func HandleLookingForTitle(pal *al.AcrossLite, line string) (ParsingState, error)
HandleLookingForTitle verifies that the current line in the data is <TITLE>.
func HandleReadingAcross ¶
func HandleReadingAcross(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingAcross parses the across clues in the data, line by line, and and appends them to the list of across clues in the AcrossLite structure.
Note that this function does not yet know the word numbering scheme, so we just assign consecutive word number. This will be patched up when the parsing is complete.
func HandleReadingAuthor ¶
func HandleReadingAuthor(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingAuthor copies the line into the Author element of the AcrossLite structure.
func HandleReadingCopyright ¶
func HandleReadingCopyright(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingCopyright copies the current line in the data to the AcrossLite structure.
func HandleReadingDown ¶
func HandleReadingDown(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingDown parses the down clues in the data, line by line. This is a valid final state, because <NOTEPAD> is an optional element.
Note that this function does not yet know the word numbering scheme, so we just assign consecutive word number. This will be patched up when the parsing is complete.
func HandleReadingGrid ¶
func HandleReadingGrid(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingGrid stores grid lines in the AcrossLite structure. It verifies that each line is of the right length, and that the final number of lines agrees with the declared size.
func HandleReadingNotepad ¶
func HandleReadingNotepad(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingNotepad takes each line and appends it to the AcrossLite structure notepad list. Note that this is an optional section, and it doesn't require any validation.
func HandleReadingSize ¶
func HandleReadingSize(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingSize examines the current line, and verifies that it has the form <digits>x<digits>. Note that the only grids I handle are square ones.
func HandleReadingTitle ¶
func HandleReadingTitle(pal *al.AcrossLite, line string) (ParsingState, error)
HandleReadingTitel copies the line into the Title element of the AcrossLite structure.