cvs: php-lang / syntax_spec_scanner.pl

From: Date: Tue, 21 Nov 2000 22:47:37 +0000
Subject: cvs: php-lang / syntax_spec_scanner.pl
Groups: php.lang 
Request: Send a blank email to php-lang+get-77@lists.php.net to get a copy of this message
sas Tue Nov 21 14:47:37 2000 EDT Added files: /php-lang syntax_spec_scanner.pl Log: A script which scans the syntax as found in c-like-syntax-spec and outputs XML. Index: php-lang/syntax_spec_scanner.pl +++ php-lang/syntax_spec_scanner.pl #! /usr/bin/perl # # This script converts the syntax to XML # # $Id: syntax_spec_scanner.pl,v 1.1 2000/11/21 22:47:36 sas Exp $ use strict; my %nts; my $nt; my @nt_list; my $lineno = 0; my $flags; my $one_of; my $match; while (<>) { chop; $lineno++; # Skip empty and comment lines next if (/^(\s*|#.*)$/); if (/^([-a-z]+):(.*)/) { $nt = $1; $flags = $2; $one_of = 0; $match = 0; if ($flags =~ /one of/) { $one_of = 1; } elsif ($flags =~ /match/) { $match = 1; } # We want to keep the order. keys %nts does not # maintain the order.. push @nt_list, $nt; } elsif (/^\s{4}(.+)/) { if ($one_of) { foreach my $e (split(" ", $1)) { push @{$nts{$nt}}, $e; } } elsif ($match) { push @{$nts{$nt}}, "MATCH$1"; } else { push @{$nts{$nt}}, $1; } } else { print "Unrecognized line $lineno\n"; } } foreach $nt (@nt_list) { print "<defsym>$nt\n"; foreach my $opt (@{$nts{$nt}}) { print " <def>"; foreach my $t (split(" ", $opt)) { if ($t =~ /^'(.*)'$/) { print "<literal>$1</literal>"; } elsif ($t =~ /^\[(.*)\]$/) { print "<opt-non-term>$1</opt-non-term>"; } elsif ($t =~ /^MATCH(.*)$/) { print "<match>$1</match>"; } else { print "<non-terminal>$t</non-terminal>"; } } print "</def>\n"; } print "</defsym>\n"; }

« previous php.lang (#77) next »