00001 // /////////////////////////////////////////////////////////////////////////// 00002 // trison.cpp.targetspec by Victor Dods, created 2007/01/25 00003 // /////////////////////////////////////////////////////////////////////////// 00004 // Unless a different license was explicitly granted in writing by the 00005 // copyright holder (Victor Dods), this software is freely distributable under 00006 // the terms of the GNU General Public License, version 2. Any works deriving 00007 // from this work must also be released under the GNU GPL. See the included 00008 // file LICENSE for details. 00009 // /////////////////////////////////////////////////////////////////////////// 00010 00011 // This is a trison targetspec file for a C++ LALR(k) parser class using a 00012 // nondeterministic pushdown automaton (NPDA). 00013 %target cpp 00014 00015 // The value of this directive specifies the filename to use when generating 00016 // the header file (it is used by the below add_codespec directive). 00017 %add_required_directive header_filename %string 00018 // This refers to the file trison.cpp.header.codespec in the data directory. 00019 // See that file for the header template code. 00020 %add_codespec "header" header_filename 00021 00022 // The value of this directive specifies the filename to use when generating 00023 // the implementation file (it is used by the below add_codespec directive). 00024 %add_required_directive implementation_filename %string 00025 // This refers to the file trison.cpp.implementation.codespec in the data 00026 // directory. See that file for the implementation template code. 00027 %add_codespec "implementation" implementation_filename 00028 00029 // /////////////////////////////////////////////////////////////////////////// 00030 // The following directives can be thought of as applying to the header file 00031 // which is to be generated by trison. 00032 // /////////////////////////////////////////////////////////////////////////// 00033 00034 // The value of this directive will be placed at the top of the generated 00035 // header file, below the generated #include directives. It is a dumb code 00036 // block (as opposed to a strict code block) so that you can open a namespace 00037 // which the generated class will be enclosed in (and consequently, the 00038 // matching close-bracket is not in the same code block). 00039 // e.g. %{ namespace SweetNamespace { %} 00040 %add_optional_directive top_of_header_file %dumb_code_block 00041 // The name of the class to be generated by trison, e.g. "DumbParser" 00042 %add_required_directive class_name %identifier 00043 // The optional class inheritance of the generated class, 00044 // e.g. { public AwesomeBase } 00045 %add_optional_directive class_inheritance %strict_code_block 00046 // Class declarations to put at the top of the generated class. They will by 00047 // default have class access of public. This may be necessary to use in some 00048 // cases to guarantee that these declarations come before later ones 00049 // (including the scanner's generated methods. 00050 // e.g. { enum HippoType { HAPPY, SAD, ANGRY }; } 00051 %add_optional_directive top_of_class %strict_code_block 00052 // Specifies the parameters for both the declaration and the definition of the 00053 // generated class' constructor, unless constructor_definition_parameters is 00054 // also specified, in which case, this one is only used for the constructor's 00055 // declaration (i.e. the one which appears in the header file). 00056 // e.g. "HippoType best_hippo_type = ANGRY" 00057 %add_optional_directive constructor_parameters %strict_code_block 00058 // Specifies the parameters for the definition of the generated class' 00059 // constructor (i.e. the one which appears in the implementation file), 00060 // overriding constructor_parameters. It is an error to specify a value 00061 // for this directive without specifying a value for constructor_parameters. 00062 // e.g. "HippoType best_hippo_type" 00063 %add_optional_directive constructor_definition_parameters %strict_code_block 00064 // When present, causes the generated class' destructor to be virtual. 00065 %add_optional_directive force_virtual_destructor 00066 // Specifies the class access of the generated Parse method. Valid values are 00067 // "public:", "protected:" or "private:". The default access is "public:". 00068 %add_optional_directive parse_method_access %string 00069 /* 00070 // Specifies the parameters for the declaration and the definition of the 00071 // generated Parse method, unless parse_method_definition_parameters is also 00072 // specified, in which case, this one is only used for the Parse method's 00073 // declaration (i.e. the one which appears in the header file). 00074 // e.g. "AstBase *dest_token, HippoType hippo_type = HAPPY" 00075 %add_optional_directive parse_method_parameters %strict_code_block 00076 // Specifies the parameters for the definition of the generated Parse method 00077 // (i.e. the one which appears in the implementation file). It is an error to 00078 // specify a value for this directive without specifying a value for 00079 // parse_method_parameters. These parameters will be available to all regex 00080 // rule handlers specified in the trison source file. 00081 // e.g. "AstBase *dest_token, HippoType hippo_type" 00082 %add_optional_directive parse_method_definition_parameters %strict_code_block 00083 */ 00084 // Similar to top_of_class, this facilitates class declarations at the bottom, 00085 // which may be necessary when declarations from the middle of the generated 00086 // class are needed. Again, the default class access level is public. 00087 // e.g. { State::Name m_saved_state; } 00088 %add_optional_directive bottom_of_class %strict_code_block 00089 // This is the analog to top_of_header_file -- its contents go directly at the 00090 // bottom of the generated header file. If you opened a namespace from within 00091 // top_of_header_file, remember to close it here. 00092 // e.g. %{ } // end of namespace SweetNamespace %} 00093 %add_optional_directive bottom_of_header_file %dumb_code_block 00094 00095 // /////////////////////////////////////////////////////////////////////////// 00096 // The following directives can be thought of as applying to the 00097 // implementation file which is to be generated by trison. 00098 // /////////////////////////////////////////////////////////////////////////// 00099 00100 // Like top_of_header_file, the value of this directive will be placed at the 00101 // top of the generated implementation file, below the generated #include 00102 // directives. It is also a dumb code block, so you can employ unterminated 00103 // namespace blocks. 00104 // e.g. %{ namespace SweetNamespace { %} 00105 %add_optional_directive top_of_implementation_file %dumb_code_block 00106 // If any superclasses or members need explicit construction, do it here. 00107 // e.g. { AwesomeBase(1, 2, 3), m_saved_thingy(456) } 00108 %add_optional_directive superclass_and_member_constructors %strict_code_block 00109 // This specifies code for the body of the generated class' constructor. 00110 // e.g. { std::cout << "constructor being executed" << std::endl; } 00111 %add_optional_directive constructor_actions %strict_code_block 00112 // Like constructor_actions, this specifies code for the body of the generated 00113 // class' destructor. 00114 // e.g. { std::cout << "destructor being executed" << std::endl; } 00115 %add_optional_directive destructor_actions %strict_code_block 00116 // If anything needs to be done at the very beginning of the generated Parse 00117 // method, it should be specified here. If you wanted to enclose the entire 00118 // contents of the Parse method within a "try" block, you would use this to 00119 // open the "try" block. 00120 // e.g. %{ try { %} 00121 %add_optional_directive start_of_parse_method_actions %dumb_code_block 00122 // This is the analog to start_of_parse_method_actions -- its contents go 00123 // directly at the end of the generated Parse method. If you opened a "try" 00124 // block within start_of_parse_method_actions, remember to finish it with one 00125 // or more "catch" blocks. 00126 // e.g. %{ } catch (...) { std::cout << "caught exception" << std::endl } %} 00127 %add_optional_directive end_of_scan_method_actions %dumb_code_block 00128 // This is the analog to top_of_implementation_file -- its contents go 00129 // directly at the bottom of the generated implementation file. If you opened 00130 // a namespace from within top_of_implementation_file, remember to close it 00131 // here. 00132 // e.g. %{ } // end of namespace SweetNamespace %} 00133 %add_optional_directive bottom_of_implementation_file %dumb_code_block 00134 00135 // /////////////////////////////////////////////////////////////////////////// 00136 // The following directives can be thought of as I/O parameters for the 00137 // parser class which is to be generated by trison. 00138 // /////////////////////////////////////////////////////////////////////////// 00139 00140 %add_optional_directive token_data_type %string %default "int" 00141 %add_optional_directive token_data_type_sentinel %string %default "0" 00142 %add_optional_directive custom_token_data_cast %identifier %default static_cast 00143 // this will take its default value from token_data_type 00144 %add_optional_directive return_token_type %string 00145 // operates on variable "token" of type token_data_type 00146 %add_optional_directive token_throw_away_actions %strict_code_block 00147 // TODO: scanner semantics 00148 00149 // This specifies code to be executed when the scanner object is being reset 00150 // to start scanning from a new source. This code is executed in addition to 00151 // various internal state-machine-related initialization that is required. 00152 %add_optional_directive reset_for_new_input_actions %strict_code_block 00153 00154 // /////////////////////////////////////////////////////////////////////////// 00155 // Miscellaneous directives 00156 // /////////////////////////////////////////////////////////////////////////// 00157 00158 // When present, indicates that the code associated with debug spew will be 00159 // generated; the methods Get/SetDebugSpewFlags will be generated. 00160 %add_optional_directive generate_debug_spew_code 00161 // When present, will prevent the timestamp from being added to the top of 00162 // the generated source code files (useful when the generated files are 00163 // checked into a version control system). The default behavior is to 00164 // put a timestamp in the generated header and implementation files. 00165 %add_optional_directive dont_generate_timestamps 00166 00167 // TODO: add BARF-developer debug code directive