summaryrefslogtreecommitdiff
path: root/pidl/lib/Parse/Pidl
diff options
context:
space:
mode:
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>2019-11-30 15:22:16 +1300
committerAndrew Bartlett <abartlet@samba.org>2019-12-04 05:10:31 +0000
commit0cb2e6ac4c730e504cf40ec328e90874a2267d7e (patch)
tree479b0bca37c9dc7a0966270e7263e758433dca4e /pidl/lib/Parse/Pidl
parent12cccf3447333dfd4f5e437cd57ca5ec68724fdd (diff)
downloadsamba-0cb2e6ac4c730e504cf40ec328e90874a2267d7e.tar.gz
pidl: add a base class for PIDL parsers
There are about 5 object-oriented parsers, all with their own effectively identical but differently spelt versions of pidl(), pidl_hdr(), indent(), and deindent(). With this commit we add a base class that they can all use. The ultimate aim is to be able to add some debugging instrumentation that benefits all[1] the parsers. [1] The parsers (e.g. Samba::ServerNDR) which use global scope rather than objects will not be affected. The versions of the functions in this file follow the most sophisticated versions of the soon-to-be subclasses. For example, the pidl() function avoids spurious whitespace and puts #define at column 0, following the Python parser. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'pidl/lib/Parse/Pidl')
-rw-r--r--pidl/lib/Parse/Pidl/Base.pm46
1 files changed, 46 insertions, 0 deletions
diff --git a/pidl/lib/Parse/Pidl/Base.pm b/pidl/lib/Parse/Pidl/Base.pm
new file mode 100644
index 00000000000..e89a48d2155
--- /dev/null
+++ b/pidl/lib/Parse/Pidl/Base.pm
@@ -0,0 +1,46 @@
+# Superclass for IDL structure generators
+# GPL3
+
+package Parse::Pidl::Base;
+
+use strict;
+use warnings;
+
+use Parse::Pidl qw(fatal warning error);
+
+use vars qw($VERSION);
+$VERSION = '0.01';
+
+sub indent {
+ my $self = shift;
+ $self->{tabs} .= "\t";
+}
+
+sub deindent {
+ my $self = shift;
+ $self->{tabs} = substr($self->{tabs}, 1);
+}
+
+sub pidl {
+ my ($self, $txt) = @_;
+ if ($txt) {
+ if ($txt !~ /^#/) {
+ $self->{res} .= $self->{tabs};
+ }
+ $self->{res} .= $txt;
+ }
+ $self->{res} .= "\n";
+}
+
+
+sub pidl_hdr {
+ my ($self, $txt) = @_;
+ $self->{res_hdr} .= "$txt\n";
+}
+
+
+sub pidl_both {
+ my ($self, $txt) = @_;
+ $self->{res} .= "$txt\n";
+ $self->{res_hdr} .= "$txt\n";
+}