File: parse.go

package info (click to toggle)
addchain 0.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: sh: 428; makefile: 10
file content (35 lines) | stat: -rw-r--r-- 820 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Package parse implements a parser for acc programs.
package parse

import (
	"io"
	"strings"

	"github.com/mmcloughlin/addchain/acc/ast"
	"github.com/mmcloughlin/addchain/acc/parse/internal/parser"
)

//go:generate pigeon -o internal/parser/zparser.go acc.peg

// File parses filename.
func File(filename string) (*ast.Chain, error) {
	return cast(parser.ParseFile(filename))
}

// Reader parses the data from r using filename as information in
// error messages.
func Reader(filename string, r io.Reader) (*ast.Chain, error) {
	return cast(parser.ParseReader(filename, r))
}

// String parses s.
func String(s string) (*ast.Chain, error) {
	return Reader("string", strings.NewReader(s))
}

func cast(i interface{}, err error) (*ast.Chain, error) {
	if err != nil {
		return nil, err
	}
	return i.(*ast.Chain), nil
}