Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52064 - in branches/release: . tools/quickbook tools/quickbook/test
From: daniel_james_at_[hidden]
Date: 2009-03-30 13:49:16


Author: danieljames
Date: 2009-03-30 13:49:15 EDT (Mon, 30 Mar 2009)
New Revision: 52064
URL: http://svn.boost.org/trac/boost/changeset/52064

Log:
Fix bug handling python and C++ strings.

Fixes #2860.

Merged revisions 51949 via svnmerge from
https://svn.boost.org/svn/boost/trunk

........
  r51949 | danieljames | 2009-03-24 08:34:09 +0000 (Tue, 24 Mar 2009) | 21 lines
  
  Use our own escape character parser.
  
  We're currently using the spirit escaped character parser. This is a
  strict C parser and causes parse errors for code that we probably should
  accept, such as any hexadecimal encoded characters with a value greater
  than the maximum value of the current platform's 'char'. This is \x7F
  on some platforms so it rejects '\x80' upwards. As well as rejecting
  characters that might be valid, it also means that quickbook will act
  differently on different platforms.
  
  In python strings, '\xaaa' is equivalent to '\xaa' + 'a', but the spirit
  parser interprets this as a character with value '0xaaa'. So we probably
  should accept these.
  
  I also think we should be liberal about what we accept. IMO it isn't our
  job to enforce correct C++/python, just to create a reasonable
  rendering of our input. So rather than write a parser which understands
  the various types of escapes, I just wrote one that ignores any
  character following a backslash.
  
  Refs #2860.
........

Added:
   branches/release/tools/quickbook/test/code-block-3.gold
      - copied unchanged from r51949, /trunk/tools/quickbook/test/code-block-3.gold
   branches/release/tools/quickbook/test/code-block-3.quickbook
      - copied unchanged from r51949, /trunk/tools/quickbook/test/code-block-3.quickbook
Properties modified:
   branches/release/ (props changed)
Text files modified:
   branches/release/tools/quickbook/syntax_highlight.hpp | 22 +++++++++++++---------
   branches/release/tools/quickbook/test/Jamfile.v2 | 1 +
   2 files changed, 14 insertions(+), 9 deletions(-)

Modified: branches/release/tools/quickbook/syntax_highlight.hpp
==============================================================================
--- branches/release/tools/quickbook/syntax_highlight.hpp (original)
+++ branches/release/tools/quickbook/syntax_highlight.hpp 2009-03-30 13:49:15 EDT (Mon, 30 Mar 2009)
@@ -14,7 +14,6 @@
 #include <boost/spirit/include/classic_confix.hpp>
 #include <boost/spirit/include/classic_chset.hpp>
 #include <boost/spirit/include/classic_symbols.hpp>
-#include <boost/spirit/include/classic_escape_char.hpp>
 #include <boost/spirit/include/classic_loops.hpp>
 #include "./phrase.hpp"
 
@@ -127,12 +126,14 @@
                     = +chset_p("~!%^&*()+={[}]:;,<.>?/|\\-")
                     ;
 
+ string_char = ('\\' >> anychar_p) | (anychar_p - '\\');
+
                 string_
- = !as_lower_d['l'] >> confix_p('"', *c_escape_ch_p, '"')
+ = !as_lower_d['l'] >> confix_p('"', *string_char, '"')
                     ;
 
                 char_
- = !as_lower_d['l'] >> confix_p('\'', *c_escape_ch_p, '\'')
+ = !as_lower_d['l'] >> confix_p('\'', *string_char, '\'')
                     ;
 
                 number
@@ -150,7 +151,8 @@
             }
 
             rule<Scanner> program, macro, preprocessor, comment, special, string_,
- char_, number, identifier, keyword, qbk_phrase, escape;
+ char_, number, identifier, keyword, qbk_phrase, escape,
+ string_char;
 
             symbols<> keyword_;
             phrase_grammar<EscapeActions> common;
@@ -275,16 +277,18 @@
                     = ! string_prefix >> (long_string | short_string)
                     ;
 
+ string_char = ('\\' >> anychar_p) | (anychar_p - '\\');
+
                 short_string
- = confix_p('\'', * c_escape_ch_p, '\'') |
- confix_p('"', * c_escape_ch_p, '"')
+ = confix_p('\'', * string_char, '\'') |
+ confix_p('"', * string_char, '"')
                     ;
             
                 long_string
                     // Note: the "str_p" on the next two lines work around
                     // an INTERNAL COMPILER ERROR when using VC7.1
- = confix_p(str_p("'''"), * lex_escape_ch_p, "'''") |
- confix_p(str_p("\"\"\""), * lex_escape_ch_p, "\"\"\"")
+ = confix_p(str_p("'''"), * string_char, "'''") |
+ confix_p(str_p("\"\"\""), * string_char, "\"\"\"")
                     ;
                 
                 number
@@ -303,7 +307,7 @@
 
             rule<Scanner> program, macro, comment, special, string_, string_prefix,
                             short_string, long_string, number, identifier, keyword,
- qbk_phrase, escape;
+ qbk_phrase, escape, string_char;
 
             symbols<> keyword_;
             phrase_grammar<EscapeActions> common;

Modified: branches/release/tools/quickbook/test/Jamfile.v2
==============================================================================
--- branches/release/tools/quickbook/test/Jamfile.v2 (original)
+++ branches/release/tools/quickbook/test/Jamfile.v2 2009-03-30 13:49:15 EDT (Mon, 30 Mar 2009)
@@ -14,6 +14,7 @@
     [ quickbook-test quickbook-manual ]
     [ quickbook-test code-block-1 ]
     [ quickbook-test code-block-2 ]
+ [ quickbook-test code-block-3 ]
     [ quickbook-test code-snippet ]
     [ quickbook-test preformatted ]
     [ quickbook-test link-side-by-side ]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk