Hello.
I realize this is not the Lexing solution you are going after, but I want to throw this out there. I also realize that this is probably not the most elegant solution, but it does seem to work with the input that you specified.
In any case I hope this helps.
Input
Host_Alias HA_FOO_GROUP = abc123, eigh456, \ foo987, bar654 #comment line Runas_Alias RA_FOO_SVCACCT = www-data, ceph, \ sshd, memcache, \ xab123 #comment line User_Alias CA_FOO_CSVACCT = www-foo, ceph, \ sshd, memcache, \ xab456
Output
C:\monks>perl parse.pl input.txt Alias type : Host_Alias Alias name : HA_FOO_GROUP Values : abc123 eigh456 foo987 bar654 **** Alias type : Runas_Alias Alias name : RA_FOO_SVCACCT Values : www-data ceph sshd memcache xab123 **** Alias type : User_Alias Alias name : CA_FOO_CSVACCT Values : www-foo ceph sshd memcache xab456 **** C:\monks>
Script
#/usr/bin/perl use strict; use warnings; die "Error. Usage \'perl parse.pl inputfile.txt\'\n $!" unless $#ARGV +== 0; my $in_filename = shift @ARGV; my $complete_line = ""; open(my $IN,"<",$in_filename) || die "Cannot find input '$in_filena +me'\n $!"; while(<$IN>) { chomp; next if ($_ eq ""); next if (m/^\#/); if ($_ =~ m/\\$/) { $_ =~ s/\\$//; $complete_line .= $_; next } $complete_line .= $_; # get alias type and name my $index_pos = index($complete_line,'='); my @alias_type_and_name = split(/ /, substr($complete_lin +e,0,$index_pos-1) ); # get alias values my @alias_values = split(/\,/, substr($complete_line,$inde +x_pos+1) ); foreach my $v (@alias_values) { $v =~ s/^\s+//; $v =~ s/\s+$//; } # print values print "Alias type : $alias_type_and_name[0]\n"; print "Alias name : $alias_type_and_name[1]\n"; print "Values : @alias_values\n ****\n"; $complete_line = ""; } close($IN);
In reply to Re: Lexing: how to define tokens based on "context"
by VincentK
in thread Lexing: how to define tokens based on "context"
by three18ti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |