示例#1
0
文件: parser.go 项目: ironbay/giraffe
func Parse(input string, options *ParseOptions) (*ast.Document, error) {
	source := ast.NewSource(input, "")
	parser, err := newParser(source, options)
	if err != nil {

	}
	return parseDocument(parser)
}
示例#2
0
文件: parser.go 项目: ironbay/giraffe
func ParseValue(input string, options *ParseOptions) {
	source := ast.NewSource(input, "")
	parser, err := newParser(source, options)
	if err != nil {

	}
	return parseValueLiteral(parser)
}
示例#3
0
func TestDollar(t *testing.T) {
	source := ast.NewSource("$", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, DOLLAR, 0, 1, "")
}
示例#4
0
func TestWhitespace(t *testing.T) {
	source := ast.NewSource("\n   foo   \n   ", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, NAME, 4, 7, "foo")
}
示例#5
0
func TestScience(t *testing.T) {
	source := ast.NewSource("123e+4", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, FLOAT, 0, 6, "123e+4")
}
示例#6
0
func TestBang(t *testing.T) {
	source := ast.NewSource("!", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, BANG, 0, 1, "")
}
示例#7
0
func TestNegative(t *testing.T) {
	source := ast.NewSource("-4", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, INT, 0, 2, "-4")
}
示例#8
0
func TestDecimal(t *testing.T) {
	source := ast.NewSource("0.123", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, FLOAT, 0, 5, "0.123")
}
示例#9
0
func TestSlashes(t *testing.T) {
	source := ast.NewSource("\"slashes \\\\ \\/\"", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, STRING, 0, 15, "slashes \\ /")
}
示例#10
0
func TestInt(t *testing.T) {
	source := ast.NewSource("4", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, INT, 0, 1, "4")
}
示例#11
0
func TestEscaped(t *testing.T) {
	source := ast.NewSource("\"escaped \\n\\r\\b\\t\\f\"", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, STRING, 0, 20, "escaped \n\r\b\t\f")
}
示例#12
0
func TestQuotes(t *testing.T) {
	source := ast.NewSource("\"quote \\\"\"", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, STRING, 0, 10, "quote \"")
}
示例#13
0
func TestWhitespaceString(t *testing.T) {
	source := ast.NewSource("\" white space \"", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, STRING, 0, 15, " white space ")
}
示例#14
0
func TestSimpleString(t *testing.T) {
	source := ast.NewSource("\"simple\"", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, STRING, 0, 8, "simple")
}
示例#15
0
func TestComments(t *testing.T) {
	source := ast.NewSource("#hello\nfoo#comment", "")
	result, err := Lex(source)(-1)
	expect(t, err, result, NAME, 7, 10, "foo")
}