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?

From Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid>
Newsgroups comp.compilers
Subject Re: How do I match empty lines with Flex?
Date 2019-10-05 22:29 +0800
Organization Easynews - www.easynews.com
Message-ID <19-10-005@comp.compilers> (permalink)
References <19-10-003@comp.compilers> <19-10-004@comp.compilers>

Show all headers | 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