Preprocessor bug filtering out comments

Here you can discuss and share functionality improvements and helper programs to make Context Free better.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
epmoyer
Posts: 1
Joined: Wed Dec 27, 2006 12:37 pm

Preprocessor bug filtering out comments

Post by epmoyer »

There is a bug in the preprocessor with repspect to filtering out comments.

The following:

startshape MAKER
blah blah blah
rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r 4}}
rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r -4}}

...generates an error, as expected, on line 2.

The following:

startshape MAKER
// blah blah blah
# blah blah blah
/* blah blah blah */
rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r 4}}
rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r -4}}

...works as expected (all 3 "blah" lines are ignored)./

BUT, the following errors exit

ERROR #1:

The follwing will generate a syntax error if there is no line feed on the end of the last line:

startshape MAKER
// blah blah blah
rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r 4}}
// rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r -4}}

ERROR #2:

The second rule will be active (i.e. not be ignored) if there is no line feed on the end of the last line:

startshape MAKER
// blah blah blah
rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r 4}}
# rule MAKER { TRIANGLE{} MAKER {s 0.9 y 1 r -4}}

I imagine both errors are related.

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

They are both caused by lex/flex not being able to skip past a line comment that ends with an end-of-file instead of a line-feed. We have known about this limitation in the lex grammar for a while. Rather than try to fix the lex grammar I put in a fix to always tack a line-feed at the end of the cfdg file.

jeremydouglass
Posts: 17
Joined: Fri Mar 30, 2007 9:10 pm

Commented last line returns error - a-ha!

Post by jeremydouglass »

I've been editing CFDG files in Textmate for the syntax highlighting and rendering in Context Free for the iterative display, and this bug was killing me until I figured it out. I'm glad to see a post about it here.

In 2.0, it still dies with most unhelpful error messages - is the appended-line-feed fix in 2.1b? And when is the line added - on save, or on render?

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

The linefeed fix is in 2.1b only, not 2.0. The linefeed is added on at the render, so it is OK if Textmate doesn't add on a linefeed.

Post Reply