Leeres Fossil Repo

Check-in [674883d4c3]
Login

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

Overview
Comment:Keep code option
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:674883d4c37c0e3b11731013bec79ede4bbec504
User & Date: nsa 2013-06-14 11:06:05
Context
2013-06-14
11:06
Keep code option Leaf check-in: 674883d4c3 user: nsa tags: trunk
2013-04-10
09:24
Added build script check-in: bf58c353ac user: nsa tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to build.go.

6
7
8
9
10
11
12
13


14

15
16


17

)


func main() {
	_ = os.Mkdir("build", os.ModePerm)
	
	tangle := exec.Command("go", "run", "bootlit.go", "--src-out", "build/lit.go", "lit.go.w")
	tangle.Start()




	build := exec.Command("go", "build", "build/lit.go")
	build.Start()


}








|
>
>
|
>

|
>
>
|
>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
)


func main() {
	_ = os.Mkdir("build", os.ModePerm)
	
	tangle := exec.Command("go", "run", "bootlit.go", "--src-out", "build/lit.go", "lit.go.w")
	err := tangle.Start()
	if err != nil {
		panic(err)
	}

	build := exec.Command("go", "build", "build/lit.go")
	err = build.Start()
	if err != nil {
		panic(err)
	}
}

Changes to lit.go.w.

26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
	"strings"
@

# Run flow
## Parsing command line parameters

Right after start application will try to parse command line parameters. If some vital data is not defined application will show usage and exit. 
There is 4 overall parameters: 
* --src-out: File name for code output ("tangle" output)
* --doc-out: File name for document output ("weave" output)
* --default-chunk: Default chunk name. Chunk with this name will consider holding main program code. By default it's name is "*"

* First parameter after all options will be used as name of file to parse

As I mention above, we using `flag` package to parse command line. For every command line argument there is variable defined. Default values for src-out and doc-out parameters are empty strings.
In Go empty string is "zero value" for string, so we can catch situation when user omit one or another parameter. Default value for default-chunk is "*".

<<Command line parsing>>=
	var sourceFile string
	var docFile string
	var parsingFile string
	var defaultChunk string


	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of lit: lit [options] file-to-parse.w\n")
		flag.PrintDefaults()
	}

	flag.StringVar(&defaultChunk, "default-chunk", "*", "Default program chunk")
	flag.StringVar(&sourceFile, "src-out", "", "File to write source code")
	flag.StringVar(&docFile, "doc-out", "", "File to write document")

	flag.Parse()
@


# Check command line options validity
If there is no file to parse we can't do anything except show usage. Another case is when both src-out and doc-out is missing. In this situation application will show usage too, because
it can't do anything useful with given file. 

<<Parameters check>>=
	if len(flag.Args()) > 0 {
		parsingFile = flag.Arg(0)
	}

	if parsingFile == "" || (sourceFile == "" && docFile == "") {
		flag.Usage()
		os.Exit(0)
	}
@

But if /only one/ of they is missing application can dump source code or documentation without dumping another part.
................................................................................
		}
	}
@

As a result of execution `parseFile` function returns `document` string and `chunks` map. 

<<File parsing definition>>=
func parseFile(fileName string) (map[string]string, string) {

	<<Open file and buf reader>>

	<<Define regular expressions>>
	
	var document string
	var chunkName string
................................................................................
}
@

To simplify processing of every line of code defined closure `processLine`. This closure decides where current processing line will go: to the chunk body or documentation.

<<Proc line closure>>=
	var processLine = func(line string) {
		if chunkName != "" {
			chunks[chunkName] += line
		} else {
			document += line
		}
	}
@

................................................................................
<<Used packages>>
)

func main() {
	<<Command line parsing>>
	<<Parameters check>>

	chunks, document := parseFile(parsingFile)
	chunks = expandChunks(chunks)

	<<Processing command line>>
}

<<File parsing definition>>
<<Expanding chunks definition>>







|



>










>









>












|







 







|







 







|







 







|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
...
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
	"strings"
@

# Run flow
## Parsing command line parameters

Right after start application will try to parse command line parameters. If some vital data is not defined application will show usage and exit. 
There is 5 overall parameters: 
* --src-out: File name for code output ("tangle" output)
* --doc-out: File name for document output ("weave" output)
* --default-chunk: Default chunk name. Chunk with this name will consider holding main program code. By default it's name is "*"
* --keep-code: lit will include source code chunks in generated documents
* First parameter after all options will be used as name of file to parse

As I mention above, we using `flag` package to parse command line. For every command line argument there is variable defined. Default values for src-out and doc-out parameters are empty strings.
In Go empty string is "zero value" for string, so we can catch situation when user omit one or another parameter. Default value for default-chunk is "*".

<<Command line parsing>>=
	var sourceFile string
	var docFile string
	var parsingFile string
	var defaultChunk string
	var keepSourceCode bool

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of lit: lit [options] file-to-parse.w\n")
		flag.PrintDefaults()
	}

	flag.StringVar(&defaultChunk, "default-chunk", "*", "Default program chunk")
	flag.StringVar(&sourceFile, "src-out", "", "File to write source code")
	flag.StringVar(&docFile, "doc-out", "", "File to write document")
	flag.BoolVar(&keepSourceCode, "keep-code", false, "Should include source code in documents")
	flag.Parse()
@


# Check command line options validity
If there is no file to parse we can't do anything except show usage. Another case is when both src-out and doc-out is missing. In this situation application will show usage too, because
it can't do anything useful with given file. 

<<Parameters check>>=
	if len(flag.Args()) > 0 {
		parsingFile = flag.Arg(0)
	}
 
	if parsingFile == "" || (sourceFile == "" && docFile == "") {
		flag.Usage()
		os.Exit(0)
	}
@

But if /only one/ of they is missing application can dump source code or documentation without dumping another part.
................................................................................
		}
	}
@

As a result of execution `parseFile` function returns `document` string and `chunks` map. 

<<File parsing definition>>=
func parseFile(fileName string, keepSourceCode bool) (map[string]string, string) {

	<<Open file and buf reader>>

	<<Define regular expressions>>
	
	var document string
	var chunkName string
................................................................................
}
@

To simplify processing of every line of code defined closure `processLine`. This closure decides where current processing line will go: to the chunk body or documentation.

<<Proc line closure>>=
	var processLine = func(line string) {
		if chunkName != "" && keepSourceCode == false {
			chunks[chunkName] += line
		} else {
			document += line
		}
	}
@

................................................................................
<<Used packages>>
)

func main() {
	<<Command line parsing>>
	<<Parameters check>>

	chunks, document := parseFile(parsingFile, keepSourceCode)
	chunks = expandChunks(chunks)

	<<Processing command line>>
}

<<File parsing definition>>
<<Expanding chunks definition>>