newParser creates a parser with the specified input source and options.
(filename string, b []byte, opts ...Option)
| 24746 | |
| 24747 | // newParser creates a parser with the specified input source and options. |
| 24748 | func newParser(filename string, b []byte, opts ...Option) *parser { |
| 24749 | stats := Stats{ |
| 24750 | ChoiceAltCnt: make(map[string]map[string]int), |
| 24751 | } |
| 24752 | |
| 24753 | p := &parser{ |
| 24754 | filename: filename, |
| 24755 | errs: new(errList), |
| 24756 | data: b, |
| 24757 | pt: savepoint{position: position{line: 1}}, |
| 24758 | recover: true, |
| 24759 | cur: current{ |
| 24760 | state: make(storeDict), |
| 24761 | globalStore: make(storeDict), |
| 24762 | }, |
| 24763 | maxFailPos: position{col: 1, line: 1}, |
| 24764 | maxFailExpected: make([]string, 0, 20), |
| 24765 | Stats: &stats, |
| 24766 | // start rule is rule [0] unless an alternate entrypoint is specified |
| 24767 | entrypoint: g.rules[0].name, |
| 24768 | } |
| 24769 | p.setOptions(opts) |
| 24770 | |
| 24771 | if p.maxExprCnt == 0 { |
| 24772 | p.maxExprCnt = math.MaxUint64 |
| 24773 | } |
| 24774 | |
| 24775 | return p |
| 24776 | } |
| 24777 | |
| 24778 | // setOptions applies the options to the parser. |
| 24779 | func (p *parser) setOptions(opts []Option) { |