Exemplo n.º 1
0
	"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,
	)

	digit = sickle.ChRange('0', '9')
Exemplo n.º 2
0
	"strconv"

	"sickle"
)

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))
Exemplo n.º 3
0
// ndt is used to wrap "non-delimiting terminal symbols". These are symbols
// which must be delimited by either a delimiting terminal symbol or whitespace.
func ndt(r sickle.Rule) sickle.Rule {
	return sickle.Left(
		r,
		sickle.And(sickle.Choice(ws, delimiting_terminal_symbol, sickle.End())),
	)
}
Exemplo n.º 4
0
	param_list = tokSepBy1(param, comma)

	param = tokSeq(dollar_sign, eq_name, sickle.Opt(type_declaration))

	function_body = enclosed_expr

	enclosed_expr = tokSeq(left_brace, expr, right_brace)

	expr        = sickle.Indirect()
	expr_actual = tokSepBy1(expr_single, comma)

	expr_single        = sickle.Indirect()
	expr_single_actual = sickle.Choice(
		for_expr,
		let_expr,
		quantified_expr,
		if_expr,
		or_expr,
	)

	for_expr = tokSeq(simple_for_clause, return_token, expr_single)

	simple_for_clause = tokSeq(for_token, tokSepBy1(simple_for_binding, comma))

	simple_for_binding = tokSeq(
		tokSepBy1(tokSeq(dollar_sign, var_name, in, expr_single), comma),
		satisfies, expr_single,
	)

	let_expr = tokSeq(simple_let_clause, return_token, expr_single)
Exemplo n.º 5
0
// 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),
		sickle.ChRange(0x10000, 0xEFFFF),
	)

	ncname_char = sickle.Choice(
		ncname_start_char,
		sickle.Ch('-'),
		sickle.Ch('.'),
		sickle.ChRange('0', '9'),
		sickle.Ch(0xB7),