コード例 #1
0
ファイル: bencode.go プロジェクト: stephenmw/sickle
	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))
	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 {
コード例 #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
ファイル: terminal_symbols.go プロジェクト: stephenmw/sickle
	"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),
		sickle.ChRange(0x10000, 0xEFFFF),
	)