| 1 | # -*- Mode: Perl -*- | ||||||||||
| 2 | |||||||||||
| 3 | ############################################################### | ||||||||||
| 4 | # | ||||||||||
| 5 | # File: Getopt::Gen::Parser.yp | ||||||||||
| 6 | # Author: Bryan Jurish <Gen/cmdline_pod.pm> | ||||||||||
| 7 | # | ||||||||||
| 8 | # Description: Yapp parser specification for | ||||||||||
| 9 | # DWDS query strings | ||||||||||
| 10 | # | ||||||||||
| 11 | ############################################################### | ||||||||||
| 12 | |||||||||||
| 13 | ############################################################### | ||||||||||
| 14 | # Header section | ||||||||||
| 15 | ############################################################### | ||||||||||
| 16 | %{ | ||||||||||
| 17 | |||||||||||
| 18 | ############################################################### | ||||||||||
| 19 | # | ||||||||||
| 20 | # Source: Getopt::Gen::Parser.yp | ||||||||||
| 21 | # Source Author: Bryan Jurish <Gen/cmdline_pod.pm> | ||||||||||
| 22 | # | ||||||||||
| 23 | # Description: Yapp parser for DWDS query strings | ||||||||||
| 24 | # | ||||||||||
| 25 | ############################################################### | ||||||||||
| 26 | |||||||||||
| 27 | #============================================================== | ||||||||||
| 28 | # * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * | ||||||||||
| 29 | #============================================================== | ||||||||||
| 30 | # Do *NOT* change Parser.pm directly, change Parser.yp | ||||||||||
| 31 | # and re-call 'yapp' instead! | ||||||||||
| 32 | #============================================================== | ||||||||||
| 33 | |||||||||||
| 34 | package Getopt::Gen::Parser; | ||||||||||
| 35 | |||||||||||
| 36 | #-------------------------------------- | ||||||||||
| 37 | # Package variables | ||||||||||
| 38 | #-------------------------------------- | ||||||||||
| 39 | our $VERSION = 0.04; | ||||||||||
| 40 | |||||||||||
| 41 | #-------------------------------------- | ||||||||||
| 42 | # Hint routines | ||||||||||
| 43 | #-------------------------------------- | ||||||||||
| 44 | # undef = $yapp_parser->show_hint($hint_code,$curtok,$curval) | ||||||||||
| 45 | 0 | ▶ | sub show_hint { | ||||||||
|
Subroutine
show_hint: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 46 | 0 | $_[0]->{USER}{'hint'} = $_[1]; | |||||||||
| 47 | 0 | ▶ | $_[0]->YYCurtok($_[2]) if (defined($_[2])); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | ▶ | $_[0]->YYCurval($_[3]) if (defined($_[3])); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | $_[0]->YYError; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | %} | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | #-------------------------------------- | ||||||||
|
Subroutine
new: not called CC=2 SCAR=17.3
Pod
undocumented
| |||||||||||
| 55 | 0 | # Grammar Start symbol | |||||||||
| 56 | 0 | ▶ | #-------------------------------------- | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | %start specs | ||||||||||
| 58 | |||||||||||
| 59 | #--------------------------------------- | ||||||||||
| 60 | # expect some shift/reduce conflicts: | ||||||||||
| 61 | #--------------------------------------- | ||||||||||
| 62 | %expect 2 | ||||||||||
| 63 | |||||||||||
| 64 | %% | ||||||||||
| 65 | ############################################################### | ||||||||||
| 66 | # Rules Section | ||||||||||
| 67 | ############################################################### | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | specs: { 1 } # --EMPTY | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 70 | 0 | ▶ | | EOI { 1 } # --EOI | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | | specs EOI | ||||||||||
| 72 | | specs newlines | ||||||||||
| 73 | | specs newlines spec # --RECURSIVE | ||||||||||
| 74 | ; | ||||||||||
| 75 | |||||||||||
| 76 | spec: | ||||||||||
| 77 | basic_spec | ||||||||||
| 78 | | ggo_option_spec | ||||||||||
| 79 | | extended_spec | ||||||||||
| 80 | | user_spec | ||||||||||
| 81 | ; | ||||||||||
| 82 | |||||||||||
| 83 | #------------------------------------------------------------------- | ||||||||||
| 84 | # extensions | ||||||||||
| 85 | #------------------------------------------------------------------- | ||||||||||
| 86 | extended_spec: | ||||||||||
| 87 | 0 | ▶ | TOK_CODE string { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||
| 88 | 1 | $_[0]->{USER}{og}->add_user_code($_[2]); | |||||||||
| 89 | } | ||||||||||
| 90 | 0 | ▶ | | TOK_RCFILE string { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||
| 91 | 1 | $_[0]->{USER}{og}->add_rcfile($_[2]); | |||||||||
| 92 | } | ||||||||||
| 93 | 0 | ▶ | | TOK_ARGUMENT string string kw_decls { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 94 | 0 | $_[0]->{USER}{og}->add_argument({name=>$_[2],descr=>$_[3],%{$_[4]}}); | |||||||||
| 95 | } | ||||||||||
| 96 | 0 | ▶ | | TOK_GROUP string { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 97 | 0 | $_[0]->{USER}{og}->add_group($_[2]); | |||||||||
| 98 | } | ||||||||||
| 99 | 0 | ▶ | | TOK_ON_REPARSE reparse_action { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 100 | 0 | $_[0]->{USER}{og}->set_reparse_action($_[2]); | |||||||||
| 101 | } | ||||||||||
| 102 | 0 | ▶ | | TOK_UNNAMED string { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 103 | 0 | $_[0]{USER}{og}{unnamed} = $_[2]; | |||||||||
| 104 | } | ||||||||||
| 105 | | extended_option_type extended_option_body | ||||||||||
| 106 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 107 | 0 | $_[0]->{USER}{og}->add_option({ type=>$_[1], %{$_[2]}, }, | |||||||||
| 108 | $_[0]); | ||||||||||
| 109 | } | ||||||||||
| 110 | ; | ||||||||||
| 111 | |||||||||||
| 112 | |||||||||||
| 113 | extended_option_type: | ||||||||||
| 114 | 0 | ▶ | TOK_FUNCT { 'funct' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 115 | 0 | ▶ | | TOK_FLAG { 'flag2' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 116 | 0 | ▶ | | TOK_TOGGLE { 'flag' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 117 | 0 | ▶ | | TOK_STRING { 'string' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 118 | 0 | ▶ | | TOK_INT { 'int' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 119 | 0 | ▶ | | TOK_SHORT { 'short' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 120 | 0 | ▶ | | TOK_LONG { 'long' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 121 | 0 | ▶ | | TOK_FLOAT { 'float' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 122 | 0 | ▶ | | TOK_DOUBLE { 'double' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 123 | 0 | ▶ | | TOK_LONGDOUBLE { 'longdouble' } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 124 | ; | ||||||||||
| 125 | |||||||||||
| 126 | extended_option_body: | ||||||||||
| 127 | longname shortname description kw_decls | ||||||||||
| 128 | 0 | ▶ | { my %hash = (long=>$_[1], | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 129 | short=>$_[2], | ||||||||||
| 130 | descr=>$_[3], | ||||||||||
| 131 | 0 | %{$_[4]}); | |||||||||
| 132 | 0 | \%hash; | |||||||||
| 133 | } | ||||||||||
| 134 | ; | ||||||||||
| 135 | |||||||||||
| 136 | reparse_action: string | ||||||||||
| 137 | ; | ||||||||||
| 138 | |||||||||||
| 139 | |||||||||||
| 140 | ## -- arbitrary user strings | ||||||||||
| 141 | user_spec: | ||||||||||
| 142 | symbol user_value | ||||||||||
| 143 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 144 | 0 | $_[0]->{USER}{og}{USER}{$_[1]} = $_[2]; | |||||||||
| 145 | } | ||||||||||
| 146 | ; | ||||||||||
| 147 | |||||||||||
| 148 | user_value: string | ||||||||||
| 149 | ; | ||||||||||
| 150 | |||||||||||
| 151 | #------------------------------------------------------------------- | ||||||||||
| 152 | # gengetopt-compatible stuff | ||||||||||
| 153 | #------------------------------------------------------------------- | ||||||||||
| 154 | basic_spec: | ||||||||||
| 155 | 0 | ▶ | TOK_PACKAGE string { $_[0]->{USER}{og}{package} = $_[2]; } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 156 | 0 | ▶ | | TOK_VERSION string { $_[0]->{USER}{og}{version} = $_[2]; } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 157 | 0 | ▶ | | TOK_PURPOSE string { $_[0]->{USER}{og}{purpose} = $_[2]; } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 158 | 0 | ▶ | | TOK_PODPREAMBLE string { $_[0]->{USER}{og}{podpreamble} = $_[2]; } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 159 | ; | ||||||||||
| 160 | |||||||||||
| 161 | ggo_option_spec: | ||||||||||
| 162 | 0 | ▶ | TOK_OPTION longname shortname description ggo_option_body { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 163 | $_[0]->{USER}{og}->add_option({ | ||||||||||
| 164 | long=>$_[2], | ||||||||||
| 165 | short=>$_[3], | ||||||||||
| 166 | descr=>$_[4], | ||||||||||
| 167 | 0 | %{$_[5]}, | |||||||||
| 168 | }, | ||||||||||
| 169 | $_[0]); | ||||||||||
| 170 | }; | ||||||||||
| 171 | |||||||||||
| 172 | |||||||||||
| 173 | #------------------------------------------------------------------- | ||||||||||
| 174 | # gengetopt-compatible declarations | ||||||||||
| 175 | #------------------------------------------------------------------- | ||||||||||
| 176 | ggo_option_body: | ||||||||||
| 177 | 0 | ▶ | functType { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 178 | ## -- function-option | ||||||||||
| 179 | 0 | {type=>'funct',default=>0}; | |||||||||
| 180 | } | ||||||||||
| 181 | 0 | ▶ | | flagType kw_decls onoff_value { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 182 | ## -- flag option | ||||||||||
| 183 | 0 | {type=>'flag', %{$_[2]}, default=>$_[3]}; | |||||||||
| 184 | } | ||||||||||
| 185 | 0 | ▶ | | option_argument_type kw_decls required { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 186 | ## -- option with an argument | ||||||||||
| 187 | 0 | {type=>$_[1], %{$_[2]}, required=>$_[3]}; | |||||||||
| 188 | } | ||||||||||
| 189 | ; | ||||||||||
| 190 | |||||||||||
| 191 | required: yesno | ||||||||||
| 192 | ; | ||||||||||
| 193 | |||||||||||
| 194 | yesno: | ||||||||||
| 195 | 0 | ▶ | TOK_NO { "0" } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 196 | 0 | ▶ | | TOK_YES { "1" } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 197 | ; | ||||||||||
| 198 | |||||||||||
| 199 | 0 | ▶ | kw_decls: { {} }## -- empty | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 200 | | kw_decls symbol EQUALS string | ||||||||||
| 201 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 202 | 0 | my %hash = (%{$_[1]}, $_[2]=>$_[4]); | |||||||||
| 203 | 0 | \%hash; | |||||||||
| 204 | } | ||||||||||
| 205 | ; | ||||||||||
| 206 | |||||||||||
| 207 | functType: TOK_NO; | ||||||||||
| 208 | |||||||||||
| 209 | flagType: TOK_FLAG; | ||||||||||
| 210 | |||||||||||
| 211 | option_argument_type: | ||||||||||
| 212 | TOK_STRING | ||||||||||
| 213 | | TOK_INT | ||||||||||
| 214 | | TOK_SHORT | ||||||||||
| 215 | | TOK_LONG | ||||||||||
| 216 | | TOK_FLOAT | ||||||||||
| 217 | | TOK_DOUBLE | ||||||||||
| 218 | | TOK_LONGDOUBLE | ||||||||||
| 219 | ; | ||||||||||
| 220 | |||||||||||
| 221 | 0 | ▶ | longname: string | MINUS { "-" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 222 | |||||||||||
| 223 | shortname: SYMBOL | ||||||||||
| 224 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 225 | 0 | ▶ | if (length("$_[1]") ne 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 226 | 0 | $_[0]->show_hint('NOT_SHORT_ENOUGH','SHORT_OPTION_NAME',$_[1]); | |||||||||
| 227 | } | ||||||||||
| 228 | 0 | $_[1]; | |||||||||
| 229 | } | ||||||||||
| 230 | 0 | ▶ | | MINUS { "-" } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 231 | ; | ||||||||||
| 232 | |||||||||||
| 233 | description: string | ||||||||||
| 234 | ; | ||||||||||
| 235 | |||||||||||
| 236 | onoff_value: | ||||||||||
| 237 | 0 | ▶ | TOK_ON { "1" } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 238 | 0 | ▶ | | TOK_OFF { "0" } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 239 | ; | ||||||||||
| 240 | |||||||||||
| 241 | symbol: | ||||||||||
| 242 | SYMBOL | ||||||||||
| 243 | | TOK_CODE | ||||||||||
| 244 | ; | ||||||||||
| 245 | |||||||||||
| 246 | ## -- strings are implicitly dequoted! | ||||||||||
| 247 | string: | ||||||||||
| 248 | 0 | ▶ | DQ_STRING { $_[1] } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 249 | 0 | ▶ | | SQ_STRING { $_[1] } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 250 | 0 | ▶ | | BR_STRING { $_[1] } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 251 | 0 | ▶ | | BQ_STRING { $_[1] } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 252 | 0 | ▶ | | SYMBOL { $_[1] } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 253 | 0 | ; | |||||||||
| 254 | |||||||||||
| 255 | newlines: | ||||||||||
| 256 | newline | ||||||||||
| 257 | | newlines newline | ||||||||||
| 258 | ; | ||||||||||
| 259 | |||||||||||
| 260 | newline: NEWLINE | ||||||||||
| 261 | ; | ||||||||||
| 262 | |||||||||||
| 263 | %% | ||||||||||
| 264 | ############################################################## | ||||||||||
| 265 | 0 | # Footer Section | |||||||||
| 266 | ############################################################### | ||||||||||
| 267 | |||||||||||
| 268 | package Getopt::Gen::Parser; | ||||||||||
| 269 | |||||||||||
| 270 | 1; | ||||||||||
| 271 | |||||||||||
| 272 | __END__ | ||||||||||