#define __SFJP_ROAST__lexical__lexical_HPP__
#include "roast/lexical/rule.hpp"
+#include "roast/lexical/rule_numeric.hpp"
#include "roast/lexical/string_rule.hpp"
#include "roast/lexical/generator_base.hpp"
#include "roast/lexical/parser_base.hpp"
template <int N>
class marker : public lex_num_marker<N> {};
-
- ////////////////////////////////////////////////////////////
-
- template <typename T, T _Min, T _Max>
- class range : public lengthable
- {
- public:
- static const int length = sizeof(T);
-
- template <typename _It, typename _Param>
- bool analyze(_It& it, _Param& param)
- {
- T n = *it;
- if ( n >= _Min && n <= _Max )
- {
- it++;
- return true;
- }
- else
- return false;
- }
- };
-
- template <char _Min, char _Max>
- class char_range : public range<char, _Min, _Max> {};
-
- template <short _Min, short _Max>
- class short_range : public range<short, _Min, _Max> {};
-
- template <int _Min, int _Max>
- class int_range : public range<int, _Min, _Max> {};
-
- template <unsigned char _Min, unsigned char _Max>
- class uchar_range : public range<unsigned char, _Min, _Max> {};
-
- template <unsigned short _Min, unsigned short _Max>
- class ushort_range : public range<unsigned short, _Min, _Max> {};
-
- template <int _Min, int _Max>
- class uint_range : public range<unsigned int, _Min, _Max> {};
-
- /////////////////////////////////////////////////////////////
-
- template <typename T, T _Val>
- class fixed_numeric : public lengthable
- {
- public:
- static const int length = sizeof(T);
-
- template <typename _It, typename _Param>
- bool analyze(_It& it, _Param& param)
- {
- switch(*it)
- {
- case _Val:
- it++;
- return true;
- }
- return false;
- }
-
- //----
-
- template <typename _Strm, typename _Document>
- bool generate(_Strm& strm, _Document& doc)
- {
- //strm << _Val;
- T v = _Val;
- //strm << v;
- strm << sized_ptr_<char>((char*)&v,sizeof(T));
- return true;
- }
- /*template <typename _Document>
- bool generate(::std::fstream& strm, _Document& doc)
- {
- //strm << _Val;
- T v = _Val;
- strm.write((const char*)&v, sizeof(_Val));
- return true;
- }*/
- };
-
- /////////////////////////////////////////////////////////////
-
- /*
- template <unsigned char _ByteCode>
- class unibyte
- {
- public:
- template <typename _It, typename _Param>
- bool analyze(_It& it, _Param& param)
- {
- switch(*it)
- {
- case _Byte:
- it++;
- return true;
- }
- return false;
- }
-
- template <typename _Strm, typename _Document>
- bool generate(_Strm& strm, _Document& doc)
- {
- strm << _ByteCode;
- return true;
- }
- };
- */
- template <unsigned char _ByteCode>
- class unibyte : public fixed_numeric<unsigned char, _ByteCode> {};
-
- template <char _Val>
- class fixed_char : public fixed_numeric<char, _Val> {};
- template <short _Val>
- class fixed_short : public fixed_numeric<short, _Val> {};
- template <int _Val>
- class fixed_int : public fixed_numeric<int, _Val> {};
- template <long _Val>
- class fixed_long : public fixed_numeric<long, _Val> {};
-
- template <unsigned char _Val>
- class fixed_uchar : public fixed_numeric<unsigned char, _Val> {};
- template <unsigned short _Val>
- class fixed_ushort : public fixed_numeric<unsigned short, _Val> {};
- template <unsigned int _Val>
- class fixed_uint : public fixed_numeric<unsigned int, _Val> {};
- template <unsigned long _Val>
- class fixed_ulong : public fixed_numeric<unsigned long, _Val> {};
-
- typedef unibyte<0> zeroterm;
}
- ///////////////////////////////////////
+ //////////////////////////////////////////////////
}
}
--- /dev/null
+// Roast+ License
+/*
+*/
+#ifndef __SFJP_ROAST__lexical__rule_numeric_HPP__
+#define __SFJP_ROAST__lexical__rule_numeric_HPP__
+
+namespace roast
+{
+ namespace lexical
+ {
+ namespace rule
+ {
+ ////////////////////////////////////////////////////////////////////
+
+ template <typename T, T _Min, T _Max>
+ class range : public lengthable
+ {
+ public:
+ static const int length = sizeof(T);
+
+ template <typename _It, typename _Param>
+ bool analyze(_It& it, _Param& param)
+ {
+ T n = *it;
+ if ( n >= _Min && n <= _Max )
+ {
+ it++;
+ return true;
+ }
+ else
+ return false;
+ }
+ };
+
+ template <char _Min, char _Max>
+ class char_range : public range<char, _Min, _Max> {};
+
+ template <short _Min, short _Max>
+ class short_range : public range<short, _Min, _Max> {};
+
+ template <int _Min, int _Max>
+ class int_range : public range<int, _Min, _Max> {};
+
+ template <unsigned char _Min, unsigned char _Max>
+ class uchar_range : public range<unsigned char, _Min, _Max> {};
+
+ template <unsigned short _Min, unsigned short _Max>
+ class ushort_range : public range<unsigned short, _Min, _Max> {};
+
+ template <int _Min, int _Max>
+ class uint_range : public range<unsigned int, _Min, _Max> {};
+
+ /////////////////////////////////////////////////////////////
+
+ template <typename T, T _Val>
+ class fixed_numeric : public lengthable
+ {
+ public:
+ static const int length = sizeof(T);
+
+ template <typename _It, typename _Param>
+ bool analyze(_It& it, _Param& param)
+ {
+ switch(*it)
+ {
+ case _Val:
+ it++;
+ return true;
+ }
+ return false;
+ }
+
+ //----
+
+ template <typename _Strm, typename _Document>
+ bool generate(_Strm& strm, _Document& doc)
+ {
+ //strm << _Val;
+ T v = _Val;
+ //strm << v;
+ strm << sized_ptr_<char>((char*)&v,sizeof(T));
+ return true;
+ }
+ /*template <typename _Document>
+ bool generate(::std::fstream& strm, _Document& doc)
+ {
+ //strm << _Val;
+ T v = _Val;
+ strm.write((const char*)&v, sizeof(_Val));
+ return true;
+ }*/
+ };
+
+ /////////////////////////////////////////////////////////////
+
+ /*
+ template <unsigned char _ByteCode>
+ class unibyte
+ {
+ public:
+ template <typename _It, typename _Param>
+ bool analyze(_It& it, _Param& param)
+ {
+ switch(*it)
+ {
+ case _Byte:
+ it++;
+ return true;
+ }
+ return false;
+ }
+
+ template <typename _Strm, typename _Document>
+ bool generate(_Strm& strm, _Document& doc)
+ {
+ strm << _ByteCode;
+ return true;
+ }
+ };
+ */
+ template <unsigned char _ByteCode>
+ class unibyte : public fixed_numeric<unsigned char, _ByteCode> {};
+
+ template <char _Val>
+ class fixed_char : public fixed_numeric<char, _Val> {};
+ template <short _Val>
+ class fixed_short : public fixed_numeric<short, _Val> {};
+ template <int _Val>
+ class fixed_int : public fixed_numeric<int, _Val> {};
+ template <long _Val>
+ class fixed_long : public fixed_numeric<long, _Val> {};
+
+ template <unsigned char _Val>
+ class fixed_uchar : public fixed_numeric<unsigned char, _Val> {};
+ template <unsigned short _Val>
+ class fixed_ushort : public fixed_numeric<unsigned short, _Val> {};
+ template <unsigned int _Val>
+ class fixed_uint : public fixed_numeric<unsigned int, _Val> {};
+ template <unsigned long _Val>
+ class fixed_ulong : public fixed_numeric<unsigned long, _Val> {};
+
+ typedef unibyte<0> zeroterm;
+
+ ////////////////////////////////////////////////////////////////////
+ }
+ }
+}
+
+#endif//__SFJP_ROAST__lexical__rule_numeric_HPP__