Leeres Fossil Repo

Check-in [2141176eb1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:It finally works
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2141176eb18a4308e9e15fa9c6e46b72b03c8e13
User & Date: nsa 2013-04-08 12:10:00
Context
2013-04-08
13:00
Typos fixing check-in: a4ec1e8a42 user: nsa tags: trunk
12:10
It finally works check-in: 2141176eb1 user: nsa tags: trunk
11:35
Draft implementation in literate style check-in: bd5b945d3b user: nsa tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bootlit.go.

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
		endOfChunkMatcher *regexp.Regexp
		chunkMatcher *regexp.Regexp
		regexpError error
	)

	chunkMatcher, regexpError = regexp.Compile("<<([^>]+)>>=")
	if regexpError != nil {
		panic(regexpError)и
	}
	endOfChunkMatcher, regexpError = regexp.Compile("@")
	if regexpError != nil {
		panic(regexpError)
	}
	
	var document string
	var chunkName string
	var chunks = make(map[string]string)







|

|







73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
		endOfChunkMatcher *regexp.Regexp
		chunkMatcher *regexp.Regexp
		regexpError error
	)

	chunkMatcher, regexpError = regexp.Compile("<<([^>]+)>>=")
	if regexpError != nil {
		panic(regexpError)
	}
	endOfChunkMatcher, regexpError = regexp.Compile("^@")
	if regexpError != nil {
		panic(regexpError)
	}
	
	var document string
	var chunkName string
	var chunks = make(map[string]string)

Changes to lit.go.w.

1
2
3
4
5
6
7
8
9
10
11
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
# Lit, simple tool for language agnostic literate programming

Literate programming is a technique introduced by Dolad Knuth many years ago. 
Nowdays literate programming is almost dead, it's really sad in my opinion. This little application designed to bring
literate programming approach to almost any programming language expirience.

I strongly recomend to read original Knuth paper on Literate Programming (http://www.literateprogramming.com/knuthweb.pdf)

Noweb.py by Jonathan Aquino was inspiration for this humble peace of code.

## Main idea
................................................................................
		panic(err)
	}
	defer f.Close()

	fileBuf := bufio.NewReader(f)
@

Expression "<<([^>]+)>>=" is used to match beginning of chunk, "@" for end of chunk.

<<Define regular expressions>>=
	var (
		endOfChunkMatcher *regexp.Regexp
		chunkMatcher *regexp.Regexp
		regexpError error
	)

	chunkMatcher, regexpError = regexp.Compile("<<([^>]+)>>=")
	if regexpError != nil {
		panic(regexpError)и
	}

	endOfChunkMatcher, regexpError = regexp.Compile("@")
	if regexpError != nil {
		panic(regexpError)
	}
@

After chunk beginning is found we extract his name from submatches and store it in variable `chunkName`, after that any line not matched by any regular expression is added to Map named `chunks` 
with value of `chunkName` as a key.
If line matches with end of chunk expression chunkName is set ot zero value. If line no one expression can match line and `chunkName` variable set to zero value, that line is adding to `document` string variable.

<<Reading and processing lines>>=
	for {
		line, err := fileBuf.ReadString('\n')
		if err == io.EOF {
			processLine(line)
			break
................................................................................
	if err != nil {
		panic(err)
	}
@

Expand body closure defined inside `expandChunks` function takes a body as an argument and match it for links to another chunks. After that it takes every linked chunk name and replaces it with
result of recursive self-invocation with linked chunk body.
If there is no linked chunks closure just returns given body. May be I should check if `expandedChunks` already has expanded body for linked chunk to avoid extra work.


<<Define expand body closure>>=
	var expandBody func(b string) string
	expandBody = func(b string) string {
		var newBody = b
		submatches := chunkMatcher.FindAllStringSubmatch(b, -1)
		if submatches != nil {



|







 







|










|

>
|





|

|







 







|
>







1
2
3
4
5
6
7
8
9
10
11
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# Lit, simple tool for language agnostic literate programming

Literate programming is a technique introduced by Dolad Knuth many years ago. 
Nowadays literate programming is almost dead, it's really sad in my opinion. This little application designed to bring
literate programming approach to almost any programming language expirience.

I strongly recomend to read original Knuth paper on Literate Programming (http://www.literateprogramming.com/knuthweb.pdf)

Noweb.py by Jonathan Aquino was inspiration for this humble peace of code.

## Main idea
................................................................................
		panic(err)
	}
	defer f.Close()

	fileBuf := bufio.NewReader(f)
@

Expression "<<([^>]+)>>=" is used to match beginning of chunk, "^@" for end of chunk.

<<Define regular expressions>>=
	var (
		endOfChunkMatcher *regexp.Regexp
		chunkMatcher *regexp.Regexp
		regexpError error
	)

	chunkMatcher, regexpError = regexp.Compile("<<([^>]+)>>=")
	if regexpError != nil {
		panic(regexpError)
	}

	endOfChunkMatcher, regexpError = regexp.Compile("^@")
	if regexpError != nil {
		panic(regexpError)
	}
@

After chunk beginning is found we extract it's name from submatches and store it in variable `chunkName`, after that any line not matched by any regular expression is added to Map named `chunks` 
with value of `chunkName` as a key.
If line matches with end of chunk expression `chunkName` is set ot zero value. If expressions can match line and `chunkName` variable set to zero value, that line will added to `document` string variable.

<<Reading and processing lines>>=
	for {
		line, err := fileBuf.ReadString('\n')
		if err == io.EOF {
			processLine(line)
			break
................................................................................
	if err != nil {
		panic(err)
	}
@

Expand body closure defined inside `expandChunks` function takes a body as an argument and match it for links to another chunks. After that it takes every linked chunk name and replaces it with
result of recursive self-invocation with linked chunk body.
If there is no linked chunks closure just returns given body. May be I should check if `expandedChunks` already has expanded body for linked chunk to avoid extra work. And definitelly I should 
detect recursion.

<<Define expand body closure>>=
	var expandBody func(b string) string
	expandBody = func(b string) string {
		var newBody = b
		submatches := chunkMatcher.FindAllStringSubmatch(b, -1)
		if submatches != nil {

Deleted test.w.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Hello!

<<test>>=
	begin test
		print "Ok"
	end
@ 

Another one tricky insert
<<test2>>=
	if a > b then
		<<test>>
	else 
		return 42
	end
@

Bye!

<<Здравствуйте>>=
	hello world
@

<<*>>= 
	program dummy
	<<test>>
	<<test2>>
	<<Здравствуйте>>
	end
@

Conclusion
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<