Parse parses the input just enough to group tokens, in order, by server block. No further parsing is performed. Server blocks are returned in the order in which they appear. Directives that do not appear in validDirectives will cause an error. If you do not want to check for valid directives, pass i
(filename string, input []byte)
| 37 | // Environment variables in {$ENVIRONMENT_VARIABLE} notation |
| 38 | // will be replaced before parsing begins. |
| 39 | func Parse(filename string, input []byte) ([]ServerBlock, error) { |
| 40 | // unfortunately, we must copy the input because parsing must |
| 41 | // remain a read-only operation, but we have to expand environment |
| 42 | // variables before we parse, which changes the underlying array (#4422) |
| 43 | inputCopy := make([]byte, len(input)) |
| 44 | copy(inputCopy, input) |
| 45 | |
| 46 | tokens, err := allTokens(filename, inputCopy) |
| 47 | if err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | p := parser{ |
| 51 | Dispenser: NewDispenser(tokens), |
| 52 | importGraph: importGraph{ |
| 53 | nodes: make(map[string]struct{}), |
| 54 | edges: make(adjacency), |
| 55 | }, |
| 56 | } |
| 57 | return p.parseAll() |
| 58 | } |
| 59 | |
| 60 | // allTokens lexes the entire input, but does not parse it. |
| 61 | // It returns all the tokens from the input, unstructured |