Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent handling of #line directives in input files #98

Closed
skvadrik opened this issue Apr 2, 2008 · 7 comments

Comments

@skvadrik
Copy link
Owner

commented Apr 2, 2008

I was playing around with a project where I pass the re2c input file through a preprocessor (m4) first. For best results in this situation, it’s best if re2c can handle #file directives in its input file.

The attached patch to 0.13.3 accomplishes this. While it takes reasonable precautions against false matches for #line directives, it does not strictly check for the directives to start at the beginning of a line (as far as I know, re2c does not yet support the ^pattern syntax, does it?)

While I tried to match the general style of re2c’s source code, I’m open to reworking the patch to meet any further standards I may have missed.

Original comment by: neeri

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Apr 2, 2008

Original comment by: neeri

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Apr 3, 2008

Logged In: YES
user_id=271023
Originator: NO

I think it is a good idea and I am going to add it. However I need to change your patch a bit. And I will need a few tests for it. Also a patch for documentation might be good. Dunno how right now, tough.

Original comment by: helly

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Apr 3, 2008

- priority: 5 —> 3
- assigned_to: nobody —> helly
- status: open —> open-accepted

Original comment by: helly

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Apr 3, 2008

Logged In: YES
user_id=271023
Originator: NO

I’ve added this feature along with an initial test. Turned out to be much more complex than you thought, when implementing it completely.

Original comment by: helly

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Apr 3, 2008

- status: open-accepted —> closed-fixed

Original comment by: helly

@pskocik

This comment has been minimized.

Copy link
Contributor

commented Jun 25, 2018

This doesn't appear to be working. I tried to use lemon output (with #line directives) as re2c input and large parts of the generated source got deleted. If I try feeding the output of running re2c on

typedef enum num_t { ERR, BIN, OCT, DEC, HEX } num_t;
static num_t lex(const char *YYCURSOR)
{
	const char *YYMARKER;
	/*!re2c
		re2c:define:YYCTYPE = char;
		re2c:yyfill:enable = 0;

		end = "\x00";
		bin = '0b' [01]+;
		oct = "0" [0-7]*;
		dec = [1-9][0-9]*;
		hex = '0x' [0-9a-fA-F]+;

		*       { return ERR; }
		bin end { return BIN; }
		oct end { return OCT; }
		dec end { return DEC; }
		hex end { return HEX; }
	*/
}

(from the docs) back to re2c with

re2c example.c.re |re2c -

I get

/* Generated by re2c 1.0.3 on Mon Jun 25 20:48:07 2018 */
#line 1 ""

}

(I'm on an older browser and I'm having some difficulties with the commenting tool, so apologies for the formatting.)

skvadrik added a commit that referenced this issue Jun 25, 2018

Fixed processing of #line directives in input files.
The correct behaviour was broken somewhere in between 0.16 and 1.0:
re2c was forgetting to output the chunk of input file that precedes
the #line directive.

Reported by pskocik in #98.
@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Jun 25, 2018

Pushed a fix: 96aea70, thanks for reporting! The correct behaviour was broken between 0.16 and 1.0.

@skvadrik skvadrik reopened this Jun 25, 2018

@skvadrik skvadrik closed this Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.