1Pegex::Overview(3)    User Contributed Perl Documentation   Pegex::Overview(3)
2
3
4

What is Pegex?

6       Pegex is a Friendly, Acmeist, PEG Parser framework. Friendly means that
7       it is simple to create, understand, modify and maintain Pegex parsers.
8       Acmeist means that the parsers will work automatically in many
9       programming languages (as long as they have some kind of traditional
10       "regex" support). PEG (Parser Expression Grammars) is the new style of
11       Recursive-Descent/BNF style grammar definition syntax.
12
13       The name "Pegex" comes from PEG + Regex. With Pegex you define top down
14       grammars that eventually break down to regex fragments. ie The low
15       level parsing matches are always done with regexes against the current
16       position in the input stream.
17

What is Parsing?

19       It may seem like a silly question, but it's important to have an
20       understanding of what parsing is and what a parser can do for you. At
21       the the most basic level "parsing" is the act of reading through an
22       input, making sense of it, and possibly doing something with what is
23       found.
24
25       Usually a parser gets its instructions of what means what from
26       something called a grammar. A grammar is a set of rules that defines
27       how the input must be structured. In many parsing methodologies, input
28       is preprocessed (possibly into tokens) before the parser/grammar get to
29       look at it. Although this is a common method, it is not the only
30       approach.
31

How Pegex Works

33       Pegex parsing consists of 4 distinct parts or objects:
34
35       Parser
36           The Pegex parsing engine
37
38       Grammar
39           The rules of a particular syntax
40
41       Receiver
42           The logic for processing matches
43
44       Input
45           Text conforming to the grammar rules
46
47       Quite simply, a parser object is created with a grammar object and a
48       receiver object. Then the parser object's "parse()" method is called on
49       an input object. The parser applies the rules of the grammar to the
50       input and invokes methods of the receiver as the rules match. The parse
51       is either successful or results in an error. The result is whatever the
52       receiver object decides it should be.
53
54       For example consider a parser that turns the Markdown text language
55       into HTML.  The Pegex code to use this might look like this:
56
57       In the simplest terms, Pegex works like this (pseudocode):
58
59           parser = new Pegex.Parser(
60               grammar: new Markdown.Grammar
61               receiver: new Markdown.Receiver.HTML
62           )
63           html = parser.parse(markdown)
64

See Also

66       •   Pegex::API
67
68       •   Pegex::Syntax
69
70       •   Pegex::Tutorial
71
72
73
74perl v5.32.1                      2021-01-27                Pegex::Overview(3)
Impressum