Bash.pm
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
4 # All rights reserved.
5 #
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
9 
10 ##############################################################################
11 # @file DoxyFilter/Bash.pm
12 # @brief Doxygen filter for Bash.
13 #
14 # @ingroup BasisTools
15 ##############################################################################
16 
17 package BASIS::DoxyFilter::Bash;
18 use base BASIS::DoxyFilter;
19 
20 # ============================================================================
21 # public
22 # ============================================================================
23 
24 # ----------------------------------------------------------------------------
25 ## @brief Constructs a CMake Doxygen filter.
26 sub new
27 {
28  my $self = shift;
29  $self->SUPER::new([
30  # if elif fi
31  ['start', qr/^\s*if\s*\[/, undef, 'start'], # discard if's such that
32  # Doxygen comment is
33  # associated with next
34  # block that is supposed
35  # to be in the then branch.
36  # source
37  ['start', qr/^\s*(\.|source)\s+(\"([^\"]|\\\")*[^\\]\"|'([^']|\\')*[^\\]'|[^\s&|]*)(\s*(\|\||&&|#).*)?$/, \&_source, 'start'],
38  # constant
39  ['start', qr/^\s*(\[\s+.*\s+\]\s*(\|\||&&)\s*|if\s+\[\s+.*\s+\]\s*;\s*then\s+)?readonly\s+(\w+)=(\"([^\"]|\\\")*[^\\]\"|'([^']|\\')*[^\\]'|[^#]*)(\s*;\s*fi\s*)?(\s*#.*)?$/, \&_constant, 'start'],
40  # function
41  ['start', qr/^\s*(function\s*(\w+)|(\w+)\s*\(\s*\))\s*{\s*(#.*)?$/, \&_fndef, 'fnbody'],
42  ['start', qr/^\s*(function\s*(\w+)|(\w+)\s*\(\s*\))\s*(#.*)?$/, \&_fndef, 'fndef'],
43  ['fndef', qr/^{\s*(#.*)?$/, undef, 'fnbody'],
44  ['fnbody', qr/^}\s*(#.*)?$/, undef, 'start'],
45  ]);
46 }
47 
48 # ============================================================================
49 # actions
50 # ============================================================================
51 
52 # ----------------------------------------------------------------------------
53 sub _source
54 {
55  my ($self, $unused, $module) = @_;
56  $module =~ s/^\s*[\"']?//;
57  $module =~ s/[\"']?\s*$//;
58  $module =~ s/\/.\//\//g;
59  $module =~ s/^\${_\w+_DIR}\///;
60  $module =~ s/^\$\(exedir\)\///;
61  $module =~ s/^\${?exec_dir}?\///;
62  $self->_append("#include \"$module\"");
63 }
64 
65 # ----------------------------------------------------------------------------
66 sub _constant
67 {
68  my ($self, $unused1, $unused2, $name, $value) = @_;
69  if ($name =~ m/^_/) {
70  $self->_noneblank();
71  } else {
72  $value =~ s/^\s*[\"']?//;
73  $value =~ s/[\"']?\s*$//;
74  if ($value =~ /^[+-]?[0-9]+$/) {
75  $self->_append("int $name = $value;");
76  } elsif ($value =~ /^[+-]?[0-9]+[.][0-9]+$/) {
77  $self->_append("float $name = $value;");
78  } else {
79  $self->_append("string $name = \"$value\";");
80  }
81  }
82 }
83 
84 # ----------------------------------------------------------------------------
85 sub _fndef
86 {
87  my ($self, $unused, $name1, $name2) = @_;
88  my $name = $name1 ? $name1 : $name2;
89  if ($name =~ m/^_/) {
90  $self->_noneblank();
91  } else {
92  my @params = ();
93  foreach my $paramdoc (@{$self->{'params'}}) {
94  push @params, $paramdoc->{'dir'} . " " . $paramdoc->{'name'};
95  }
96  $self->_append("/// \@returns Nothing.") if not $self->{'returndoc'};
97  $self->_append("function $name(" . join(', ', @params) . ");");
98  }
99 }
100 
101 
102 1;