Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-02

h2pas: Patch for multi-line macros

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jeff Pohlmeyer

I see things like this a lot in C headers:

#define foo(a,b,c) \
( a + b + c )

But h2pas chokes when it sees the backslash:

Illegal character in line 1
"#define foo(a,b,c) \"
at line 1 error : syntax error
at line 2 error : syntax error

I think this will solve the problem:

[PATCH]

--- scan.l.OEM Wed Feb 26 12:45:31 2003
+++ scan.l.JKP Mon Feb 9 11:31:39 2004
@@ -149,6 +149,8 @@

     const
        in_define : boolean = false;
+       { True if define spans to the next line }
+       cont_line : boolean = false;
        { 1 after define; 2 after the ID to print the first separating space }
        in_space_define : byte = 0;
        arglevel : longint = 0;
@@ -668,12 +670,31 @@
 \n                      begin
                            if in_define then
                             begin
-                              in_define:=false;
-                              in_space_define:=0;
-                              return(NEW_LINE);
+                              in_space_define:=0;
+                              if cont_line then
+                              begin
+                                cont_line:=false;
+                              end
+                              else
+                              begin
+                                in_define:=false;
+                                return(NEW_LINE);
+                              end;
                             end;
-                        end;
-.                       begin
+                       end;
+\\$                    begin
+                           if in_define then
+                           begin
+                             cont_line:=true;
+                           end
+                           else
+                           begin
+                             writeln('Unexpected wrap of line ',yylineno);
+                             writeln('"',yyline,'"');
+                             return(256);
+                           end;
+                       end;
+.                      begin
                            writeln('Illegal character in line ',yylineno);
                            writeln('"',yyline,'"');
                            return(256);

[/PATCH]

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online. http://taxes.yahoo.com/filing.html

Reply by email

Unknown author
to Jeff Pohlmeyer
Jeff Pohlmeyer wrote 14 lines
I see things like this a lot in C headers: #define foo(a,b,c) \ ( a + b + c ) But h2pas chokes when it sees the backslash: Illegal character in line 1 "#define foo(a,b,c) \" at line 1 error : syntax error at line 2 error : syntax error

A known problem :)

I think this will solve the problem:

I applied the patch, thank you very much !

Michael.

Reply by email