Flex prints newline to stdout on default rule match - want to alter that behavior
Asked Answered
L

1

6

I have the following flex rules in place.

"#"{name}               {printf(" HASH |  %s\n", yytext);}
.                       {}

It works great for my purposes and outputs upon a match to the first rule;

HASH | some matched string

What's bothering me is that flex is also printing a newline on each match of the second rule. So I get a stdout filled with newlines. Is there a do nothing OP in C? Am I implicitly telling flex to print a newline with a empty rule action? Omitting the "{}" results in the same behavior. I can use sed or whatever to filter out the newlines, but I'd rather just tell flex to stop printing newlines.

I'm happy to provide follow-up examples and data.

Limb answered 26/10, 2013 at 10:32 Comment(0)
E
6

You need to add \n to your default rule:

.|\n   {}
Epos answered 26/10, 2013 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.