示例#1
0
文件: xpath.go 项目: stephenmw/sickle
// ignores optional whitespace between rules
func tokSeq(rules ...sickle.Rule) sickle.Rule {
	// make a new rule slice with enough space to put a separator between each
	// rule.
	newLen := 2*len(rules) - 1
	rs := make([]sickle.Rule, newLen)

	// fill in rules
	for i := 0; i < len(rs); i += 2 {
		rs[i] = rules[i/2]
	}

	// fill in separators
	for i := 1; i < len(rs); i += 2 {
		rs[i] = ignore_optional_ws
	}

	return sickle.Seq(rs...)
}
示例#2
0
文件: calc.go 项目: stephenmw/sickle
	"os"

	"github.com/davecgh/go-spew/spew"
	"sickle"
)

func init() {
	expr.Bind(expr_actual)
}

var (
	Rule = expr

	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,
	)
示例#3
0
func init() {
	any_type.Bind(any_type_actual)
}

var (
	Rule = any_type

	any_type        = sickle.Indirect()
	any_type_actual = sickle.Choice(
		b_dict,
		b_list,
		b_string,
		b_int,
	)

	b_dict   = sickle.Seq(dict_start, dict_elements, end)
	b_list   = sickle.Seq(list_start, list_elements, end)
	b_int    = sickle.Seq(int_start, b_sint, end)
	b_string = sickle.LengthValue(sickle.Left(parseUint(b_uint), colon), sickle.Byte())

	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))
示例#4
0
文件: xpath.go 项目: stephenmw/sickle
// sepBy1 but ignore whitespace around separator
func tokSepBy1(r, sep sickle.Rule) sickle.Rule {
	return sickle.SepBy1(
		r,
		sickle.Seq(ignore_optional_ws, sep, ignore_optional_ws),
	)
}
示例#5
0
文件: xpath.go 项目: stephenmw/sickle
	reverse_axis = sickle.Choice(
		tokSeq(parent, double_colon),
		tokSeq(ancestor, double_colon),
		tokSeq(preceding_sibling, double_colon),
		tokSeq(preceding, double_colon),
		tokSeq(ancestor_or_self, double_colon),
	)
	abbrev_reverse_step = double_dot

	node_test = sickle.Choice(kind_test, name_test)
	name_test = sickle.Choice(eq_name, wildcard)
	wildcard  = sickle.Choice(
		asterisk,
		tokSeq(nc_name, colon, asterisk),
		tokSeq(asterisk, colon, nc_name),
		sickle.Seq(braced_uri_literal, asterisk), // ws: explicit
	)

	postfix_expr = tokSeq(
		primary_expr,
		tokMany(sickle.Choice(predicate, argument_list)),
	)

	argument_list = tokSeq(
		left_paren,
		sickle.Opt(tokSepBy1(argument, comma)),
		right_paren,
	)

	predicate_list = tokMany(predicate)
	predicate      = tokSeq(left_bracket, expr, right_bracket)
示例#6
0
	ws = sickle.Many1(sickle.Choice(
		ws_char,
		comment,
	))

	ws_char = sickle.Choice(
		sickle.Ch(0x20),
		sickle.Ch(0x9),
		sickle.Ch(0xD),
		sickle.Ch(0xA),
	)

	comment        = sickle.Indirect()
	comment_actual = sickle.Seq(
		comment_start,
		sickle.Many(sickle.Choice(comment_contents, comment)),
		comment_end,
	)

	comment_contents = sickle.Many1(sickle.Right(
		sickle.Not(sickle.Choice(comment_start, comment_end)),
		char,
	))

	comment_start = sickle.TokenStr("(:")
	comment_end   = sickle.TokenStr(":)")

	char = sickle.Choice(
		ws_char,
		sickle.ChRange(0x20, 0xD7FF),
		sickle.ChRange(0x20, 0xD7FF),