Orocos Real-Time Toolkit  2.8.3
CommonParser.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 15 11:21:07 CEST 2004 CommonParser.cxx
3 
4  CommonParser.cxx - description
5  -------------------
6  begin : Thu July 15 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens at mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 #include <boost/bind.hpp>
38 
39 #include "parse_exception.hpp"
40 #include "parser-debug.hpp"
41 #include "CommonParser.hpp"
42 
43 namespace RTT {
44  using boost::bind;
45  using namespace detail;
46 
47  namespace {
48  boost::spirit::classic::assertion<std::string> expect_eos("End of statement expected. Use a newline or ';' to separate statements.");
49  }
50 
52 
54  : identchar( "a-zA-Z_0-9" ), skipeol(true),
56  {
57  // we reserve a few words
59  "do",
60  "until",
61  "done",
62  "or",
63  "and",
64  "not",
65  "include",
66  "if",
67  "define",
68  "then",
69  "else",
70  "for",
71  "foreach",
72  "while",
73  "true",
74  "false",
75  "const",
76  "nothing", // do not exclude 'do nothing' !
77  "yield",
78  "var",
79  "set",
80  "alias",
81  "send",
82  "collect",
83  "collectIfDone",
84  "return",
85  "call",
86  "try",
87  "catch";
88 
89  BOOST_SPIRIT_DEBUG_RULE( idr );
90  BOOST_SPIRIT_DEBUG_RULE( idlr );
91  BOOST_SPIRIT_DEBUG_RULE( eos );
92  BOOST_SPIRIT_DEBUG_RULE( notassertingeos );
93  BOOST_SPIRIT_DEBUG_RULE( leos );
94  BOOST_SPIRIT_DEBUG_RULE( endofkeyword );
95  BOOST_SPIRIT_DEBUG_RULE( keywords );
96  BOOST_SPIRIT_DEBUG_RULE( keyword );
97  BOOST_SPIRIT_DEBUG_RULE( identifier );
98  BOOST_SPIRIT_DEBUG_RULE( templ );
99  BOOST_SPIRIT_DEBUG_RULE( tidentifier );
100  BOOST_SPIRIT_DEBUG_RULE( identchar );
101  BOOST_SPIRIT_DEBUG_RULE( notassertingidentifier );
102  BOOST_SPIRIT_DEBUG_RULE( lexeme_identifier );
103  BOOST_SPIRIT_DEBUG_RULE( lexeme_notassertingidentifier );
104  BOOST_SPIRIT_DEBUG_RULE( type_name );
105  BOOST_SPIRIT_DEBUG_RULE( skipper );
106 
107  // an identifier is a word which can be used to identify a
108  // label, or be the name of an object or method. it is required
109  // to start with a letter, followed by any number of letters,
110  // numbers, dashes, underscores or letters. The keywords we
111  // reserved above are excluded..
113  endofkeyword = (~identchar) | eol_p | end_p;
114  keyword = lexeme_d[keywords >> eps_p(endofkeyword)];
115 
116  idlr = lexeme_d[alpha_p >> *identchar][assign( lastparsedident )];
117 
118  // silently parses every identifier except keywords
119  notassertingidentifier = (idlr >> !str_p("[]")) - keyword;
120  // loudly asserts when a keyword comes in
121  identifier = keyword[bind( &CommonParser::seenillegalidentifier, this, _1, _2 )] | (idlr >> !str_p("[]") );
122 
123  // this is a recursive rule. 't' stands for 'template' and 'terminal' (followed by a '(')
124  templ = ch_p('<') >> identifier >> *templ >> '>';
125  tidentifier = identifier >> *templ; // >> eps_p( ch_p('(') ); // This is a hack: we expect always the form A<B<C>>(...)
126 
127  // end of statement is on a newline or a ';'
128  //eos = lexeme_d[ *(space_p - eol_p) >> (eol_p | ch_p(';')) ];
129  eos = expect_eos( notassertingeos ); // detect } as eos, but do not consume.
130  notassertingeos = eol_p | ch_p(';') | eps_p(ch_p('}')); // detect } as eos, but do not consume.
131  leos = *(space_p - eol_p) >> (eol_p | ch_p(';') | eps_p(ch_p('}')));
132 
133  chset<> t_identchar( "a-zA-Z-_0-9/<>." );
134  type_name = lexeme_d[ alpha_p >> *t_identchar ] - keyword;
135  }
136 
138  {
139  std::string ident(begin, end);
140  throw parse_exception_illegal_identifier( ident );
141  }
142 
143 }
rule_t notassertingeos
End Of Statement Parser.
rule_t tidentifier
recursive template def.
rule_t eos
End Of Statement Parser.
bool skipeol
Saves eol skipping state.
symbols< nil_t > keywordstable
void seenillegalidentifier(iter_t begin, iter_t end)
lexeme_rule_t lexeme_notassertingidentifier
See identifier, but in lexeme parsing mode.
rule_t type_name
See notassertingidentifier, but in lexeme parsing mode.
functor_parser< eol_skip_functor > skipper
End Of Statement Parser.
lexeme_rule_t leos
End Of Statement Parser.
lexeme_rule_t lexeme_identifier
plain &#39;C&#39; identifier. Does not throw if keyword is parsed.
Due to a bug in MSVC 2005, the operator() ends up with a null reference of the skipeol member Tried s...
rule_t templ
plain &#39;C&#39; identifier. Throws if keyword is parsed.
rule_t notassertingidentifier
identifier with <template> marks in it
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
our_pos_iter_t iter_t