Skip to content

Commit 4dc8bc1

Browse files
stevegtalecthomas
authored andcommitted
clarify README.md
- fixes #180 - make it clear custom lexers are fully supported - indentation lexers are implementable - stateful replaced regex - EBNF lexer removed -- callers need to implement their own EBNF lexer
1 parent d2d42d9 commit 4dc8bc1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

README.md

+20-8
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,11 @@ To use your own Lexer you will need to implement two interfaces:
303303
### Stateful lexer
304304
<a id="markdown-stateful-lexer" name="stateful-lexer"></a>
305305

306-
Participle's included stateful/modal lexer provides powerful yet convenient
307-
construction of most lexers (notably, indentation based lexers cannot be
308-
expressed).
306+
In addition to the default lexer, Participle includes an optional
307+
stateful/modal lexer which provides powerful yet convenient
308+
construction of most lexers. (Notably, indentation based lexers cannot
309+
be expressed using the `stateful` lexer -- for discussion of how these
310+
lexers can be implemented, see [#20](https://github.com/alecthomas/participle/issues/20)).
309311

310312
It is sometimes the case that a simple lexer cannot fully express the tokens
311313
required by a parser. The canonical example of this is interpolated strings
@@ -376,12 +378,13 @@ var lexer = stateful.Must(Rules{
376378
### Example simple/non-stateful lexer
377379
<a id="markdown-example-simple%2Fnon-stateful-lexer" name="example-simple%2Fnon-stateful-lexer"></a>
378380

379-
The Stateful lexer is now the only custom lexer supported by Participle, but
380-
most parsers won't need this level of flexibility. To support this common
381-
case, which replaces the old `Regex` and `EBNF` lexers, you can use
382-
`stateful.MustSimple()` and `stateful.NewSimple()`.
381+
Other than the default and `stateful` lexers, it's easy to define your
382+
own stateless lexer using the `stateful.MustSimple()` and
383+
`stateful.NewSimple()` methods. These methods accept a slice of
384+
stateful.Rule{} objects consisting of a key and a regex-style pattern.
385+
The `stateful` lexer replaced the old `Regex` lexer.
383386

384-
eg. The lexer for a form of BASIC:
387+
For example, the lexer for a form of BASIC:
385388

386389
```go
387390
var basicLexer = stateful.MustSimple([]stateful.Rule{
@@ -394,6 +397,7 @@ var basicLexer = stateful.MustSimple([]stateful.Rule{
394397
{"whitespace", `[ \t]+`, nil},
395398
})
396399
```
400+
397401
### Experimental - code generation
398402
<a id="markdown-experimental---code-generation" name="experimental---code-generation"></a>
399403

@@ -584,6 +588,14 @@ recursion must be eliminated by restructuring your grammar.
584588
## EBNF
585589
<a id="markdown-ebnf" name="ebnf"></a>
586590

591+
The old `EBNF` lexer was removed in a major refactoring at
592+
362b26640fa3dc406aa60960f7d9a5b9a909414e -- if you have an EBNF
593+
grammar you need to implement, you can either translate it into
594+
regex-style stateful.Rule{} syntax or implement your own EBNF lexer --
595+
you might be able to use [the old EBNF
596+
lexer](https://github.com/alecthomas/participle/blob/2403858c8b2068b4b0cf96a6b36dd7069674039b/lexer/ebnf/ebnf.go)
597+
as a starting point.
598+
587599
Participle supports outputting an EBNF grammar from a Participle parser. Once
588600
the parser is constructed simply call `String()`.
589601

0 commit comments

Comments
 (0)