parse.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Code to parse a template.
  5. package template
  6. import (
  7. "fmt"
  8. "io"
  9. "io/ioutil"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "unicode"
  14. "unicode/utf8"
  15. )
  16. // Errors returned during parsing and execution. Users may extract the information and reformat
  17. // if they desire.
  18. type Error struct {
  19. Line int
  20. Msg string
  21. }
  22. func (e *Error) Error() string { return fmt.Sprintf("line %d: %s", e.Line, e.Msg) }
  23. // checkError is a deferred function to turn a panic with type *Error into a plain error return.
  24. // Other panics are unexpected and so are re-enabled.
  25. func checkError(error *error) {
  26. if v := recover(); v != nil {
  27. if e, ok := v.(*Error); ok {
  28. *error = e
  29. } else {
  30. // runtime errors should crash
  31. panic(v)
  32. }
  33. }
  34. }
  35. // Most of the literals are aces.
  36. var lbrace = []byte{'{'}
  37. var rbrace = []byte{'}'}
  38. var space = []byte{' '}
  39. var tab = []byte{'\t'}
  40. // The various types of "tokens", which are plain text or (usually) brace-delimited descriptors
  41. const (
  42. tokAlternates = iota
  43. tokComment
  44. tokEnd
  45. tokLiteral
  46. tokOr
  47. tokRepeated
  48. tokSection
  49. tokText
  50. tokVariable
  51. )
  52. // FormatterMap is the type describing the mapping from formatter
  53. // names to the functions that implement them.
  54. type FormatterMap map[string]func(io.Writer, string, ...interface{})
  55. // Built-in formatters.
  56. var builtins = FormatterMap{
  57. "html": HTMLFormatter,
  58. "str": StringFormatter,
  59. "": StringFormatter,
  60. }
  61. // The parsed state of a template is a vector of xxxElement structs.
  62. // Sections have line numbers so errors can be reported better during execution.
  63. // Plain text.
  64. type textElement struct {
  65. text []byte
  66. }
  67. // A literal such as .meta-left or .meta-right
  68. type literalElement struct {
  69. text []byte
  70. }
  71. // A variable invocation to be evaluated
  72. type variableElement struct {
  73. linenum int
  74. args []interface{} // The fields and literals in the invocation.
  75. fmts []string // Names of formatters to apply. len(fmts) > 0
  76. }
  77. // A variableElement arg to be evaluated as a field name
  78. type fieldName string
  79. // A .section block, possibly with a .or
  80. type sectionElement struct {
  81. linenum int // of .section itself
  82. field string // cursor field for this block
  83. start int // first element
  84. or int // first element of .or block
  85. end int // one beyond last element
  86. }
  87. // A .repeated block, possibly with a .or and a .alternates
  88. type repeatedElement struct {
  89. sectionElement // It has the same structure...
  90. altstart int // ... except for alternates
  91. altend int
  92. }
  93. // Template is the type that represents a template definition.
  94. // It is unchanged after parsing.
  95. type Template struct {
  96. fmap FormatterMap // formatters for variables
  97. // Used during parsing:
  98. ldelim, rdelim []byte // delimiters; default {}
  99. buf []byte // input text to process
  100. p int // position in buf
  101. linenum int // position in input
  102. // Parsed results:
  103. elems []interface{}
  104. }
  105. // New creates a new template with the specified formatter map (which
  106. // may be nil) to define auxiliary functions for formatting variables.
  107. func New(fmap FormatterMap) *Template {
  108. t := new(Template)
  109. t.fmap = fmap
  110. t.ldelim = lbrace
  111. t.rdelim = rbrace
  112. t.elems = make([]interface{}, 0, 16)
  113. return t
  114. }
  115. // Report error and stop executing. The line number must be provided explicitly.
  116. func (t *Template) execError(st *state, line int, err string, args ...interface{}) {
  117. panic(&Error{line, fmt.Sprintf(err, args...)})
  118. }
  119. // Report error, panic to terminate parsing.
  120. // The line number comes from the template state.
  121. func (t *Template) parseError(err string, args ...interface{}) {
  122. panic(&Error{t.linenum, fmt.Sprintf(err, args...)})
  123. }
  124. // Is this an exported - upper case - name?
  125. func isExported(name string) bool {
  126. r, _ := utf8.DecodeRuneInString(name)
  127. return unicode.IsUpper(r)
  128. }
  129. // -- Lexical analysis
  130. // Is c a space character?
  131. func isSpace(c uint8) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' }
  132. // Safely, does s[n:n+len(t)] == t?
  133. func equal(s []byte, n int, t []byte) bool {
  134. b := s[n:]
  135. if len(t) > len(b) { // not enough space left for a match.
  136. return false
  137. }
  138. for i, c := range t {
  139. if c != b[i] {
  140. return false
  141. }
  142. }
  143. return true
  144. }
  145. // isQuote returns true if c is a string- or character-delimiting quote character.
  146. func isQuote(c byte) bool {
  147. return c == '"' || c == '`' || c == '\''
  148. }
  149. // endQuote returns the end quote index for the quoted string that
  150. // starts at n, or -1 if no matching end quote is found before the end
  151. // of the line.
  152. func endQuote(s []byte, n int) int {
  153. quote := s[n]
  154. for n++; n < len(s); n++ {
  155. switch s[n] {
  156. case '\\':
  157. if quote == '"' || quote == '\'' {
  158. n++
  159. }
  160. case '\n':
  161. return -1
  162. case quote:
  163. return n
  164. }
  165. }
  166. return -1
  167. }
  168. // nextItem returns the next item from the input buffer. If the returned
  169. // item is empty, we are at EOF. The item will be either a
  170. // delimited string or a non-empty string between delimited
  171. // strings. Tokens stop at (but include, if plain text) a newline.
  172. // Action tokens on a line by themselves drop any space on
  173. // either side, up to and including the newline.
  174. func (t *Template) nextItem() []byte {
  175. startOfLine := t.p == 0 || t.buf[t.p-1] == '\n'
  176. start := t.p
  177. var i int
  178. newline := func() {
  179. t.linenum++
  180. i++
  181. }
  182. // Leading space up to but not including newline
  183. for i = start; i < len(t.buf); i++ {
  184. if t.buf[i] == '\n' || !isSpace(t.buf[i]) {
  185. break
  186. }
  187. }
  188. leadingSpace := i > start
  189. // What's left is nothing, newline, delimited string, or plain text
  190. switch {
  191. case i == len(t.buf):
  192. // EOF; nothing to do
  193. case t.buf[i] == '\n':
  194. newline()
  195. case equal(t.buf, i, t.ldelim):
  196. left := i // Start of left delimiter.
  197. right := -1 // Will be (immediately after) right delimiter.
  198. haveText := false // Delimiters contain text.
  199. i += len(t.ldelim)
  200. // Find the end of the action.
  201. for ; i < len(t.buf); i++ {
  202. if t.buf[i] == '\n' {
  203. break
  204. }
  205. if isQuote(t.buf[i]) {
  206. i = endQuote(t.buf, i)
  207. if i == -1 {
  208. t.parseError("unmatched quote")
  209. return nil
  210. }
  211. continue
  212. }
  213. if equal(t.buf, i, t.rdelim) {
  214. i += len(t.rdelim)
  215. right = i
  216. break
  217. }
  218. haveText = true
  219. }
  220. if right < 0 {
  221. t.parseError("unmatched opening delimiter")
  222. return nil
  223. }
  224. // Is this a special action (starts with '.' or '#') and the only thing on the line?
  225. if startOfLine && haveText {
  226. firstChar := t.buf[left+len(t.ldelim)]
  227. if firstChar == '.' || firstChar == '#' {
  228. // It's special and the first thing on the line. Is it the last?
  229. for j := right; j < len(t.buf) && isSpace(t.buf[j]); j++ {
  230. if t.buf[j] == '\n' {
  231. // Yes it is. Drop the surrounding space and return the {.foo}
  232. t.linenum++
  233. t.p = j + 1
  234. return t.buf[left:right]
  235. }
  236. }
  237. }
  238. }
  239. // No it's not. If there's leading space, return that.
  240. if leadingSpace {
  241. // not trimming space: return leading space if there is some.
  242. t.p = left
  243. return t.buf[start:left]
  244. }
  245. // Return the word, leave the trailing space.
  246. start = left
  247. break
  248. default:
  249. for ; i < len(t.buf); i++ {
  250. if t.buf[i] == '\n' {
  251. newline()
  252. break
  253. }
  254. if equal(t.buf, i, t.ldelim) {
  255. break
  256. }
  257. }
  258. }
  259. item := t.buf[start:i]
  260. t.p = i
  261. return item
  262. }
  263. // Turn a byte array into a space-split array of strings,
  264. // taking into account quoted strings.
  265. func words(buf []byte) []string {
  266. s := make([]string, 0, 5)
  267. for i := 0; i < len(buf); {
  268. // One word per loop
  269. for i < len(buf) && isSpace(buf[i]) {
  270. i++
  271. }
  272. if i == len(buf) {
  273. break
  274. }
  275. // Got a word
  276. start := i
  277. if isQuote(buf[i]) {
  278. i = endQuote(buf, i)
  279. if i < 0 {
  280. i = len(buf)
  281. } else {
  282. i++
  283. }
  284. }
  285. // Even with quotes, break on space only. This handles input
  286. // such as {""|} and catches quoting mistakes.
  287. for i < len(buf) && !isSpace(buf[i]) {
  288. i++
  289. }
  290. s = append(s, string(buf[start:i]))
  291. }
  292. return s
  293. }
  294. // Analyze an item and return its token type and, if it's an action item, an array of
  295. // its constituent words.
  296. func (t *Template) analyze(item []byte) (tok int, w []string) {
  297. // item is known to be non-empty
  298. if !equal(item, 0, t.ldelim) { // doesn't start with left delimiter
  299. tok = tokText
  300. return
  301. }
  302. if !equal(item, len(item)-len(t.rdelim), t.rdelim) { // doesn't end with right delimiter
  303. t.parseError("internal error: unmatched opening delimiter") // lexing should prevent this
  304. return
  305. }
  306. if len(item) <= len(t.ldelim)+len(t.rdelim) { // no contents
  307. t.parseError("empty directive")
  308. return
  309. }
  310. // Comment
  311. if item[len(t.ldelim)] == '#' {
  312. tok = tokComment
  313. return
  314. }
  315. // Split into words
  316. w = words(item[len(t.ldelim) : len(item)-len(t.rdelim)]) // drop final delimiter
  317. if len(w) == 0 {
  318. t.parseError("empty directive")
  319. return
  320. }
  321. first := w[0]
  322. if first[0] != '.' {
  323. tok = tokVariable
  324. return
  325. }
  326. if len(first) > 1 && first[1] >= '0' && first[1] <= '9' {
  327. // Must be a float.
  328. tok = tokVariable
  329. return
  330. }
  331. switch first {
  332. case ".meta-left", ".meta-right", ".space", ".tab":
  333. tok = tokLiteral
  334. return
  335. case ".or":
  336. tok = tokOr
  337. return
  338. case ".end":
  339. tok = tokEnd
  340. return
  341. case ".section":
  342. if len(w) != 2 {
  343. t.parseError("incorrect fields for .section: %s", item)
  344. return
  345. }
  346. tok = tokSection
  347. return
  348. case ".repeated":
  349. if len(w) != 3 || w[1] != "section" {
  350. t.parseError("incorrect fields for .repeated: %s", item)
  351. return
  352. }
  353. tok = tokRepeated
  354. return
  355. case ".alternates":
  356. if len(w) != 2 || w[1] != "with" {
  357. t.parseError("incorrect fields for .alternates: %s", item)
  358. return
  359. }
  360. tok = tokAlternates
  361. return
  362. }
  363. t.parseError("bad directive: %s", item)
  364. return
  365. }
  366. // formatter returns the Formatter with the given name in the Template, or nil if none exists.
  367. func (t *Template) formatter(name string) func(io.Writer, string, ...interface{}) {
  368. if t.fmap != nil {
  369. if fn := t.fmap[name]; fn != nil {
  370. return fn
  371. }
  372. }
  373. return builtins[name]
  374. }
  375. // -- Parsing
  376. // newVariable allocates a new variable-evaluation element.
  377. func (t *Template) newVariable(words []string) *variableElement {
  378. formatters := extractFormatters(words)
  379. args := make([]interface{}, len(words))
  380. // Build argument list, processing any literals
  381. for i, word := range words {
  382. var lerr error
  383. switch word[0] {
  384. case '"', '`', '\'':
  385. v, err := strconv.Unquote(word)
  386. if err == nil && word[0] == '\'' {
  387. args[i], _ = utf8.DecodeRuneInString(v)
  388. } else {
  389. args[i], lerr = v, err
  390. }
  391. case '.', '+', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
  392. v, err := strconv.ParseInt(word, 0, 64)
  393. if err == nil {
  394. args[i] = v
  395. } else {
  396. v, err := strconv.ParseFloat(word, 64)
  397. args[i], lerr = v, err
  398. }
  399. default:
  400. args[i] = fieldName(word)
  401. }
  402. if lerr != nil {
  403. t.parseError("invalid literal: %q: %s", word, lerr)
  404. }
  405. }
  406. // We could remember the function address here and avoid the lookup later,
  407. // but it's more dynamic to let the user change the map contents underfoot.
  408. // We do require the name to be present, though.
  409. // Is it in user-supplied map?
  410. for _, f := range formatters {
  411. if t.formatter(f) == nil {
  412. t.parseError("unknown formatter: %q", f)
  413. }
  414. }
  415. return &variableElement{t.linenum, args, formatters}
  416. }
  417. // extractFormatters extracts a list of formatters from words.
  418. // After the final space-separated argument in a variable, formatters may be
  419. // specified separated by pipe symbols. For example: {a b c|d|e}
  420. // The words parameter still has the formatters joined by '|' in the last word.
  421. // extractFormatters splits formatters, replaces the last word with the content
  422. // found before the first '|' within it, and returns the formatters obtained.
  423. // If no formatters are found in words, the default formatter is returned.
  424. func extractFormatters(words []string) (formatters []string) {
  425. // "" is the default formatter.
  426. formatters = []string{""}
  427. if len(words) == 0 {
  428. return
  429. }
  430. var bar int
  431. lastWord := words[len(words)-1]
  432. if isQuote(lastWord[0]) {
  433. end := endQuote([]byte(lastWord), 0)
  434. if end < 0 || end+1 == len(lastWord) || lastWord[end+1] != '|' {
  435. return
  436. }
  437. bar = end + 1
  438. } else {
  439. bar = strings.IndexRune(lastWord, '|')
  440. if bar < 0 {
  441. return
  442. }
  443. }
  444. words[len(words)-1] = lastWord[0:bar]
  445. formatters = strings.Split(lastWord[bar+1:], "|")
  446. return
  447. }
  448. // Grab the next item. If it's simple, just append it to the template.
  449. // Otherwise return its details.
  450. func (t *Template) parseSimple(item []byte) (done bool, tok int, w []string) {
  451. tok, w = t.analyze(item)
  452. done = true // assume for simplicity
  453. switch tok {
  454. case tokComment:
  455. return
  456. case tokText:
  457. t.elems = append(t.elems, &textElement{item})
  458. return
  459. case tokLiteral:
  460. switch w[0] {
  461. case ".meta-left":
  462. t.elems = append(t.elems, &literalElement{t.ldelim})
  463. case ".meta-right":
  464. t.elems = append(t.elems, &literalElement{t.rdelim})
  465. case ".space":
  466. t.elems = append(t.elems, &literalElement{space})
  467. case ".tab":
  468. t.elems = append(t.elems, &literalElement{tab})
  469. default:
  470. t.parseError("internal error: unknown literal: %s", w[0])
  471. }
  472. return
  473. case tokVariable:
  474. t.elems = append(t.elems, t.newVariable(w))
  475. return
  476. }
  477. return false, tok, w
  478. }
  479. // parseRepeated and parseSection are mutually recursive
  480. func (t *Template) parseRepeated(words []string) *repeatedElement {
  481. r := new(repeatedElement)
  482. t.elems = append(t.elems, r)
  483. r.linenum = t.linenum
  484. r.field = words[2]
  485. // Scan section, collecting true and false (.or) blocks.
  486. r.start = len(t.elems)
  487. r.or = -1
  488. r.altstart = -1
  489. r.altend = -1
  490. Loop:
  491. for {
  492. item := t.nextItem()
  493. if len(item) == 0 {
  494. t.parseError("missing .end for .repeated section")
  495. break
  496. }
  497. done, tok, w := t.parseSimple(item)
  498. if done {
  499. continue
  500. }
  501. switch tok {
  502. case tokEnd:
  503. break Loop
  504. case tokOr:
  505. if r.or >= 0 {
  506. t.parseError("extra .or in .repeated section")
  507. break Loop
  508. }
  509. r.altend = len(t.elems)
  510. r.or = len(t.elems)
  511. case tokSection:
  512. t.parseSection(w)
  513. case tokRepeated:
  514. t.parseRepeated(w)
  515. case tokAlternates:
  516. if r.altstart >= 0 {
  517. t.parseError("extra .alternates in .repeated section")
  518. break Loop
  519. }
  520. if r.or >= 0 {
  521. t.parseError(".alternates inside .or block in .repeated section")
  522. break Loop
  523. }
  524. r.altstart = len(t.elems)
  525. default:
  526. t.parseError("internal error: unknown repeated section item: %s", item)
  527. break Loop
  528. }
  529. }
  530. if r.altend < 0 {
  531. r.altend = len(t.elems)
  532. }
  533. r.end = len(t.elems)
  534. return r
  535. }
  536. func (t *Template) parseSection(words []string) *sectionElement {
  537. s := new(sectionElement)
  538. t.elems = append(t.elems, s)
  539. s.linenum = t.linenum
  540. s.field = words[1]
  541. // Scan section, collecting true and false (.or) blocks.
  542. s.start = len(t.elems)
  543. s.or = -1
  544. Loop:
  545. for {
  546. item := t.nextItem()
  547. if len(item) == 0 {
  548. t.parseError("missing .end for .section")
  549. break
  550. }
  551. done, tok, w := t.parseSimple(item)
  552. if done {
  553. continue
  554. }
  555. switch tok {
  556. case tokEnd:
  557. break Loop
  558. case tokOr:
  559. if s.or >= 0 {
  560. t.parseError("extra .or in .section")
  561. break Loop
  562. }
  563. s.or = len(t.elems)
  564. case tokSection:
  565. t.parseSection(w)
  566. case tokRepeated:
  567. t.parseRepeated(w)
  568. case tokAlternates:
  569. t.parseError(".alternates not in .repeated")
  570. default:
  571. t.parseError("internal error: unknown section item: %s", item)
  572. }
  573. }
  574. s.end = len(t.elems)
  575. return s
  576. }
  577. func (t *Template) parse() {
  578. for {
  579. item := t.nextItem()
  580. if len(item) == 0 {
  581. break
  582. }
  583. done, tok, w := t.parseSimple(item)
  584. if done {
  585. continue
  586. }
  587. switch tok {
  588. case tokOr, tokEnd, tokAlternates:
  589. t.parseError("unexpected %s", w[0])
  590. case tokSection:
  591. t.parseSection(w)
  592. case tokRepeated:
  593. t.parseRepeated(w)
  594. default:
  595. t.parseError("internal error: bad directive in parse: %s", item)
  596. }
  597. }
  598. }
  599. // -- Execution
  600. // -- Public interface
  601. // Parse initializes a Template by parsing its definition. The string
  602. // s contains the template text. If any errors occur, Parse returns
  603. // the error.
  604. func (t *Template) Parse(s string) (err error) {
  605. if t.elems == nil {
  606. return &Error{1, "template not allocated with New"}
  607. }
  608. if !validDelim(t.ldelim) || !validDelim(t.rdelim) {
  609. return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)}
  610. }
  611. defer checkError(&err)
  612. t.buf = []byte(s)
  613. t.p = 0
  614. t.linenum = 1
  615. t.parse()
  616. return nil
  617. }
  618. // ParseFile is like Parse but reads the template definition from the
  619. // named file.
  620. func (t *Template) ParseFile(filename string) (err error) {
  621. b, err := ioutil.ReadFile(filename)
  622. if err != nil {
  623. return err
  624. }
  625. return t.Parse(string(b))
  626. }
  627. // Execute applies a parsed template to the specified data object,
  628. // generating output to wr.
  629. func (t *Template) Execute(wr io.Writer, data interface{}) (err error) {
  630. // Extract the driver data.
  631. val := reflect.ValueOf(data)
  632. defer checkError(&err)
  633. t.p = 0
  634. t.execute(0, len(t.elems), &state{parent: nil, data: val, wr: wr})
  635. return nil
  636. }
  637. // SetDelims sets the left and right delimiters for operations in the
  638. // template. They are validated during parsing. They could be
  639. // validated here but it's better to keep the routine simple. The
  640. // delimiters are very rarely invalid and Parse has the necessary
  641. // error-handling interface already.
  642. func (t *Template) SetDelims(left, right string) {
  643. t.ldelim = []byte(left)
  644. t.rdelim = []byte(right)
  645. }
  646. // Parse creates a Template with default parameters (such as {} for
  647. // metacharacters). The string s contains the template text while
  648. // the formatter map fmap, which may be nil, defines auxiliary functions
  649. // for formatting variables. The template is returned. If any errors
  650. // occur, err will be non-nil.
  651. func Parse(s string, fmap FormatterMap) (t *Template, err error) {
  652. t = New(fmap)
  653. err = t.Parse(s)
  654. if err != nil {
  655. t = nil
  656. }
  657. return
  658. }
  659. // ParseFile is a wrapper function that creates a Template with default
  660. // parameters (such as {} for metacharacters). The filename identifies
  661. // a file containing the template text, while the formatter map fmap, which
  662. // may be nil, defines auxiliary functions for formatting variables.
  663. // The template is returned. If any errors occur, err will be non-nil.
  664. func ParseFile(filename string, fmap FormatterMap) (t *Template, err error) {
  665. b, err := ioutil.ReadFile(filename)
  666. if err != nil {
  667. return nil, err
  668. }
  669. return Parse(string(b), fmap)
  670. }
  671. // MustParse is like Parse but panics if the template cannot be parsed.
  672. func MustParse(s string, fmap FormatterMap) *Template {
  673. t, err := Parse(s, fmap)
  674. if err != nil {
  675. panic("template.MustParse error: " + err.Error())
  676. }
  677. return t
  678. }
  679. // MustParseFile is like ParseFile but panics if the file cannot be read
  680. // or the template cannot be parsed.
  681. func MustParseFile(filename string, fmap FormatterMap) *Template {
  682. b, err := ioutil.ReadFile(filename)
  683. if err != nil {
  684. panic("template.MustParseFile error: " + err.Error())
  685. }
  686. return MustParse(string(b), fmap)
  687. }