File: regenerate_parsers.tcl

package info (click to toggle)
tcllib 1.16-dfsg-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 50,040 kB
  • ctags: 18,603
  • sloc: tcl: 156,708; ansic: 14,098; sh: 10,783; xml: 1,766; yacc: 1,114; pascal: 551; makefile: 89; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (74 lines) | stat: -rw-r--r-- 2,246 bytes parent folder | download
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
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
#!/usr/bin/env tclsh
# -*- tcl -*-

package require Tcl 8.5

set     self      [file normalize [info script]]
set     selfdir   [file dirname $self]
set     module    [file dirname $selfdir]
lappend auto_path [file dirname $module]

package require pt::pgen
package require fileutil

set specification     [file join $module tests/data/ok/peg_peg/3_peg_itself]
set new_parser_tcl    [file join $module pt_parse_peg_tcl.tcl-NEW]
set new_parser_critcl [file join $module pt_parse_peg_c.tcl-NEW]
set me                $tcl_platform(user)
set name              PEG
set class             pt::parse::peg

# Note: Chicken'n'Egg here. The pt_pgen parser generator needs a PEG
#       parser to read the grammar definition from which to generate
#       a PEG parser.

# This problem was initially solved by using the grammar interpreter
# package pt::peg::interp together with a definition of the PEG
# grammar kept in the container package pt::peg::container::peg. That
# definition was created through manual conversion of the PE grammar.

# And we avoid getting back into the problem by writing the generated
# parser into a different file instead of overwriting the
# definition/package just used by the parser generator.

# The user has to, well, is asked to, review the results before
# replacing the working system with the newly-made code. And in case
# the user still ran into the problem, just go to the implementation
# of package pt::peg::from::peg and switch there from use of
# pt::parse::peg to the interpreter/container combination. The code
# for bootstrapping is still present, just commented out.

puts "Reading spec..."
set spec [fileutil::cat $specification]

# 1.
# Generate snit-based Tcl parser for the PEG grammar.

puts Tcl
fileutil::writeFile $new_parser_tcl \
    [pt::pgen \
	 peg  $spec \
	 snit \
	 -name  $name \
	 -user  $me \
	 -file  [file tail $specification] \
	 -class ${class}_tcl \
	 -package ${class}_tcl \
	]

# 2.
# Generate critcl-based C parser for the PEG grammar.

puts CriTcl
fileutil::writeFile $new_parser_critcl \
    [pt::pgen \
	 peg  $spec \
	 critcl \
	 -name    $name \
	 -user    $me \
	 -file    [file tail $specification] \
	 -class   $class \
	 -package [string map {:: _} $class]_c \
	]

exit