[Newbies] How to approach this PEGParser Grammar Fix.

tty gettimothy at zoho.com
Thu Sep 5 15:25:25 UTC 2019

Slowly grokking the big picture.

A Gramamar is a bunch of PEG rules

in the grammarWiki (and now grammarMediaWiki) the "top rule" is

Page <- (Preformatted / Code / UnorderedList / OrderedList / Heading / Table
/ Paragraph / Empty)*

which is a a grouping of zero or more subrules. The rule for Preformatted
looks like this:

Preformatted <- "---\n" .{"---\n"} 

Now here is the neat thing.

In the PEGActor subclass for that grammar PEGWikiGenerator, there are a
bunch of methods. However, within many of those methods are PRAGMAS.

Here is the Preformatted method:

Preformatted: text

	<action: 'Preformatted' arguments: #(2)>
	<action: 'Code' arguments: #(2)>

		newElementTag: Preformatted
		elements: (Array with: (self newText: text))

See those pragmas? 
They match up exactly with the Grammar rules.

Somehow, something, parses the grammars and then goes looking in the Actor
for pragmas. When a pragma in a method matches a rule, then I "think" that a
block is stored in the PEGParser and when that rule is encountered during
the parse, that block is executed.

Sent from: http://forum.world.st/Squeak-Beginners-f107673.html

More information about the Beginners mailing list