package ebnf

import "github.com/alecthomas/participle/lexer/ebnf"

Package ebnf is an EBNF lexer for Participle.

The EBNF grammar syntax is as defined by "golang.org/x/exp/ebnf" with one extension: ranges also support exclusions, eg. "a"…"z"-"f" and "a"…"z"-"f"…"g".

Index

Functions

func New

func New(grammar string, options ...Option) (lexer.Definition, error)

New creates a Lexer from an EBNF grammar.

The EBNF grammar syntax is as defined by "golang.org/x/exp/ebnf" with one extension: ranges also support exclusions, eg. "a"…"z"-"f" and "a"…"z"-"f"…"g". Exclusions can be chained.

Upper-case productions are exported as terminals. Lower-case productions are non-terminals. All productions are lexical.

Here's an example grammar for parsing whitespace and identifiers:

Identifier = alpha { alpha | number } .
Whitespace = "\n" | "\r" | "\t" | " " .
alpha = "a"…"z" | "A"…"Z" | "_" .
number = "0"…"9" .

Types

type Option

type Option func(*ebnfLexerDefinition)

Option for configuring the EBNF lexer.

Source Files

ebnf.go expressions.go options.go reader.go

Directories

PathSynopsis
lexer/ebnf/internalPackage internal is a library for EBNF grammars.
Version
v0.7.1 (latest)
Published
Nov 26, 2020
Platform
linux/amd64
Imports
9 packages
Last checked
1 week ago

Tools for package owners.