00001
00007
#ifndef SECTION_HPP_INCLUDED
00008
#define SECTION_HPP_INCLUDED
00009
00010
#include <boost/spirit/core.hpp>
00011
#include <boost/spirit/actor/assign_actor.hpp>
00012
00013
00017 namespace dvbcodec
00018 {
00019
using namespace boost::spirit;
00020
00031
template <
typename Actions>
00032 struct Section :
00033
public grammar<Section<Actions> >
00034 {
00039 Section(Actions & actions)
00040 :
actions_(actions)
00041 {
00042 }
00043
00051
template <
typename Scanner>
00052 struct definition
00053 {
00058 definition(
Section const &
self)
00059 {
00060 Actions & actions =
self.actions_;
00061
00062
section_
00063 =
section_ref_ [actions.section_name_]
00064 >>
block_
00065 ;
00066
00067 section_ref_
00068 =
text_id_ [assign_a(actions.section_id_)]
00069 >>
'('
00070 >>
')'
00071 ;
00072
00073 text_id_
00074 = lexeme_d[
00075 alpha_p
00076 >> * (alnum_p |
'_')
00077 ]
00078 ;
00079
00080
quoted_binary_
00081 = lexeme_d[
00082
'\''
00083 >> bin_p
00084 >>
'\''
00085 ]
00086 ;
00087
00088
item_
00089 =
field_
00090 |
loop_
00091 |
conditional_
00092 | section_ref_ [actions.section_ref_]
00093 ;
00094
00095 block_
00096 = ch_p(
'{') [actions.enter_block_]
00097 >> *
item_
00098 >> ch_p(
'}') [actions.leave_block_]
00099 ;
00100
00101
field_
00102 =
identifier_ [assign_a(actions.field_name_)]
00103 >> uint_p [actions.field_]
00104 ;
00105
00106 identifier_
00107 = text_id_
00108 |
quoted_binary_
00109 ;
00110
00111
conditional_
00112 = str_p(
"if")
00113 >>
condition_ [actions.if_]
00114 >> block_
00115 >> ! (str_p(
"else") [actions.else_]
00116 >> block_)
00117 ;
00118
00119 condition_
00120 =
'('
00121 >> text_id_ [assign_a(actions.if_item_)]
00122 >> str_p(
"==") [assign_a(actions.if_op_)]
00123 >>
quoted_binary_ [assign_a(actions.if_value_)]
00124 >>
00125
')'
00126 ;
00127
00128
loop_
00129 =
loop_control_ [actions.loop_control_]
00130 >> ch_p(
'{') [actions.loop_start_]
00131 >> *
item_
00132 >> ch_p(
'}') [actions.loop_end_]
00133 ;
00134
00135 loop_control_
00136 = str_p(
"for")
00137 >>
'('
00138 >> * (anychar_p -
')')
00139 >>
')'
00140 ;
00141
00142 }
00143
00144 rule<Scanner>
00145 section_,
section_name_,
section_ref_,
00146
block_,
field_,
00147
text_id_,
quoted_binary_,
identifier_,
item_,
00148
condition_,
conditional_,
00149
loop_,
loop_control_,
loop_start_,
loop_end_;
00150
00155 rule<Scanner>
const &
00156 start()
const
00157
{
00158
return section_;
00159 }
00160 };
00161
00162 Actions &
actions_;
00163 };
00164
00165 }
00166
00167
#endif
00168