23 public function __construct()
26 $this->lang_name =
"";
27 # Language configuration hashtable.
28 $this->indent_depth = 8;
30 $this->config = array();
33 $this->validkeys = array();
35 $this->indent = array();
36 $this->unindent = array();
37 $this->blockcommenton = array();
38 $this->blockcommentoff = array();
39 $this->linecommenton = array();
40 $this->preprocessors = array();
43 $this->zones = array();
45 # Hashtable of keywords - maps from keyword to colour.
46 $this->keywords = array();
48 # Used for conversion from keyword -> regexp.
49 $this->keypats = array();
51 # Which colours to use for each 'level'.
52 $this->colours = array(
"blue",
"purple",
"gray",
"brown",
"blue",
"purple",
"gray",
"brown");
53 $this->quotecolour =
"blue";
54 $this->blockcommentcolour =
"green";
55 $this->linecommentcolour =
"green";
56 $this->stringchars = array();
57 $this->delimiters = array();
58 $this->escchar =
"\\";
60 # Caches for the harvesters.
62 $this->stringcache =
"";
70 public function parse_file(
$file)
72 print "This method should not be called from here, but from an extending configuration class.<br>";
75 public function to_perl($stub, $tofile = 1)
77 $this->used_categories = $this->_get_categories();
81###############################
83# Beautifier Perl HFile
86###############################
94 bless \$self, \$class;
98 $this->_dump_var($this->nocase,
" \$self->{nocase} ");
99 $this->_dump_var($this->notrim,
" \$self->{notrim} ");
100 $this->_dump_var($this->perl,
" \$self->{perl} ");
101 $this->_dump_perl_array($this->indent,
" \$self->{indent} ");
102 $this->_dump_perl_array($this->unindent,
" \$self->{unindent} ");
103 $this->_dump_perl_array($this->stringchars,
" \$self->{stringchars} ");
104 $this->_dump_perl_array($this->delimiters,
" \$self->{delimiters} ");
105 $this->_dump_var($this->escchar,
" \$self->{escchar} ");
106 $this->_dump_perl_array($this->linecommenton,
" \$self->{linecommenton} ");
107 $this->_dump_perl_array($this->blockcommenton,
" \$self->{blockcommenton} ");
108 $this->_dump_perl_array($this->blockcommentoff,
" \$self->{blockcommentoff}");
109 $this->_dump_perl_hash($this->keywords,
" \$self->{keywords} ");
110 $this->_dump_perl_linkscripts();
117 $this->_dump_perl_defaultscripts();
121 public function to_php($stub, $tofile = 1)
123 $this->used_categories = $this->_get_categories();
130 print "require_once('psh.php');\n";
131 print "class psh_$stub extends psh\n{\n";
132 print "function psh_$stub(){\n";
133 print "\$this->psh();\n";
134 print "######################################\n";
135 print "# Beautifier Highlighting Configuration File \n";
136 print "# $this->lang_name\n";
137 print "######################################\n";
139 $this->_dump_var($this->nocase,
"\$this->nocase ");
140 $this->_dump_var($this->notrim,
"\$this->notrim ");
141 $this->_dump_var($this->perl,
"\$this->perl ");
142 print "\n# Colours\n\n";
143 $this->_dump_colours();
144 $this->_dump_var(
"blue",
"\$this->quotecolour ");
145 $this->_dump_var(
"green",
"\$this->blockcommentcolour");
146 $this->_dump_var(
"green",
"\$this->linecommentcolour ");
147 print "\n# Indent Strings\n\n";
148 $this->_dump_array($this->indent,
"\$this->indent ");
149 $this->_dump_array($this->unindent,
"\$this->unindent ");
150 print "\n# String characters and delimiters\n\n";
151 $this->_dump_array($this->stringchars,
"\$this->stringchars ");
152 $this->_dump_array($this->delimiters,
"\$this->delimiters ");
153 $this->_dump_var($this->escchar,
"\$this->escchar ");
154 print "\n# Comment settings\n\n";
155 $this->_dump_array($this->linecommenton,
"\$this->linecommenton ");
156 $this->_dump_var($this->blockcommenton,
"\$this->blockcommenton ");
157 $this->_dump_var($this->blockcommentoff,
"\$this->blockcommentoff ");
158 print "\n# Keywords (keyword mapping to colour number)\n\n";
159 $this->_dump_hash($this->keywords,
"\$this->keywords ");
160 print "\n# Special extensions\n";
161 $this->_dump_linkscripts();
170 public function _get_categories()
174 foreach (array_keys($this->keywords) as $k) {
175 $cat = $this->keywords[$k];
176 if (!in_array($cat, $usedcats)) {
177 array_push($usedcats, $cat);
183 public function _dump_linkscripts()
186# Each category can specify a PHP function that takes in the function name, and returns a string
187# to put in its place. This can be used to generate links, images, etc.\n\n";
191 foreach ($this->used_categories as $c) {
192 $linkhash{$c} =
"donothing";
195 $this->_dump_hash($linkhash,
"\$this->linkscripts ");
197 print "\n# DoNothing link function\n\n";
198 print "function donothing(\$keywordin)\n{\n return \$keywordin;\n}\n";
201 public function _dump_perl_linkscripts()
204# Each category can specify a Perl function that takes in the function name, and returns a string
205# to put in its place. This can be used to generate links, images, etc.\n\n";
208 foreach ($this->used_categories as $c) {
209 $linkhash{$c} =
"donothing";
212 $this->_dump_perl_hash($linkhash,
"\$self->{linkscripts} ");
215 public function _dump_perl_defaultscripts()
217 print "\n# DoNothing link function\n\n";
218 print "sub donothing\n{\nmy ( \$self ) = @_;\nreturn;\n}\n";
221 public function _dump_colours()
224 foreach ($this->used_categories as $c) {
225 array_push($usedcols, $this->colours[$c-1]);
227 $this->_dump_array($usedcols,
"\$this->colours ");
230 public function _dump_var($variable,
$name)
232 print $name .
" = \"" . addslashes($variable) .
"\";\n";
235 public function _dump_array($array,
$name)
239 foreach ($array as $a) {
245 print "\"" . addslashes($a) .
"\"";
250 public function _dump_perl_array($array,
$name)
254 foreach ($array as $a) {
260 print "\"" . addslashes($a) .
"\"";
265 public function _dump_hash($hash,
$name)
269 foreach (array_keys($hash) as $k) {
275 print "\n \"" . addslashes($k) .
"\"";
276 print " => \"" . addslashes($hash[$k]) .
"\"";
281 public function _dump_perl_hash($hash,
$name)
285 foreach (array_keys($hash) as $k) {
291 print "\n \"" . addslashes($k) .
"\"";
292 print " => \"" . addslashes($hash[$k]) .
"\"";
An exception for terminatinating execution or to throw for unit testing.
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file