Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
adapted gst example script to Paolo Bonzini's regex patch
Browse files Browse the repository at this point in the history
git-svn-id: https://www.iam.unibe.ch/scg/svn_repos/SqueakByExample/Book@12382 54883e8d-cf1d-0410-83d6-f114b9419f37
  • Loading branch information
Oscar Nierstrasz committed Sep 25, 2007
1 parent 6728539 commit 994e3a9
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions examples.st
Expand Up @@ -3,6 +3,7 @@
examples --- extract code examples from Squeak by Example LaTeX source

Assumes you have Gnu Smalltalk with scripting syntax installed (at least v2.95c).
(Applied Paolo Bonzini's patch eliminating need to send #asRegex to strings.)

$Id$
"
Expand Down Expand Up @@ -30,50 +31,40 @@ http://www.squeaksource.com/SBEtesting.html
'.

Object subclass: Chapter [
| name title code titleRegex codeRegex endRegex |
setName: aName [
| title code |
initWithName: aName [
<category: 'initialization'>
| name fileName file codeStream line |
name := aName.
self initRegexes.
self init.
]
setTitle: aString [
<category: 'initialization'>
title := aString.
title := title replacingAllRegex: '\\sq' with: 'Squeak'.
title := title replacingAllRegex: '\\st' with: 'Smalltalk'.
]
initRegexes [
<category: 'initialization'>
titleRegex := '\\chapter\{([^}]*)\}' asRegex.
codeRegex := '^\\begin\{(code|example|script|classdef|methods?|numMethod)\}' asRegex.
endRegex := '^\\end\{' asRegex.
]
init [
<category: 'initialization'>
| fileName file codeStream |
title := '<unknown>'. "default value"
codeStream := WriteStream on: String new.
fileName := name, '/', name, '.tex'.
file := FileStream open: fileName mode: FileStream read.
[ file atEnd ] whileFalse: [ | line |
[ file atEnd ] whileFalse: [
line := file nextLine.
line =~ titleRegex ifMatched: [ :result |
line =~ '\\chapter\{([^}]*)\}' ifMatched: [ :result |
self setTitle: (result at: 1)
] ifNotMatched: [
line =~ codeRegex ifMatched: [ :result |
line =~ '^\\begin\{(code|example|script|classdef|methods?|numMethod)\}'
ifMatched: [ :result |
self getCode: file to: codeStream
] ifNotMatched: [ ]
]
].
code := codeStream contents.
file close.
]
setTitle: aString [
<category: 'initialization'>
title := aString.
title := title replacingAllRegex: '\\sq' with: 'Squeak'.
title := title replacingAllRegex: '\\st' with: 'Smalltalk'.
]
getCode: file to: codeStream [
<category: 'private'>
| line |
line := file nextLine.
[ line ~ endRegex ] whileFalse: [
[ line ~ '^\\end\{' ] whileFalse: [
"comment out --> incantation"
line := line replacingAllRegex: '\s*(-->[^"\r\n]*)' with: ' "%1" '.
"translate listings macros"
Expand Down Expand Up @@ -103,7 +94,7 @@ Chapter class extend [
<category: 'instance creation'>
| ch |
ch := super new.
ch setName: aName.
ch initWithName: aName.
^ ch
]
]
Expand Down

0 comments on commit 994e3a9

Please sign in to comment.