1 /*=============================================================================
2 Copyright (c) 2002 2004 2006 Joel de Guzman
3 Copyright (c) 2004 Eric Niebler
4 http://spirit.sourceforge.net/
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
10 #if !defined(BOOST_SPIRIT_QUICKBOOK_PHRASE_HPP)
11 #define BOOST_SPIRIT_QUICKBOOK_PHRASE_HPP
13 #include "detail/utils.hpp"
14 #include <boost/spirit/include/classic_core.hpp>
15 #include <boost/spirit/include/classic_confix.hpp>
16 #include <boost/spirit/include/classic_chset.hpp>
17 #include <boost/spirit/include/classic_assign_actor.hpp>
18 #include <boost/spirit/include/classic_if.hpp>
22 using namespace boost::spirit::classic
;
24 template <typename Rule
, typename Action
>
29 , Action
const& action
37 graph_p
// A single char. e.g. *c*
39 >> (space_p
| punct_p
| end_p
))
40 // space_p, punct_p or end_p
43 ( graph_p
>> // graph_p must follow mark
45 ( (graph_p
>> mark
) // Make sure that we don't go
46 | close
// past a single block
48 ) >> graph_p
// graph_p must precede mark
50 >> (space_p
| punct_p
| end_p
))
51 // space_p, punct_p or end_p
58 template <typename Actions
>
59 struct phrase_grammar
: grammar
<phrase_grammar
<Actions
> >
61 phrase_grammar(Actions
& actions
, bool& no_eols
)
62 : no_eols(no_eols
), actions(actions
) {}
64 template <typename Scanner
>
67 definition(phrase_grammar
const& self
)
70 Actions
& actions
= self
.actions
;
85 if_p(var(self
.no_eols
))
87 eol
>> eol
// Make sure that we don't go
88 ] // past a single block, except
89 ; // when preformatted.
92 (eps_p
- (alnum_p
| '_')) >> space
// must not be preceded by
93 ; // alpha-numeric or underscore
96 "[/" >> *(dummy_block
| (anychar_p
- ']')) >> ']'
100 '[' >> *(dummy_block
| (anychar_p
- ']')) >> ']'
114 eps_p(actions
.macro
// must not be followed by
115 >> (eps_p
- (alpha_p
| '_'))) // alpha or underscore
116 >> actions
.macro
[actions
.do_macro
]
120 template_arg
[push_back_a(actions
.template_info
)]
122 ".." >> template_arg
[push_back_a(actions
.template_info
)]
126 static const bool true_
= true;
127 static const bool false_
= false;
131 ch_p('`') [assign_a(actions
.template_escape
,true_
)]
133 eps_p
[assign_a(actions
.template_escape
,false_
)]
138 >> actions
.templates
.scope
139 ) [push_back_a(actions
.template_info
)]
142 (actions
.templates
.scope
144 ) [push_back_a(actions
.template_info
)]
151 '[' >> +template_arg
>> ']'
155 +(brackets
| (anychar_p
- (str_p("..") | ']')))
163 | (eol
>> eol
) // Make sure that we don't go
164 ) // past a single block
166 ) [actions
.inline_code
]
176 ) [actions
.code_block
]
184 ) [actions
.code_block
]
196 simple_markup(simple_bold
,
197 '*', actions
.simple_bold
, phrase_end
);
198 simple_markup(simple_italic
,
199 '/', actions
.simple_italic
, phrase_end
);
200 simple_markup(simple_underline
,
201 '_', actions
.simple_underline
, phrase_end
);
202 simple_markup(simple_teletype
,
203 '=', actions
.simple_teletype
, phrase_end
);
208 | (anychar_p
- phrase_end
) [actions
.plain_char
]
236 | template_
[actions
.do_template
]
237 | str_p("br") [actions
.break_
]
243 str_p("\\n") [actions
.break_
]
244 | "\\ " // ignore an escaped char
245 | '\\' >> punct_p
[actions
.raw_char
]
247 ("'''" >> !eol
) [actions
.escape_pre
]
248 >> *(anychar_p
- "'''") [actions
.raw_char
]
249 >> str_p("'''") [actions
.escape_post
]
254 +(anychar_p
- (space_p
| ']'))
259 >> macro_identifier
[actions
.cond_phrase_pre
]
260 >> (!phrase
) [actions
.cond_phrase_post
]
266 phrase_end
)) [actions
.image
]
272 (']' | hard_space
))) [actions
.url_pre
]
274 | (hard_space
>> phrase
)
281 (']' | hard_space
))) [actions
.link_pre
]
283 | (hard_space
>> phrase
)
284 ) [actions
.link_post
]
296 "funcref" >> hard_space
298 (']' | hard_space
))) [actions
.funcref_pre
]
300 | (hard_space
>> phrase
)
301 ) [actions
.funcref_post
]
305 "classref" >> hard_space
307 (']' | hard_space
))) [actions
.classref_pre
]
309 | (hard_space
>> phrase
)
310 ) [actions
.classref_post
]
314 "memberref" >> hard_space
316 (']' | hard_space
))) [actions
.memberref_pre
]
318 | (hard_space
>> phrase
)
319 ) [actions
.memberref_post
]
323 "enumref" >> hard_space
325 (']' | hard_space
))) [actions
.enumref_pre
]
327 | (hard_space
>> phrase
)
328 ) [actions
.enumref_post
]
332 "macroref" >> hard_space
334 (']' | hard_space
))) [actions
.macroref_pre
]
336 | (hard_space
>> phrase
)
337 ) [actions
.macroref_post
]
341 "headerref" >> hard_space
343 (']' | hard_space
))) [actions
.headerref_pre
]
345 | (hard_space
>> phrase
)
346 ) [actions
.headerref_post
]
350 "conceptref" >> hard_space
352 (']' | hard_space
))) [actions
.conceptref_pre
]
354 | (hard_space
>> phrase
)
355 ) [actions
.conceptref_post
]
359 "globalref" >> hard_space
361 (']' | hard_space
))) [actions
.globalref_pre
]
363 | (hard_space
>> phrase
)
364 ) [actions
.globalref_post
]
368 ch_p('*') [actions
.bold_pre
]
369 >> blank
>> phrase
[actions
.bold_post
]
373 ch_p('\'') [actions
.italic_pre
]
374 >> blank
>> phrase
[actions
.italic_post
]
378 ch_p('_') [actions
.underline_pre
]
379 >> blank
>> phrase
[actions
.underline_post
]
383 ch_p('^') [actions
.teletype_pre
]
384 >> blank
>> phrase
[actions
.teletype_post
]
388 ch_p('-') [actions
.strikethrough_pre
]
389 >> blank
>> phrase
[actions
.strikethrough_post
]
393 ch_p('"') [actions
.quote_pre
]
394 >> blank
>> phrase
[actions
.quote_post
]
398 ch_p('~') [actions
.replaceable_pre
]
399 >> blank
>> phrase
[actions
.replaceable_post
]
406 ) [assign_a(actions
.source_mode
)]
410 str_p("footnote") [actions
.footnote_pre
]
411 >> blank
>> phrase
[actions
.footnote_post
]
415 rule
<Scanner
> space
, blank
, comment
, phrase
, phrase_markup
, image
,
416 phrase_end
, bold
, italic
, underline
, teletype
,
417 strikethrough
, escape
, url
, common
, funcref
, classref
,
418 memberref
, enumref
, macroref
, headerref
, conceptref
, globalref
,
419 anchor
, link
, hard_space
, eol
, inline_code
, simple_format
,
420 simple_bold
, simple_italic
, simple_underline
,
421 simple_teletype
, source_mode
, template_
, template_arg
,
422 quote
, code_block
, footnote
, replaceable
, macro
,
423 brackets
, template_args
, dummy_block
, cond_phrase
,
428 start() const { return common
; }
435 template <typename Actions
>
436 struct simple_phrase_grammar
437 : public grammar
<simple_phrase_grammar
<Actions
> >
439 simple_phrase_grammar(Actions
& actions
)
440 : actions(actions
) {}
442 template <typename Scanner
>
445 definition(simple_phrase_grammar
const& self
)
446 : unused(false), common(self
.actions
, unused
)
448 Actions
& actions
= self
.actions
;
453 | (anychar_p
- ']') [actions
.plain_char
]
458 "[/" >> *(dummy_block
| (anychar_p
- ']')) >> ']'
462 '[' >> *(dummy_block
| (anychar_p
- ']')) >> ']'
467 rule
<Scanner
> phrase
, comment
, dummy_block
;
468 phrase_grammar
<Actions
> common
;
471 start() const { return phrase
; }
478 #endif // BOOST_SPIRIT_QUICKBOOK_PHRASE_HPP