/[svn]/linuxsampler/trunk/scripts/update_grammar.pl
ViewVC logotype

Contents of /linuxsampler/trunk/scripts/update_grammar.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1552 - (show annotations) (download)
Wed Dec 5 22:37:42 2007 UTC (11 years, 10 months ago) by schoenebeck
File MIME type: text/plain
File size: 4006 byte(s)
* seems mingw has problems with accessing static variables from another
  static (noinst) libtool library, at least it prevented it from producing
  the liblinuxsampler.dll and just created a static archive
* fixed Perl script which automatically updates our LSCP spec source file
  (lscp.xml), it didn't remove multi line C++ code

1 #!/usr/bin/perl -w
2
3 # Updates grammer in lscp.xml
4 #
5 # Updates the "Command Syntax" section of Documentation/lscp.xml with current
6 # LSCP grammar definition from network/lscp.y which is the yacc input file
7 # used to automatically generate LinuxSampler's LSCP parser C++ source file
8 # (network/lscpparser.cpp).
9 #
10 # Usage: update_grammar.pl [-v]
11 #
12 # -v verbose output
13
14 my $YACC_FILE = "../src/network/lscp.y";
15 my $XML2RFC_FILE = "../Documentation/lscp.xml";
16 my $ANCHOR_TOKEN_BEGIN = "GRAMMAR_BNF_BEGIN";
17 my $ANCHOR_TOKEN_END = "GRAMMAR_BNF_END";
18
19 my $verbose = 0;
20 if (defined($ARGV[0]) and $ARGV[0] eq "-v") {
21 $verbose = 1;
22 }
23
24 open(IN, $YACC_FILE) || die "Can't open yacc input file for creating xml2rfc file.";
25 open(OUT, $XML2RFC_FILE) || die "Can't read xml2rfc file.";
26
27
28 my @yacc_in = <IN>;
29 my $in_marker_begin = -1;
30 my $in_marker_end = -1;
31 my $i = 0;
32
33 # scan the yacc input file for the marker lines
34 if ($verbose) { print "Scanning file \"${YACC_FILE}\" ...\n"; }
35 foreach $line (@yacc_in) {
36 if ($line =~ /$ANCHOR_TOKEN_BEGIN/o) { $in_marker_begin = $i; }
37 elsif ($line =~ /$ANCHOR_TOKEN_END/o) { $in_marker_end = $i; }
38 $i++;
39 }
40 if ($in_marker_begin < 0) {
41 die "Did not find ${ANCHOR_TOKEN_BEGIN} token in ${YACC_FILE}, exiting!";
42 }
43 if ($in_marker_end < 0) {
44 die "Did not find ${ANCHOR_TOKEN_END} token in ${YACC_FILE}, exiting!";
45 }
46 if ($in_marker_end <= $in_marker_begin) {
47 die "Marker line ${ANCHOR_TOKEN_END} appears before marker line ${ANCHOR_TOKEN_BEGIN}, exiting!";
48 }
49 if ($verbose) { print "Ok, found ${ANCHOR_TOKEN_BEGIN} in line ${in_marker_begin} and ${ANCHOR_TOKEN_END} in line ${in_marker_end}.\n"; }
50 # delete everything except the grammar lines
51 splice(@yacc_in, $in_marker_end, $#yacc_in - $in_marker_end);
52 splice(@yacc_in, 0, $in_marker_begin + 1);
53
54 # remove C++ code
55 $scalar_yacc_in = join("", @yacc_in);
56 $scalar_yacc_in =~ s/'\{'|'\}'//mg;
57 $scalar_yacc_in =~ s/\{(\d|[a-z]|[A-Z]|\#|;|:|<|>|\(|\)|\$|\[|\]|=|\+|-|\"|'|_|\\|\/|\.|,|\s|\n|\r)*\}//mgix;
58 # remove surving '}' character ;-)
59 #$scalar_yacc_in =~ s/\}/\n/g;
60
61 # convert scalar, long string into a line array
62 @yacc_in = split(/\n/, $scalar_yacc_in);
63
64 # do the XML transformation
65 $i = 0;
66 foreach $line (@yacc_in) {
67 $_ = $line . "\n";
68 # remove C++ code
69 s/\{\p{IsASCII}*\}//g;
70 s/\/\/\p{IsASCII}*$/\r\n/g;
71 s/\{//g;
72 s/\}//g;
73 # place XML tags
74 s!^(\w+)\s*:\s*(\p{IsASCII}*)!<t>$1 =\r\n\t<list>\r\n\t\t<t>$2!;
75 s!^\s+\|\s*(\p{IsASCII}*)!\t\t</t>\r\n\t\t<t>/ $1!;
76 s!^\s*;(\p{IsASCII}*)!\t\t</t>\r\n\t</list>\r\n</t>!;
77 #s/:/<list>/g;
78 # remove space(s) at the end of each line
79 s/\s+$/\r\n/g;
80 $yacc_in[$i] = $_;
81 $i++;
82 }
83
84 my @xml_in = <OUT>;
85 my $out_marker_begin = -1;
86 my $out_marker_end = -1;
87 $i = 0;
88
89 # scan the xml2rfc file for the marker lines
90 if ($verbose) { print "Scanning file \"${XML2RFC_FILE}\" ...\n"; }
91 foreach $line (@xml_in) {
92 if ($line =~ /$ANCHOR_TOKEN_BEGIN/o) { $out_marker_begin = $i; }
93 elsif ($line =~ /$ANCHOR_TOKEN_END/o) { $out_marker_end = $i; }
94 $i++;
95 }
96 if ($out_marker_begin < 0) {
97 die "Did not find ${ANCHOR_TOKEN_BEGIN} token in ${XML2RFC_FILE}, exiting!";
98 }
99 if ($out_marker_end < 0) {
100 die "Did not find ${ANCHOR_TOKEN_END} token in ${XML2RFC_FILE}, exiting!";
101 }
102 if ($out_marker_end <= $out_marker_begin) {
103 die "Marker line ${ANCHOR_TOKEN_END} appears before marker line ${ANCHOR_TOKEN_BEGIN}, exiting!";
104 }
105 if ($verbose) { print "Ok, found ${ANCHOR_TOKEN_BEGIN} in line ${out_marker_begin} and ${ANCHOR_TOKEN_END} in line ${out_marker_end}.\n"; }
106 close(OUT); # we reopen in write (clobber) mode
107
108 # finally replace the area in the output xml file with the new grammar
109 splice(@xml_in, $out_marker_begin + 1, $out_marker_end - $out_marker_begin - 1, @yacc_in);
110 open(OUT, "+>", $XML2RFC_FILE) || die "Can't open xml2rfc file for output";
111 print OUT @xml_in;
112 close(OUT);
113 close(IN);
114
115 if ($verbose) { print "Done.\n"; }
116
117 exit(0);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC