Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60343 - trunk/libs/spirit/example/qi/scheme
From: joel_at_[hidden]
Date: 2010-03-08 07:00:26


Author: djowel
Date: 2010-03-08 07:00:25 EST (Mon, 08 Mar 2010)
New Revision: 60343
URL: http://svn.boost.org/trac/boost/changeset/60343

Log:
correct BOM prefix handling
Text files modified:
   trunk/libs/spirit/example/qi/scheme/out.txt | 2 +-
   trunk/libs/spirit/example/qi/scheme/sexpr.hpp | 3 +++
   trunk/libs/spirit/example/qi/scheme/sexpr_test.cpp | 21 ++++++++++++---------
   trunk/libs/spirit/example/qi/scheme/sexpr_test.txt | 3 +++
   4 files changed, 19 insertions(+), 10 deletions(-)

Modified: trunk/libs/spirit/example/qi/scheme/out.txt
==============================================================================
--- trunk/libs/spirit/example/qi/scheme/out.txt (original)
+++ trunk/libs/spirit/example/qi/scheme/out.txt 2010-03-08 07:00:25 EST (Mon, 08 Mar 2010)
@@ -1,2 +1,2 @@
-success: (123.45 "this is a € string" "Τη γλώσσα μου έδωσαν ελληνική" (92 ("another string" apple Sîne)))
+success: (123.45 true false 987 "this is a € string" "Τη γλώσσα μου έδωσαν ελληνική" (92 ("another string" apple Sîne)))
 

Modified: trunk/libs/spirit/example/qi/scheme/sexpr.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/scheme/sexpr.hpp (original)
+++ trunk/libs/spirit/example/qi/scheme/sexpr.hpp 2010-03-08 07:00:25 EST (Mon, 08 Mar 2010)
@@ -42,6 +42,7 @@
     using boost::spirit::qi::oct;
     using boost::spirit::qi::no_case;
     using boost::spirit::qi::lexeme;
+ using boost::spirit::qi::lit;
     using boost::phoenix::function;
 
     typedef boost::spirit::char_encoding::unicode unicode;
@@ -160,6 +161,8 @@
             list = '(' >> *start >> ')';
 
             atom = number [_val = _1]
+ | lit("true") [_val = true]
+ | lit("false") [_val = false]
                     | string [_val = _1]
                     | symbol [_val = _1]
                     ;

Modified: trunk/libs/spirit/example/qi/scheme/sexpr_test.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/scheme/sexpr_test.cpp (original)
+++ trunk/libs/spirit/example/qi/scheme/sexpr_test.cpp 2010-03-08 07:00:25 EST (Mon, 08 Mar 2010)
@@ -43,16 +43,19 @@
         return 1;
     }
 
- char prefix[4]; // Read the UTF-8 prefix (0xEF 0xBB 0xBF)
- in >> prefix[0]; // marking the beginning of a UTF-8 file
- in >> prefix[1];
- in >> prefix[2];
- prefix[3] = 0;
- if (std::string("\xef\xbb\xbf") != prefix)
+ // Ignore the BOM marking the beginning of a UTF-8 file in Windows
+ char c = in.peek();
+ if (c == '\xef')
     {
- std::cerr << "Not a UTF-8 file: "
- << filename << std::endl;
- return 1;
+ char s[3];
+ in >> s[0] >> s[1] >> s[2];
+ s[3] = '\0';
+ if (s != std::string("\xef\xbb\xbf"))
+ {
+ std::cerr << "Error: Unexpected characters from input file: "
+ << filename << std::endl;
+ return 1;
+ }
     }
 
     std::string source_code; // We will read the contents here.

Modified: trunk/libs/spirit/example/qi/scheme/sexpr_test.txt
==============================================================================
--- trunk/libs/spirit/example/qi/scheme/sexpr_test.txt (original)
+++ trunk/libs/spirit/example/qi/scheme/sexpr_test.txt 2010-03-08 07:00:25 EST (Mon, 08 Mar 2010)
@@ -1,5 +1,8 @@
 ï»¿(
     123.45
+ true
+ false
+ 987
     "this is a \u20AC string" ; A UTF-8 string
     "Τη γλώσσα μου έδωσαν ελληνική" ; Another UTF-8 string
     (


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