aboutsummaryrefslogtreecommitdiff
path: root/xsde/cxx/parser
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-01-07 13:50:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-01-07 13:50:11 +0200
commit76d23e639004517db8f9469d64ac1789f8449365 (patch)
treedbafc8c4e31a97f74046c98af19d0fe76f360001 /xsde/cxx/parser
parentc30caae30bc64974eeaa1e81aa2abdc203f5120d (diff)
Add support for ISO-8859-1 as application encoding
New runtime configuration parameter, XSDE_ENCODING. New option, --char-encoding. New test, tests/cxx/hybrid/iso8859-1.
Diffstat (limited to 'xsde/cxx/parser')
-rw-r--r--xsde/cxx/parser/cli.hxx2
-rw-r--r--xsde/cxx/parser/elements.cxx1
-rw-r--r--xsde/cxx/parser/generator.cxx36
-rw-r--r--xsde/cxx/parser/name-processor.cxx1
-rw-r--r--xsde/cxx/parser/parser-header.cxx16
-rw-r--r--xsde/cxx/parser/validator.cxx10
6 files changed, 64 insertions, 2 deletions
diff --git a/xsde/cxx/parser/cli.hxx b/xsde/cxx/parser/cli.hxx
index 62a1891..a50c3ff 100644
--- a/xsde/cxx/parser/cli.hxx
+++ b/xsde/cxx/parser/cli.hxx
@@ -24,6 +24,7 @@ namespace CXX
typedef Char const Key[];
extern Key type_map;
+ extern Key char_encoding;
extern Key no_stl;
extern Key no_iostream;
extern Key no_exceptions;
@@ -86,6 +87,7 @@ namespace CXX
typedef Cult::CLI::Options<
type_map, Cult::Containers::Vector<NarrowString>,
+ char_encoding, NarrowString,
no_stl, Boolean,
no_iostream, Boolean,
no_exceptions, Boolean,
diff --git a/xsde/cxx/parser/elements.cxx b/xsde/cxx/parser/elements.cxx
index 4b624ff..3c62b5b 100644
--- a/xsde/cxx/parser/elements.cxx
+++ b/xsde/cxx/parser/elements.cxx
@@ -20,6 +20,7 @@ namespace CXX
root,
"p:name",
"char",
+ ops.value<CLI::char_encoding> (),
ops.value<CLI::include_with_brackets> (),
ops.value<CLI::include_prefix> (),
"", // export symbol
diff --git a/xsde/cxx/parser/generator.cxx b/xsde/cxx/parser/generator.cxx
index e59180c..1936286 100644
--- a/xsde/cxx/parser/generator.cxx
+++ b/xsde/cxx/parser/generator.cxx
@@ -113,6 +113,7 @@ namespace CXX
namespace CLI
{
extern Key type_map = "type-map";
+ extern Key char_encoding = "char-encoding";
extern Key no_stl = "no-stl";
extern Key no_iostream = "no-iostream";
extern Key no_exceptions = "no-exceptions";
@@ -188,6 +189,12 @@ namespace CXX
<< " order of appearance and the first match is used."
<< endl;
+ e << "--char-encoding <enc>" << endl
+ << " Specify the character encoding that should be\n"
+ << " used for the extracted text data. Valid values\n"
+ << " are 'utf8' (default) and 'iso8859-1'."
+ << endl;
+
e << "--no-stl" << endl
<< " Generate code that does not use STL."
<< endl;
@@ -514,6 +521,8 @@ namespace CXX
{
CLI::OptionsSpec spec;
+ spec.option<CLI::char_encoding> ().default_value ("utf8");
+
spec.option<CLI::skel_file_suffix> ().default_value ("-pskel");
spec.option<CLI::skel_type_suffix> ().default_value ("_pskel");
spec.option<CLI::impl_file_suffix> ().default_value ("-pimpl");
@@ -1207,6 +1216,25 @@ namespace CXX
hxx << "#include <xsde/cxx/config.hxx>" << endl
<< endl;
+ if (ops.value<CLI::char_encoding> () == "iso8859-1")
+ {
+ hxx << "#ifndef XSDE_ENCODING_ISO8859_1" << endl
+ << "#error the generated code uses the ISO-8859-1 encoding" <<
+ "while the XSD/e runtime does not (reconfigure the runtime " <<
+ "or change the --char-encoding value)" << endl
+ << "#endif" << endl
+ << endl;
+ }
+ else
+ {
+ hxx << "#ifndef XSDE_ENCODING_UTF8" << endl
+ << "#error the generated code uses the UTF-8 encoding" <<
+ "while the XSD/e runtime does not (reconfigure the runtime " <<
+ "or change the --char-encoding value)" << endl
+ << "#endif" << endl
+ << endl;
+ }
+
if (ops.value<CLI::no_stl> ())
{
hxx << "#ifdef XSDE_STL" << endl
@@ -1585,6 +1613,14 @@ namespace CXX
return sloc;
}
+ catch (UnrepresentableCharacter const& e)
+ {
+ wcerr << "error: character at position " << e.position () << " "
+ << "in string '" << e.string () << "' is unrepresentable in "
+ << "the target encoding" << endl;
+
+ throw Failed ();
+ }
catch (NoNamespaceMapping const& e)
{
wcerr << e.file () << ":" << e.line () << ":" << e.column ()
diff --git a/xsde/cxx/parser/name-processor.cxx b/xsde/cxx/parser/name-processor.cxx
index 658b70a..a168c28 100644
--- a/xsde/cxx/parser/name-processor.cxx
+++ b/xsde/cxx/parser/name-processor.cxx
@@ -34,6 +34,7 @@ namespace CXX
root,
"p:name",
"char",
+ ops.value<CLI::char_encoding> (),
ops.value<CLI::include_with_brackets> (),
ops.value<CLI::include_prefix> (),
"", // export symbol
diff --git a/xsde/cxx/parser/parser-header.cxx b/xsde/cxx/parser/parser-header.cxx
index f3dd45c..6ef9578 100644
--- a/xsde/cxx/parser/parser-header.cxx
+++ b/xsde/cxx/parser/parser-header.cxx
@@ -1634,6 +1634,14 @@ namespace CXX
<< "typedef xsde::cxx::parser::context parser_context;"
<< endl;
+ if (char_encoding == L"iso8859-1")
+ {
+ os << "// ISO-8859-1 transcoder." << endl
+ << "//" << endl
+ << "using xsde::cxx::iso8859_1;"
+ << endl;
+ }
+
post (ns);
}
};
@@ -1675,8 +1683,12 @@ namespace CXX
else
{
ctx.os << "#include <xsde/config.h>" << endl
- << "#include <xsde/cxx/ro-string.hxx>" << endl
- << endl;
+ << "#include <xsde/cxx/ro-string.hxx>" << endl;
+
+ if (ctx.char_encoding == L"iso8859-1")
+ ctx.os << "#include <xsde/cxx/iso8859-1.hxx>" << endl;
+
+ ctx.os << endl;
// Data types.
//
diff --git a/xsde/cxx/parser/validator.cxx b/xsde/cxx/parser/validator.cxx
index 96170de..33fe2e2 100644
--- a/xsde/cxx/parser/validator.cxx
+++ b/xsde/cxx/parser/validator.cxx
@@ -601,6 +601,16 @@ namespace CXX
//
//
+ NarrowString enc (options.value<CLI::char_encoding> ());
+
+ if (enc != "utf8" && enc != "iso8859-1")
+ {
+ wcerr << "error: unknown encoding '" << enc.c_str () << "'" << endl;
+ return false;
+ }
+
+ //
+ //
if (options.value<CLI::generate_noop_impl> () &&
options.value<CLI::generate_print_impl> ())
{