[squeak-dev] Xtreams up to date
mkobetic at gmail.com
mkobetic at gmail.com
Mon Jan 24 16:40:04 UTC 2011
"Hannes Hirzel"<hannes.hirzel at gmail.com> wrote:
> I worked through it and understood it. I adapted the class names so
> that it runs in the current Squeak 4.2 out of the box. In addition I
> edited it slightly. I think it could be added as to the PEGParser
> class. Maybe somebody else like to check it in addition ....
Yes, wrote it with the intent to eventually turn it into documentation for the Parsing package. On VW side we keep these in package comments, that's the most obvious location for it IMO. I'm not convinced that using a class comment on Squeak/Pharo side is a good choice. I would have difficulty myself to pick the class for it, so the chances that a new user will find it are even lower. I'm intrigued by the help facilities that were mentioned on Pharo side quite a bit recently. Is that something people hope to turn into the primary resource for these things ? Sounds like it would be quite easy to package it as that. The package comment are already written using the google wiki syntax, so that they can be directly posted to the google project site. So the help facilities allowing wiki syntax sound particularly attractive. Is this something that could work on Squeak side too, or do we need to do something different there ? In the meantime I intend to at least keep the google project pages up to date.
> Additional example: Wiki text parsing
>
> In the previous mail you mentioned that you'll add the fileout of the class
>
> PEGWikiGenerator
Ah, I got caught up in the arithmetic example and forgot the attachments. They are attached now. Sorry about that.
Thanks for the edited version of the example. I'll work on it some more and turn it into a doc page on the site. If we figure out how to package it in Squeak and Pharo so that people can find it easily, I'd be happy to add all the documentation we have on the site.
Cheers,
Martin
-------------- next part --------------
PEGActor subclass: #PEGWikiGenerator
instanceVariableNames: ''
classVariableNames: 'Anchor Break Division Heading1 Heading2 Heading3 Heading4 Href ListItem OrderedList Paragraph Preformatted Span Style Table TableBody TableData TableHead TableHeading TableRow UnorderedList '
poolDictionaries: ''
category: ''!
PEGWikiGenerator class
instanceVariableNames: ''!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
!PEGWikiGenerator class methodsFor: 'utilities' stamp: ' 22/1/11 17:38'!
docsCSS
^'<style type="text/css">
table {border-collapse: separate;}
th {border: 1px solid black; padding: 3px; text-align: center;}
td {border: 1px solid black; padding: 3px; text-align: left;}
</style>'!
generateHtmlDocsInto: directory
"Convert package comments into a set of web pages and put the files into @directory.
"
"
self generateHtmlDocsInto: Kernel.ObjectMemory imageDirectory
"
((Registry bundleNamed: 'XtreamsDevelopment') leafItems
reject: [:p | '*-Tests' match: p name])
collect:
[:p |
| body file |
body := self process: p comment reading.
file := directory / (p name , '.html').
file exists ifTrue: [file delete].
(file writing encoding: #ascii)
write: '<html>';
cr;
write: '<head>';
cr;
write: '<title>';
write: p name;
write: '</title>';
cr;
write: self docsCSS;
cr;
write: '</head>';
cr;
write: '<body>';
cr;
write: body printString;
cr;
write: '</body>';
cr;
write: '</html>';
close]!
generateWikiDocsInto: directory
"Save package comments into a set of wiki pages for the project site wiki. Put the files into @directory.
"
"
self generateWikiDocsInto: Kernel.ObjectMemory imageDirectory
"
"
self generateWikiDocsInto: (OS.Filename fromComponents: ('$(HOME)/st/xtreams/wiki' tokensBasedOn: $/)) asFilename
"
((Registry bundleNamed: 'XtreamsDevelopment') leafItems
reject:
[:p |
#('*-Tests' '*-Xperiments' '*-Support')
anySatisfy: [:pattern | pattern match: p name]])
collect:
[:p |
| file |
file := p name
copyFrom: 'Xtreams-' size + 1
to: p name size.
file := directory / (file , '.wiki').
file exists ifTrue: [file delete].
(file writing encoding: #ascii)
write: p comment;
close]!
process: input
"Convert input into an xhtml XML document.
"
" input <ReadStream> text with wiki markup
^ <XML.Element>
"
"
self process: 'Single paragraph with *bold* and _italic_ text and a [link]' reading
"
"
| package div file |
package := Store.Registry packageNamed: 'Xtreams-Core'.
div := self process: package comment reading.
file := '/dev/shm/', package name, '.html'.
file asFilename writing write: '<html><body>'; write: div printString; write: '</body></html>'; close.
ExternalWebBrowser open: 'file://', file
"
^self parser
parse: 'Page'
stream: input
actor: self new! !
!PEGWikiGenerator class methodsFor: 'accessing' stamp: ' 22/1/11 17:38'!
parser
^Parser parserPEG
parse: 'Grammar'
stream: Parser grammarWiki reading
actor: ParserParser new! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
PEGWikiGenerator comment:
'This actor is used to convert text with wiki mark-up into an XML document with xhtml tags.
Shared Variables
Anchor <NodeTag>
Break <NodeTag>
Division <NodeTag>
Heading1 <NodeTag>
Heading2 <NodeTag>
Heading3 <NodeTag>
Heading4 <NodeTag>
Href <NodeTag>
ListItem <NodeTag>
OrderedList <NodeTag>
Paragraph <NodeTag>
Preformatted <NodeTag>
Span <NodeTag>
Style <NodeTag>
Table <NodeTag>
TableBody <NodeTag>
TableData <NodeTag>
TableHead <NodeTag>
TableHeading <NodeTag>
TableRow <NodeTag>
UnorderedList <NodeTag>
'!
!PEGWikiGenerator methodsFor: 'Lexical' stamp: ' 22/1/11 17:38'!
Bold: flow
<action: 'Bold' arguments: #(2)>
^Element
tag: Span
attributes:
(Array with: (Attribute name: Style value: 'font-weight: bold'))
elements: flow!
Character: character
<action: 'Character'>
^Text text: (String with: character)!
Escape: escape
<action: 'Escape'>
^escape first!
Italic: flow
<action: 'Italic' arguments: #(2)>
^Element
tag: Span
attributes:
(Array with: (Attribute name: Style value: 'font-style: italic'))
elements: flow!
LineCharacter: character
<action: 'LineCharacter'>
^Text text: (String with: character)!
Link: address
<action: 'LinkShort' arguments: #(2)>
^Element
tag: Anchor
attributes:
(Array
with:
(Attribute
name: Href
value: address , '.html'))
elements: (Array with: (Text text: address))!
Link: flow address: address
<action: 'LinkFull' arguments: #(2 3)>
^Element
tag: Anchor
attributes: (Array with: (Attribute name: Href value: address))
elements: flow!
Underline: flow
<action: 'Underline' arguments: #(2)>
^Element
tag: Span
attributes:
(Array with: (Attribute name: Style value: 'text-decoration: underline'))
elements: flow! !
!PEGWikiGenerator methodsFor: 'Structural' stamp: ' 22/1/11 17:38'!
Empty
<action: 'Empty' arguments: #()>
^Text text: '' "^Element tag: break"!
Heading1: flow
<action: 'Heading1' arguments: #(3)>
^Element tag: Heading1 elements: flow!
Heading2: flow
<action: 'Heading2' arguments: #(3)>
^Element tag: Heading2 elements: flow!
Heading3: flow
<action: 'Heading3' arguments: #(3)>
^Element tag: Heading3 elements: flow!
Heading4: flow
<action: 'Heading4' arguments: #(3)>
^Element tag: Heading4 elements: flow!
ListItem: bullets flow: flow
<action: 'Bullet1' arguments: #(2 3)>
<action: 'Bullet2' arguments: #(2 3)>
<action: 'Bullet3' arguments: #(2 3)>
<action: 'Hash1' arguments: #(2 3)>
<action: 'Hash2' arguments: #(2 3)>
<action: 'Hash3' arguments: #(2 3)>
^Element tag: ListItem elements: flow!
OrderedList: bullets
<action: 'OrderedList'>
^Element tag: OrderedList elements: bullets!
OrderedListN: bullets
<action: 'OrderedList2'>
<action: 'OrderedList3'>
^Element
tag: ListItem
elements: (Array with: (Element tag: OrderedList elements: bullets))!
Page: lines
<action: 'Page'>
^Element tag: Division elements: lines!
Paragraph: flow
<action: 'Paragraph'>
^Element tag: Paragraph elements: flow!
Preformatted: text
<action: 'Preformatted' arguments: #(2)>
<action: 'Code' arguments: #(2)>
^Element
tag: Preformatted
elements: (Array with: (Text text: text))!
Table: header rows: rows
<action: 'Table' arguments: #(1 2)>
^Element
tag: Table
elements:
(Array
with:
(Element
tag: TableHead
elements: (Array with: header))
with: (Element tag: TableBody elements: rows))!
TableCell: flow
<action: 'Cell'>
^Element tag: TableData elements: flow!
TableHeadingCell: flow
<action: 'HeadingCell'>
^Element tag: TableHeading elements: flow!
TableRow: cells
<action: 'TableRow' arguments: #(3)>
<action: 'HeadingRow' arguments: #(3)>
^Element tag: TableRow elements: cells!
UnorderedList: bullets
<action: 'UnorderedList'>
^Element tag: UnorderedList elements: bullets!
UnorderedListN: bullets
<action: 'UnorderedList2'>
<action: 'UnorderedList3'>
^Element
tag: ListItem
elements: (Array with: (Element tag: UnorderedList elements: bullets))! !
-------------- next part --------------
PEG.WikiGenerator defineSharedVariable: #Anchor
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''a'''!
PEG.WikiGenerator defineSharedVariable: #Break
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''br'''!
PEG.WikiGenerator defineSharedVariable: #Division
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''div'''!
PEG.WikiGenerator defineSharedVariable: #Heading1
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''h1'''!
PEG.WikiGenerator defineSharedVariable: #Heading2
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''h2'''!
PEG.WikiGenerator defineSharedVariable: #Heading3
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''h3'''!
PEG.WikiGenerator defineSharedVariable: #Heading4
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''h4'''!
PEG.WikiGenerator defineSharedVariable: #Href
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''href'''!
PEG.WikiGenerator defineSharedVariable: #ListItem
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''li'''!
PEG.WikiGenerator defineSharedVariable: #OrderedList
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''ol'''!
PEG.WikiGenerator defineSharedVariable: #Paragraph
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''p'''!
PEG.WikiGenerator defineSharedVariable: #Preformatted
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''pre'''!
PEG.WikiGenerator defineSharedVariable: #Span
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''span'''!
PEG.WikiGenerator defineSharedVariable: #Style
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''style'''!
PEG.WikiGenerator defineSharedVariable: #Table
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''table'''!
PEG.WikiGenerator defineSharedVariable: #TableBody
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''tableBody'''!
PEG.WikiGenerator defineSharedVariable: #TableData
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''td'''!
PEG.WikiGenerator defineSharedVariable: #TableHead
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''tableHead'''!
PEG.WikiGenerator defineSharedVariable: #TableHeading
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''th'''!
PEG.WikiGenerator defineSharedVariable: #TableRow
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''tr'''!
PEG.WikiGenerator defineSharedVariable: #UnorderedList
private: false
constant: false
category: 'xhtml tags'
initializer: 'XML.NodeTag new qualifier: '''' ns: ''http://www.w3.org/1999/xhtml'' type: ''ul'''!
More information about the Squeak-dev
mailing list
|