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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.