@@ -303,9 +303,11 @@ To use your own Lexer you will need to implement two interfaces:
303
303
### Stateful lexer
304
304
<a id =" markdown-stateful-lexer " name =" stateful-lexer " ></a >
305
305
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 ) ).
309
311
310
312
It is sometimes the case that a simple lexer cannot fully express the tokens
311
313
required by a parser. The canonical example of this is interpolated strings
@@ -376,12 +378,13 @@ var lexer = stateful.Must(Rules{
376
378
### Example simple/non-stateful lexer
377
379
<a id =" markdown-example-simple%2Fnon-stateful-lexer " name =" example-simple%2Fnon-stateful-lexer " ></a >
378
380
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.
383
386
384
- eg. The lexer for a form of BASIC:
387
+ For example, the lexer for a form of BASIC:
385
388
386
389
``` go
387
390
var basicLexer = stateful.MustSimple ([]stateful.Rule {
@@ -394,6 +397,7 @@ var basicLexer = stateful.MustSimple([]stateful.Rule{
394
397
{" whitespace" , ` [ \t]+` , nil },
395
398
})
396
399
```
400
+
397
401
### Experimental - code generation
398
402
<a id =" markdown-experimental---code-generation " name =" experimental---code-generation " ></a >
399
403
@@ -584,6 +588,14 @@ recursion must be eliminated by restructuring your grammar.
584
588
## EBNF
585
589
<a id =" markdown-ebnf " name =" ebnf " ></a >
586
590
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
+
587
599
Participle supports outputting an EBNF grammar from a Participle parser. Once
588
600
the parser is constructed simply call ` String() ` .
589
601
0 commit comments