From 027031a505f9f0e5c8c5fafc94c4440667159e3c Mon Sep 17 00:00:00 2001 From: Grégoire Duchêne Date: Thu, 8 Sep 2011 10:57:03 +0200 Subject: Moved the default parser into a namespace. This change is motivated by the need of having several parsers. This will make mppdown more extensible. --- src/main.cpp | 4 ++-- src/parser/document_p.cpp | 20 ----------------- src/parser/document_p.h | 31 -------------------------- src/parser/line_p.cpp | 20 ----------------- src/parser/line_p.h | 31 -------------------------- src/parser/paragraph_p.cpp | 20 ----------------- src/parser/paragraph_p.h | 31 -------------------------- src/parser/text_p.cpp | 45 -------------------------------------- src/parser/text_p.h | 37 ------------------------------- src/parsers/mdown2/document_p.cpp | 20 +++++++++++++++++ src/parsers/mdown2/document_p.h | 33 ++++++++++++++++++++++++++++ src/parsers/mdown2/line_p.cpp | 20 +++++++++++++++++ src/parsers/mdown2/line_p.h | 33 ++++++++++++++++++++++++++++ src/parsers/mdown2/paragraph_p.cpp | 20 +++++++++++++++++ src/parsers/mdown2/paragraph_p.h | 33 ++++++++++++++++++++++++++++ src/parsers/mdown2/text_p.cpp | 45 ++++++++++++++++++++++++++++++++++++++ src/parsers/mdown2/text_p.h | 39 +++++++++++++++++++++++++++++++++ 17 files changed, 245 insertions(+), 237 deletions(-) delete mode 100644 src/parser/document_p.cpp delete mode 100644 src/parser/document_p.h delete mode 100644 src/parser/line_p.cpp delete mode 100644 src/parser/line_p.h delete mode 100644 src/parser/paragraph_p.cpp delete mode 100644 src/parser/paragraph_p.h delete mode 100644 src/parser/text_p.cpp delete mode 100644 src/parser/text_p.h create mode 100644 src/parsers/mdown2/document_p.cpp create mode 100644 src/parsers/mdown2/document_p.h create mode 100644 src/parsers/mdown2/line_p.cpp create mode 100644 src/parsers/mdown2/line_p.h create mode 100644 src/parsers/mdown2/paragraph_p.cpp create mode 100644 src/parsers/mdown2/paragraph_p.h create mode 100644 src/parsers/mdown2/text_p.cpp create mode 100644 src/parsers/mdown2/text_p.h diff --git a/src/main.cpp b/src/main.cpp index 0f2a157..6477e0f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "elements.h" #include "generators/latex/document_g.h" -#include "parser/document_p.h" +#include "parsers/mdown2/document_p.h" namespace ka = boost::spirit::karma; namespace po = boost::program_options; @@ -71,7 +71,7 @@ int main(int argc, char** argv) { ifile.close(); - document_p parser; + mdown2::document_p parser; iiterator begin = input.begin(); iiterator end = input.end(); document_t ast; diff --git a/src/parser/document_p.cpp b/src/parser/document_p.cpp deleted file mode 100644 index fe11aed..0000000 --- a/src/parser/document_p.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#include "document_p.h" - -document_p::document_p() : document_p::base_type(document_) { - document_ = +paragraph_; -} diff --git a/src/parser/document_p.h b/src/parser/document_p.h deleted file mode 100644 index 19565d7..0000000 --- a/src/parser/document_p.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#ifndef _MPPDOWN_DOCUMENT_P -#define _MPPDOWN_DOCUMENT_P -#include -#include "../elements.h" -#include "paragraph_p.h" - -namespace qi = boost::spirit::qi; -namespace ph = boost::phoenix; - -struct document_p : qi::grammar { - qi::rule document_; - paragraph_p paragraph_; - - document_p(); -}; -#endif diff --git a/src/parser/line_p.cpp b/src/parser/line_p.cpp deleted file mode 100644 index 8426679..0000000 --- a/src/parser/line_p.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#include "line_p.h" - -line_p::line_p() : line_p::base_type(line_) { - line_ = +text_(ph::val(L"*'`$@_[\n")) > qi::eol; -} diff --git a/src/parser/line_p.h b/src/parser/line_p.h deleted file mode 100644 index be4b61b..0000000 --- a/src/parser/line_p.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#ifndef _MPPDOWN_LINE_P -#define _MPPDOWN_LINE_P -#include -#include "../elements.h" -#include "text_p.h" - -namespace qi = boost::spirit::qi; -namespace ph = boost::phoenix; - -struct line_p : qi::grammar { - qi::rule line_; - text_p text_; - - line_p(); -}; -#endif diff --git a/src/parser/paragraph_p.cpp b/src/parser/paragraph_p.cpp deleted file mode 100644 index d7470ea..0000000 --- a/src/parser/paragraph_p.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#include "paragraph_p.h" - -paragraph_p::paragraph_p() : paragraph_p::base_type(paragraph_) { - paragraph_ = +line_ > qi::eol; -} diff --git a/src/parser/paragraph_p.h b/src/parser/paragraph_p.h deleted file mode 100644 index f7f1f56..0000000 --- a/src/parser/paragraph_p.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#ifndef _MPPDOWN_PARAGRAPH_P -#define _MPPDOWN_PARAGRAPH_P -#include -#include "../elements.h" -#include "line_p.h" - -namespace qi = boost::spirit::qi; -namespace ph = boost::phoenix; - -struct paragraph_p : qi::grammar { - qi::rule paragraph_; - line_p line_; - - paragraph_p(); -}; -#endif diff --git a/src/parser/text_p.cpp b/src/parser/text_p.cpp deleted file mode 100644 index bd16a60..0000000 --- a/src/parser/text_p.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#include "text_p.h" - -text_p::text_p() : text_p::base_type(text_) { - using namespace qi; - using namespace ph; - using qi::standard_wide::char_; - - text_ = stext_(_r1) | pstext_(_r1) | atom_ | ptext_(_r1); - - stext_ = lit("***") >> attr(VSEMPH) >> +text_(ph::val(L"*'`$@_[")) >> "***" - | lit("**") >> attr(SEMPH) >> +text_(ph::val(L"*'`$@_[")) >> "**" - | lit('*') >> attr(EMPH) >> +text_(ph::val(L"*'`$@_[")) >> '*' - | lit("''") >> attr(SALT) >> +text_(ph::val(L"*'`$@_["))>> "''" - | lit('\'') >> attr(ALT) >> +text_(ph::val(L"*'`$@_[")) >> '\'' - | lit('`') >> attr(CODE) >> +ptext_(val(L"`")) >> '`' - | lit('$') >> attr(MATH) >> +ptext_(val(L"$")) >> '$' - | lit("^{") >> attr(SUPER) >> +text_(val(L"*'`$^}[")) >> '}' - | lit('^') >> attr(SUPER) >> +text_(val(L"*'`$ ")) - | lit(L"@\"") >> attr(QUOTE) >> +text_(val(L"*'`$@\"[")) >> '"' - | lit(L"@_") >> attr(SUB) >> +text_(val(L"*'`$@_[")) >> '_'; - - pstext_ = lit('[') >> attr(LINK) >> +text_(val(L"]")) >> ']' >> - lit('(') >> ptext_(val(L")")) >> ')'; - - atom_ = lit(L"\\ ") >> attr(NBSP) | lit('\\') >> eol >> attr(NEWLINE); - - ptext_ = +(echar_ | rchar_(_r1)); - echar_ = lit('\\') >> ~char_(L" \n"); - rchar_ = ~char_('\\') - char_(_r1); -} diff --git a/src/parser/text_p.h b/src/parser/text_p.h deleted file mode 100644 index 27f84c0..0000000 --- a/src/parser/text_p.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright (c) 2010, 2011, Grégoire Duchêne - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -#ifndef _MPPDOWN_TEXT_P -#define _MPPDOWN_TEXT_P -#include -#include -#include -#include "../elements.h" - -namespace qi = boost::spirit::qi; -namespace ph = boost::phoenix; - -struct text_p : qi::grammar { - qi::rule text_; - qi::rule stext_; - qi::rule pstext_; - qi::rule atom_; - qi::rule ptext_; - qi::rule echar_; - qi::rule rchar_; - - text_p(); -}; -#endif diff --git a/src/parsers/mdown2/document_p.cpp b/src/parsers/mdown2/document_p.cpp new file mode 100644 index 0000000..e0214ad --- /dev/null +++ b/src/parsers/mdown2/document_p.cpp @@ -0,0 +1,20 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#include "document_p.h" + +mdown2::document_p::document_p() : document_p::base_type(document_) { + document_ = +paragraph_; +} diff --git a/src/parsers/mdown2/document_p.h b/src/parsers/mdown2/document_p.h new file mode 100644 index 0000000..c949a06 --- /dev/null +++ b/src/parsers/mdown2/document_p.h @@ -0,0 +1,33 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#ifndef _MPPDOWN_MDOWN2_DOCUMENT_P +#define _MPPDOWN_MDOWN2_DOCUMENT_P +#include +#include "../../elements.h" +#include "paragraph_p.h" + +namespace qi = boost::spirit::qi; +namespace ph = boost::phoenix; + +namespace mdown2 { +struct document_p : qi::grammar { + qi::rule document_; + paragraph_p paragraph_; + + document_p(); +}; +} +#endif diff --git a/src/parsers/mdown2/line_p.cpp b/src/parsers/mdown2/line_p.cpp new file mode 100644 index 0000000..f408418 --- /dev/null +++ b/src/parsers/mdown2/line_p.cpp @@ -0,0 +1,20 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#include "line_p.h" + +mdown2::line_p::line_p() : line_p::base_type(line_) { + line_ = +text_(ph::val(L"*'`$@_[\n")) > qi::eol; +} diff --git a/src/parsers/mdown2/line_p.h b/src/parsers/mdown2/line_p.h new file mode 100644 index 0000000..ecdfd46 --- /dev/null +++ b/src/parsers/mdown2/line_p.h @@ -0,0 +1,33 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#ifndef _MPPDOWN_MDOWN2_LINE_P +#define _MPPDOWN_MDOWN2_LINE_P +#include +#include "../../elements.h" +#include "text_p.h" + +namespace qi = boost::spirit::qi; +namespace ph = boost::phoenix; + +namespace mdown2 { +struct line_p : qi::grammar { + qi::rule line_; + text_p text_; + + line_p(); +}; +} +#endif diff --git a/src/parsers/mdown2/paragraph_p.cpp b/src/parsers/mdown2/paragraph_p.cpp new file mode 100644 index 0000000..7dbbc61 --- /dev/null +++ b/src/parsers/mdown2/paragraph_p.cpp @@ -0,0 +1,20 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#include "paragraph_p.h" + +mdown2::paragraph_p::paragraph_p() : paragraph_p::base_type(paragraph_) { + paragraph_ = +line_ > qi::eol; +} diff --git a/src/parsers/mdown2/paragraph_p.h b/src/parsers/mdown2/paragraph_p.h new file mode 100644 index 0000000..b90a2d1 --- /dev/null +++ b/src/parsers/mdown2/paragraph_p.h @@ -0,0 +1,33 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#ifndef _MPPDOWN_MDOWN2_PARAGRAPH_P +#define _MPPDOWN_MDOWN2_PARAGRAPH_P +#include +#include "../../elements.h" +#include "line_p.h" + +namespace qi = boost::spirit::qi; +namespace ph = boost::phoenix; + +namespace mdown2 { +struct paragraph_p : qi::grammar { + qi::rule paragraph_; + line_p line_; + + paragraph_p(); +}; +} +#endif diff --git a/src/parsers/mdown2/text_p.cpp b/src/parsers/mdown2/text_p.cpp new file mode 100644 index 0000000..d4d5e03 --- /dev/null +++ b/src/parsers/mdown2/text_p.cpp @@ -0,0 +1,45 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#include "text_p.h" + +mdown2::text_p::text_p() : text_p::base_type(text_) { + using namespace qi; + using namespace ph; + using qi::standard_wide::char_; + + text_ = stext_(_r1) | pstext_(_r1) | atom_ | ptext_(_r1); + + stext_ = lit("***") >> attr(VSEMPH) >> +text_(ph::val(L"*'`$@_[")) >> "***" + | lit("**") >> attr(SEMPH) >> +text_(ph::val(L"*'`$@_[")) >> "**" + | lit('*') >> attr(EMPH) >> +text_(ph::val(L"*'`$@_[")) >> '*' + | lit("''") >> attr(SALT) >> +text_(ph::val(L"*'`$@_["))>> "''" + | lit('\'') >> attr(ALT) >> +text_(ph::val(L"*'`$@_[")) >> '\'' + | lit('`') >> attr(CODE) >> +ptext_(val(L"`")) >> '`' + | lit('$') >> attr(MATH) >> +ptext_(val(L"$")) >> '$' + | lit("^{") >> attr(SUPER) >> +text_(val(L"*'`$^}[")) >> '}' + | lit('^') >> attr(SUPER) >> +text_(val(L"*'`$ ")) + | lit(L"@\"") >> attr(QUOTE) >> +text_(val(L"*'`$@\"[")) >> '"' + | lit(L"@_") >> attr(SUB) >> +text_(val(L"*'`$@_[")) >> '_'; + + pstext_ = lit('[') >> attr(LINK) >> +text_(val(L"]")) >> ']' >> + lit('(') >> ptext_(val(L")")) >> ')'; + + atom_ = lit(L"\\ ") >> attr(NBSP) | lit('\\') >> eol >> attr(NEWLINE); + + ptext_ = +(echar_ | rchar_(_r1)); + echar_ = lit('\\') >> ~char_(L" \n"); + rchar_ = ~char_('\\') - char_(_r1); +} diff --git a/src/parsers/mdown2/text_p.h b/src/parsers/mdown2/text_p.h new file mode 100644 index 0000000..bbed1bd --- /dev/null +++ b/src/parsers/mdown2/text_p.h @@ -0,0 +1,39 @@ +/* +Copyright (c) 2010, 2011, Grégoire Duchêne + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +#ifndef _MPPDOWN_MDOWN2_TEXT_P +#define _MPPDOWN_MDOWN2_TEXT_P +#include +#include +#include +#include "../../elements.h" + +namespace qi = boost::spirit::qi; +namespace ph = boost::phoenix; + +namespace mdown2 { +struct text_p : qi::grammar { + qi::rule text_; + qi::rule stext_; + qi::rule pstext_; + qi::rule atom_; + qi::rule ptext_; + qi::rule echar_; + qi::rule rchar_; + + text_p(); +}; +} +#endif -- cgit v1.2.3-70-g09d2