/*
  Copyright Dave Bone 1998 - 2014 
  All Rights Reserved. 
  No part of this document may be reproduced without written consent from the author.
	
FILE:		  cweave_T_sdc.lex
Dates:		  26 Jan. 2006
Purpose:	  write out cweave sentence for 
			syntax directed directives of terminals.
			This is common to all T types:
			error, rc, lrk, and T
*/
/@
@i "/usr/local/yacco2/copyright.w"
@** |cweave_T_sdc| grammar.\fbreak
Write out cweave Terminals' syntax directed directives sentences.
@/
fsm	
(fsm-id "cweave_T_sdc.lex"
,fsm-filename cweave_T_sdc
,fsm-namespace NS_cweave_T_sdc
,fsm-class Ccweave_T_sdc{
   user-prefix-declaration
#include "o2_externs.h"
  ***
 user-declaration
    public:
    std::ofstream* cweave_file_;
	KCHARP T_name_;
	void initialize
		(std::ofstream* Cweave_file
		,yacco2::KCHARP T_name);
    void output_sr_sdcode(yacco2::KCHARP Directive);
    void output_sr_sdcode_title(yacco2::KCHARP Directive);
    void wrt_directive(yacco2::KCHARP Directive,T_syntax_code* Sdc);
  ***
  user-implementation
 	void Ccweave_T_sdc::initialize
		(std::ofstream* Cweave_file
		,yacco2::KCHARP T_name){
			cweave_file_ = Cweave_file;
			T_name_ = T_name;
		}
/@
@*3 |wrt_directive|.
@/
    void Ccweave_T_sdc::wrt_directive(yacco2::KCHARP Directive,T_syntax_code* Sdc){
      output_sr_sdcode_title(Directive);
      if(Sdc == 0){
        output_sr_sdcode(Directive);
        (*cweave_file_) << "/";
        (*cweave_file_) << "/ no sdcode" << endl;
        return;
      }      
      if(Sdc->cweb_marker() != 0){
        WRT_CWEB_MARKER(cweave_file_,Sdc->cweb_marker());   
	  }
      output_sr_sdcode(Directive);
      string xlate;
      int len = Sdc->syntax_code()->length();
      string& sdc=*Sdc->syntax_code();
      // prescan @ due to cweave reqmts
      for(int x=0;x<len;++x){
        char nc = sdc[x];
        if(nc=='@'){
          // check next char for cweave type directives
          char nnc = sdc[x+1];
          if((nnc == '*') || (nnc == '<') || (nnc == '>')){
            xlate += nc;
             continue;
          }else{
            xlate += "@@";
            continue;
          }			
	}else{
            xlate += nc;
            continue;
	}
      }
      (*cweave_file_) << xlate.c_str() << endl;
    }
/@
@*3 |output_sr_sdcode|.
@/
    void Ccweave_T_sdc::output_sr_sdcode(yacco2::KCHARP Directive){
	  char big_buf_[BIG_BUFFER_32K];		
char xa[Max_cweb_item_size];
XLATE_SYMBOLS_FOR_cweave
      (T_name_
      ,xa);
      KCHARP cweave_sentence =
        "@<%s %s directive@>=\n";
       
 	  sprintf(big_buf_
 		,cweave_sentence
 		,xa
 		,Directive
 		);
	  (*cweave_file_) << big_buf_;
    }
/@
@*3 |output_sr_sdcode_title|.
@/
   void Ccweave_T_sdc::output_sr_sdcode_title(yacco2::KCHARP Directive){
	  char big_buf_[BIG_BUFFER_32K];		
char xa[Max_cweb_item_size];
XLATE_SYMBOLS_FOR_cweave
      (T_name_
      ,xa);
      KCHARP cweave_sentence =
        "@*3 %s %s directive.\n";
       
 	  sprintf(big_buf_
 		,cweave_sentence
 		,xa
 		,Directive
 		);
	  (*cweave_file_) << big_buf_;
    }
  ***
}
,fsm-version "1.0",fsm-date "5 Jan. 2006",fsm-debug "false"
,fsm-comments "Write out cweave Terminals' sdc directives.")
@"/usr/local/yacco2/compiler/grammars/yacco2_T_includes.T"

rules{
Rweave_sdc  (){
  -> Rdirectives eog 
}

Rdirectives  (){ 
  ->  Rdirective 
  ->  Rdirectives Rdirective 
}

Rdirective  (){ 
  ->  "#user-declaration"  { 
    op
      Ccweave_T_sdc* fsm = (Ccweave_T_sdc*)rule_info__.parser__->fsm_tbl__;
      KCHARP sdc = "user-declaration";
      fsm->wrt_directive(sdc,sf->p1__->syntax_code());
    ***
    }
  ->  "#constructor"  { 
    op
      Ccweave_T_sdc* fsm = (Ccweave_T_sdc*)rule_info__.parser__->fsm_tbl__;
      KCHARP sdc = "constructor";
      fsm->wrt_directive(sdc,sf->p1__->syntax_code());
    ***
    }
  ->  "#destructor"  { 
    op
      Ccweave_T_sdc* fsm = (Ccweave_T_sdc*)rule_info__.parser__->fsm_tbl__;
      KCHARP sdc = "destructor";
      fsm->wrt_directive(sdc,sf->p1__->syntax_code());
    ***
    }
  ->  "#op"  { 
    op
      Ccweave_T_sdc* fsm = (Ccweave_T_sdc*)rule_info__.parser__->fsm_tbl__;
      KCHARP sdc = "op";
      fsm->wrt_directive(sdc,sf->p1__->syntax_code());
    ***
    }
  ->  "#user-implementation"  { 
    op
      Ccweave_T_sdc* fsm = (Ccweave_T_sdc*)rule_info__.parser__->fsm_tbl__;
      KCHARP sdc = "user-implementation";
      fsm->wrt_directive(sdc,sf->p1__->syntax_code());
    ***
    }
}
}// end of rules
