POV-Ray : Newsgroups : povray.bugreports : problem with '#break' in macro : Re: problem with '#break' in macro Server Time
29 Mar 2024 03:19:52 EDT (-0400)
  Re: problem with '#break' in macro  
From: William F Pokorny
Date: 10 Sep 2021 07:52:25
Message: <613b46f9$1@news.povray.org>
On 9/7/21 5:34 AM, jr wrote:
> hi,
> 
> the docs say "Note: As of version 3.7 the #break directive can now be used: ...
> anywhere within a #macro to preliminarily terminate the macro."
> <https://wiki.povray.org/content/Reference:Conditional_Directives#Index_Entry_break>
> 
> but I get an error "File 'brktst.pov' line 10: Parse Error: Invalid context for
> #break", from both v3.7.0.8 and v3.8 POV-Rays.  the "scene":
> 
> #version 3.7;
> 
> global_settings {assumed_gamma 1}
> 
> #macro m_flag(f_)
>    #if (!f_)
>      #break
>    #else
>      #debug "ok.\n"
>    #end
> #end
> 
> m_flag(true)
> m_flag(false)
> 

Recently sidetracked by RL and otherwise focused elsewhere code wise...

Looking quickly, I think the function Parser::Break() in the file 
parser_tokenizer.cpp needs a test to handle seeing an 'else block' after 
the 'break' in the 'if block' when the if conditional tests true.

     while ( (Cond_Stack.size() > 1) &&
             (Cond_Stack.back().Cond_Type != WHILE_COND) &&
             (Cond_Stack.back().Cond_Type != FOR_COND) &&
             (Cond_Stack.back().Cond_Type != CASE_TRUE_COND) &&
             (Cond_Stack.back().Cond_Type != INVOKING_MACRO_COND) )

should read:

     while ( (Cond_Stack.size() > 1) &&
             (Cond_Stack.back().Cond_Type != WHILE_COND) &&
             (Cond_Stack.back().Cond_Type != FOR_COND) &&
             (Cond_Stack.back().Cond_Type != ELSE_COND) &&
             (Cond_Stack.back().Cond_Type != CASE_TRUE_COND) &&
             (Cond_Stack.back().Cond_Type != INVOKING_MACRO_COND) )

The code above works with the code variations recently posted. However, 
it's admittedly a slap shot. More thought and testing needed.

My quick test as to whether on the right track was to create a scene 
file like jr's original, but with macro internals looking like:

   #if (f_)
     #debug "ok.\n"
   #else
     #debug "break.\n"
     #break
   #end

The variation above works for me in all v3.7+ versions I have in hand.

Bill P.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.