Пример #1
0
	dict_elements = sickle.Many(dict_element)
	list_elements = sickle.Many(list_element)

	dict_element = sickle.Seq(b_string, any_type)
	list_element = any_type

	b_uint = flatten(sickle.Choice(zero, whole_num))
	b_sint = flatten(sickle.Choice(zero, whole_num, neg_num))

	zero      = sickle.Ch('0')
	whole_num = sickle.Seq(pos_digit, sickle.Many(digit))
	neg_num   = sickle.Seq(neg, whole_num)

	neg       = sickle.Ch('-')
	pos_digit = sickle.ChRange('1', '9')
	digit     = sickle.ChRange('0', '9')

	int_start  = sickle.Ch('i')
	list_start = sickle.Ch('l')
	dict_start = sickle.Ch('d')
	end        = sickle.Ch('e')
	colon      = sickle.Ch(':')
)

func flatten(r sickle.Rule) sickle.Rule {
	return sickle.Action(r, func(n sickle.Node) sickle.Node {
		var ret []sickle.Node
		flatten_(&ret, n)

		n.Value = ret
Пример #2
0
	expr        = sickle.Indirect()
	expr_actual = sickle.Choice(
		sickle.Seq(sickle.Ch('('), expr, sickle.Ch(')')),
		additive_term,
	)

	additive_term = sickle.Choice(
		sickle.Seq(multiplicative_term, sickle.Ch('+'), multiplicative_term),
		sickle.Seq(multiplicative_term, sickle.Ch('-'), multiplicative_term),
		multiplicative_term,
	)

	multiplicative_term = sickle.Choice(
		sickle.Seq(digit, sickle.Ch('*'), digit),
		sickle.Seq(digit, sickle.Ch('/'), digit),
		digit,
	)

	digit = sickle.ChRange('0', '9')
)

func main() {
	input, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		log.Fatal(err)
	}

	res := sickle.Parse(input, Rule)
	spew.Dump(res)
}
Пример #3
0
package xpath

import (
	"sickle"
)

func init() {
	comment.Bind(comment_actual)
}

// lexical fragments: these are not terminals themselves but are used to build
// terminals.
var (
	digits     = sickle.Many1(sickle.ChRange('0', '9'))
	digits_opt = sickle.Many(sickle.ChRange('0', '9'))

	ncname_start_char = sickle.Choice(
		sickle.ChRange('A', 'Z'),
		sickle.Ch('_'),
		sickle.ChRange('a', 'z'),
		sickle.ChRange(0xC0, 0xD6),
		sickle.ChRange(0xD8, 0xF6),
		sickle.ChRange(0xF8, 0x2FF),
		sickle.ChRange(0x370, 0x37D),
		sickle.ChRange(0x27F, 0x1FFF),
		sickle.ChRange(0x200C, 0x200D),
		sickle.ChRange(0x2070, 0x218F),
		sickle.ChRange(0x2C00, 0x2FEF),
		sickle.ChRange(0x3001, 0xD7FF),
		sickle.ChRange(0xF900, 0xFDCF),
		sickle.ChRange(0xFDF0, 0xFFFD),