Xtreams comes with a powerful parsing class called PEGParser. It’s impossible to understand without an PEGActor subclass to convert the parsed into a new string. Squeak’s Xtreams package does not have one. There is one actor in Cimcom’s VisualWorks in PEG.WikiGenerator.
I’ve adapted PEG.WikiGeneator into PWWikiActor so now there is an PEGActor subclass for Xtreams PEGParser. This is important, because now there is a complete PEGParser solution in Squeak and Pharo. This means the other grammars that do not have actors (i.e. PEGParser class grammarCSS3, grammarHttpUrl, grammarJSON, grammarJavascript, grammarSmalltalk, grammarXML) now have an example in a working actor on how to proceed.
Well, a working example. I’d be pretty disappointed if people told me my PWWikiActor was the height of coding finesse.
All the above matters, because Xtreams PEGParser is a replacement for SmaCC, PetitParser and an external regex package. I've replaced SmaCC in TinyWiki with PEGParser and PWDocumentActor.
To use it: install Xtreams [1]; load the PW-Xtreams-WikiParsing [2]; and, input some wiki syntax. [3]
Chris
[1]
| oldPref oldAuth|
oldPref := Scanner prefAllowUnderscoreSelectors.
oldAuth := Utilities authorInitialsPerSe.
Scanner prefAllowUnderscoreSelectors: true.
Utilities setAuthorInitials: 'al-loader'.
$_ tokenish ifFalse: [
Character
compile: 'tokenish
"Answer whether the receiver is a valid token-character--letter, digit, or
colon."
^self == $_ or: [self == $: or: [self isLetter or: [self isDigit]]]'
classified: 'testing'.
String initialize ].
(Installer repository: '
http://source.squeak.org/FFI')
install: 'FFI-Pools';
install: 'FFI-Kernel';
install: 'FFI-Tests';
install: 'FFI-Win32';
install: 'FFI-MacOS';
install: 'FFI-Unix'.
(Installer wiresong project: 'al')
addPackage: 'Xtreams-Support';
addPackage: 'Xtreams-CoreTests';
addPackage: 'Xtreams-Core';
addPackage: 'Xtreams-Substreams';
addPackage: 'Xtreams-Terminals';
addPackage: 'Xtreams-Parsing';
addPackage: 'Xtreams-Http';
addPackage: 'Xtreams-Xtras';
addPackage: 'Xtreams-ParsingTests';
addPackage: 'Xtreams-TerminalsTests';
addPackage: 'Xtreams-XtrasTests';
addPackage: 'Xtreams-SubstreamsTests';
addPackage: 'Xtreams-TransformsTests';
addPackage: 'Xtreams-Transforms';
addPackage: 'Xtreams-HttpTests';
install.
[2]
(Installer ss3)
project: 'PEGWiki';
install: 'PW-Xtreams-WikiParsing'.
[3]
myparser := (PEGParser parserBootstrap) parse: 'Grammar' stream: PEGParser grammarWiki reading actor: PEGParserParser new.
input :=
'= Hello World
I would like to *bold* some text
'.
myparser parse: 'Page' stream: input reading actor: PWWikiActor new
'<div><h1>Hello World</h1>
<p>I would like to <b>bold</b> some text</p></div>'