Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2375

Re: How do I match empty lines with Flex?

Path csiph.com!xmission!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end
From Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid>
Newsgroups comp.compilers
Subject Re: How do I match empty lines with Flex?
Date Sat, 5 Oct 2019 22:29:46 +0800
Organization Easynews - www.easynews.com
Lines 23
Sender news@iecc.com
Approved comp.compilers@iecc.com
Message-ID <19-10-005@comp.compilers> (permalink)
References <19-10-003@comp.compilers> <19-10-004@comp.compilers>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
Injection-Info gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="39815"; mail-complaints-to="abuse@iecc.com"
Keywords flex, comment
Posted-Date 05 Oct 2019 10:49:00 EDT
X-submission-address compilers@iecc.com
X-moderator-address compilers-request@iecc.com
X-FAQ-and-archives http://compilers.iecc.com
In-Reply-To <19-10-004@comp.compilers>
Content-Language en-GB
Xref csiph.com comp.compilers:2375

Show key headers only | View raw


On 05/10/2019 12:55 am, Kaz Kylheku wrote:
> On 2019-10-04, Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote:
>> Dear comp.compilers,
>>
>> The following program matches lines in a text file, but ignores empty
>> lines.  Is there any way I can alter it so it returns something on empty
>> lines?
>
> How about:
>
> .+\n { num_lines++; return NONEMPTY_LINE; }
> \n   { num_lines++; return EMPTY_LINE; }
> .+   { num_lines++; return MISSING_LAST_NEWLINE; }

Thank you, that indeed does the trick.  With %option yylineno the count
is off by one; the first line is numbered 2 for some reason.  With my
own count, it's correct.

--
Johann | email: invalid -> com | www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | twitter: @myrkraverk
[Flex starts yylineno at 1, so if you increment it in the pattern
that matches .+\n you'll see the first line as line 2.  -John]

Back to comp.compilers | Previous | NextPrevious in thread | Find similar


Thread

How do I match empty lines with Flex? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2019-10-04 22:01 +0800
  Re: How do I match empty lines with Flex? Kaz Kylheku <847-115-0292@kylheku.com> - 2019-10-04 16:55 +0000
    Re: How do I match empty lines with Flex? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2019-10-05 22:29 +0800

csiph-web