lldp.grammar
changeset 31 509d9985d152
equal deleted inserted replaced
30:db3aeb17baa7 31:509d9985d152
       
     1 # Grammar for Ciena devices
       
     2 # Parses "lldp show neighbors" command
       
     3 #
       
     4 # Copyright (c) 2010 Tomas Zeman <tzeman@volny.cz>
       
     5 # All rights reserved.
       
     6 #
       
     7 # Redistribution and use in source and binary forms, with or without
       
     8 # modification, are permitted providing that the following conditions 
       
     9 # are met:
       
    10 # 1. Redistributions of source code must retain the above copyright
       
    11 #    notice, this list of conditions and the following disclaimer.
       
    12 # 2. Redistributions in binary form must reproduce the above copyright
       
    13 #    notice, this list of conditions and the following disclaimer in the
       
    14 #    documentation and/or other materials provided with the distribution.
       
    15 #
       
    16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
       
    17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    19 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
       
    20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
       
    21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
       
    22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
       
    23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
       
    24 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
       
    25 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    26 # POSSIBILITY OF SUCH DAMAGE.
       
    27 #
       
    28 { # perl code follows
       
    29 
       
    30 $::res = {};
       
    31 $::res->{rows} = [];
       
    32 
       
    33 } # end of perl code
       
    34 
       
    35 file:		<skip: qr/[^\S\n]*/>	# Ignore non-newline whitespace
       
    36 		line(s) eofile
       
    37 
       
    38 line: 		row(s) row_edge
       
    39 		| <error>
       
    40 
       
    41 emptyline:	eol
       
    42 
       
    43 eofile:		/^\Z/
       
    44 
       
    45 eol:		/\n/
       
    46 
       
    47 word:		/[0-9a-zA-Z\/_\#\"\.\$,+<>=\(\)-]+/
       
    48 		{ $item[1] }
       
    49 
       
    50 row_edge:	/[+-]+/ eol
       
    51 
       
    52 row:		row_edge "|" cell(s) eol
       
    53 		{ push @{$::res->{rows}}, $item[3] }
       
    54 		| "|" cell(s) eol
       
    55 		{ push @{$::res->{rows}}, $item[2] }
       
    56 
       
    57 cell:		content_cell "|"
       
    58 		{ $item[1] }
       
    59 		| empty_cell "|"
       
    60 		{ "" }
       
    61 
       
    62 content_cell:	word(s)":" word(s)
       
    63 		{
       
    64 		my $k = join " ", @{$item[1]};
       
    65 		my $v = join " ", @{$item[3]};
       
    66 		$return = {$k => $v};
       
    67 		}
       
    68 		| word(s)
       
    69 		{ join " ", @{$item[1]} }
       
    70 
       
    71 empty_cell:	""
       
    72