package
0.33.0
Repository: https://github.com/brimdata/zed.git
Documentation: pkg.go.dev

# README

Zed parser

This directory contains the Zed parser implemented in PEG.

There is a single PEG input file that works with both pigeon, which is Go based, and pegjs, which is JavaScript based. This allows us to embed a Zed compiler into either JavaScript or Go.

The single parser file is run through the C pre-processor allowing macro and ifdef logic to create the two variants of PEG.

Install

You need pegjs, pigeon, and goimports to build the parsers. To install them, run:

go get github.com/mna/pigeon golang.org/x/tools/cmd/goimports
npm install -g pegjs

Build

To build the parsers, just run make:

make

This will run the C pre-processor to make the two PEG files and run pigeon and pegjs to create the two parsers.

Testing

The zed compile command can be used for easily testing the output of the Zed parser.

Development

During development, the easiest way to run the parser is with this make command at the root of this repository:

make peg

This will ensure the PEG-generated javascript and Go parsers are up to date with parser.peg

To update the parser and launch the zc -repl, your can run make peg-run.

# Functions

AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes.
ConcatSource concatenates the source files in filenames followed by src, returning the result and a corresponding slice of SourceInfos.
Debug creates an Option to set the debug flag to b.
Entrypoint creates an Option to set the rule name to use as entrypoint.
GlobalStore creates an Option to set a key to a certain value in the globalStore.
ImproveError tries to improve an error from Parse.
InitState creates an Option to set a key to a certain value in the global "state" store.
MaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).
Memoize creates an Option to set the memoize flag to b.
NewError returns an Error.
No description provided by the author
Parse parses the data from b using filename as information in the error messages.
ParseFile parses the file identified by filename.
ParseReader parses the data from r using filename as information in the error messages.
ParseZed calls ConcatSource followed by Parse.
ParseZedByRule calls Parse with rule as entrypoint.
Recover creates an Option to set the recover flag to b.
Statistics adds a user provided Stats struct to the parser to allow the user to process the results after the parsing has finished.

# Structs

Error is a parse error with nice formatting.
SourceInfo holds source file offsets.
Stats stores some statistics, gathered during parsing.

# Interfaces

Cloner is implemented by any value that has a Clone method, which returns a copy of the value.

# Type aliases

Option is a function that can set an option on the parser.