2
0
mirror of https://github.com/boostorg/wave.git synced 2026-01-27 07:22:15 +00:00

Fixed long character literal handling, fixed a bug in the testapplication.

[SVN r28634]
This commit is contained in:
Hartmut Kaiser
2005-05-03 16:47:11 +00:00
parent 9124a82540
commit 116a39e1fc
2 changed files with 46 additions and 23 deletions

View File

@@ -54,17 +54,32 @@ namespace impl {
///////////////////////////////////////////////////////////////////////////////
struct compose_character_literal {
template <typename ResultT, typename ArgT>
template <typename ResultT, typename Arg1T, typename Arg2T>
struct result {
typedef unsigned int type;
};
unsigned int
operator()(unsigned int res, unsigned int character) const
operator()(unsigned int& value, bool long_lit, unsigned int character) const
{
unsigned int retval = (res << 8) | (character & 0xff);
return retval;
if (long_lit) {
unsigned int mask = 0;
for (int i = 0; i < sizeof(wchar_t); ++i) {
value <<= 8;
mask = (mask << 8) | 0xff;
}
value |= character & mask;
}
else {
unsigned int mask = 0;
for (int i = 0; i < sizeof(char); ++i) {
value <<= 8;
mask = (mask << 8) | 0xff;
}
value |= character & mask;
}
return value;
}
};
phoenix::function<compose_character_literal> const compose;
@@ -118,82 +133,82 @@ struct chlit_grammar :
ch_p('\\')
>> ( ch_p('a') // BEL
[
self.value = impl::compose(self.value, val(0x07))
impl::compose(self.value, self.long_lit, val(0x07))
]
| ch_p('b') // BS
[
self.value = impl::compose(self.value, val(0x08))
impl::compose(self.value, self.long_lit, val(0x08))
]
| ch_p('t') // HT
[
self.value = impl::compose(self.value, val(0x09))
impl::compose(self.value, self.long_lit, val(0x09))
]
| ch_p('n') // NL
[
self.value = impl::compose(self.value, val(0x0a))
impl::compose(self.value, self.long_lit, val(0x0a))
]
| ch_p('v') // VT
[
self.value = impl::compose(self.value, val(0x0b))
impl::compose(self.value, self.long_lit, val(0x0b))
]
| ch_p('f') // FF
[
self.value = impl::compose(self.value, val(0x0c))
impl::compose(self.value, self.long_lit, val(0x0c))
]
| ch_p('r') // CR
[
self.value = impl::compose(self.value, val(0x0d))
impl::compose(self.value, self.long_lit, val(0x0d))
]
| ch_p('?')
[
self.value = impl::compose(self.value, val('?'))
impl::compose(self.value, self.long_lit, val('?'))
]
| ch_p('\'')
[
self.value = impl::compose(self.value, val('\''))
impl::compose(self.value, self.long_lit, val('\''))
]
| ch_p('\"')
[
self.value = impl::compose(self.value, val('\"'))
impl::compose(self.value, self.long_lit, val('\"'))
]
| ch_p('\\')
[
self.value = impl::compose(self.value, val('\\'))
impl::compose(self.value, self.long_lit, val('\\'))
]
| ch_p('x')
>> if_p(self.long_lit)
[
hex_wchar_parser_type()
[
self.value = impl::compose(self.value, arg1)
impl::compose(self.value, self.long_lit, arg1)
]
]
.else_p
[
hex_char_parser_type()
[
self.value = impl::compose(self.value, arg1)
impl::compose(self.value, self.long_lit, arg1)
]
]
| ch_p('u')
>> uint_parser<unsigned int, 16, 4, 4>()
[
self.value = impl::compose(self.value, arg1)
impl::compose(self.value, self.long_lit, arg1)
]
| ch_p('U')
>> uint_parser<unsigned int, 16, 8, 8>()
[
self.value = impl::compose(self.value, arg1)
impl::compose(self.value, self.long_lit, arg1)
]
| uint_parser<unsigned int, 8, 1, 3>()
[
self.value = impl::compose(self.value, arg1)
impl::compose(self.value, self.long_lit, arg1)
]
)
)
| ~eps_p(ch_p('\'')) >> anychar_p
[
self.value = impl::compose(self.value, arg1)
impl::compose(self.value, self.long_lit, arg1)
]
)
>> ch_p('\'')

View File

@@ -270,8 +270,16 @@ testwave_app::test_a_file(std::string filename)
if (debuglevel > 2) {
std::cerr
<< filename << ": failed" << std::endl
<< "result: " << std::endl << result << std::endl
<< "expected error: " << std::endl << expected << std::endl;
<< "result: " << std::endl << result << std::endl;
if (!error.empty()) {
std::cerr << "expected result: " << std::endl
<< expected << std::endl;
}
if (!expected_error.empty()) {
std::cerr << "expected error: " << std::endl
<< expected_error << std::endl;
}
}
else if (debuglevel > 1) {
std::cerr << filename << ": failed" << std::endl;