package parser

import (
	
	
	
)

type listItemParser struct {
}

var defaultListItemParser = &listItemParser{}

// NewListItemParser returns a new BlockParser that
// parses list items.
func () BlockParser {
	return defaultListItemParser
}

func ( *listItemParser) () []byte {
	return []byte{'-', '+', '*', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
}

func ( *listItemParser) ( ast.Node,  text.Reader,  Context) (ast.Node, State) {
	,  := .(*ast.List)
	if ! { // list item must be a child of a list
		return nil, NoChildren
	}
	 := lastOffset()
	,  := .PeekLine()
	,  := matchesListItem(, false)
	if  == notList {
		return nil, NoChildren
	}
	if [1]- > 3 {
		return nil, NoChildren
	}

	.Set(emptyListItemWithBlankLines, nil)

	 := calcListOffset(, )
	 := ast.NewListItem([3] + )
	if [4] < 0 || util.IsBlank([[4]:[5]]) {
		return , NoChildren
	}

	,  := util.IndentPosition([[4]:], [4], )
	 := [3] + 
	.AdvanceAndSetPadding(, )
	return , HasChildren
}

func ( *listItemParser) ( ast.Node,  text.Reader,  Context) State {
	,  := .PeekLine()
	if util.IsBlank() {
		.Advance(len() - 1)
		return Continue | HasChildren
	}

	 := lastOffset(.Parent())
	 := .ChildCount() == 0
	,  := util.IndentWidth(, .LineOffset())
	if ( ||  < ) &&  < 4 {
		,  := matchesListItem(, true)
		// new list item found
		if  != notList {
			.Set(skipListParserKey, listItemFlagValue)
			return Close
		}
		if ! {
			return Close
		}
	}
	,  := util.IndentPosition(, .LineOffset(), )
	.AdvanceAndSetPadding(, )

	return Continue | HasChildren
}

func ( *listItemParser) ( ast.Node,  text.Reader,  Context) {
	// nothing to do
}

func ( *listItemParser) () bool {
	return true
}

func ( *listItemParser) () bool {
	return false
}