Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 0 additions & 104 deletions include/iris/x4/ast/position_tagged.hpp

This file was deleted.

34 changes: 16 additions & 18 deletions include/iris/x4/char/char_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#include <iris/x4/char/char_parser.hpp>
#include <iris/x4/char/detail/cast_char.hpp>
#include <iris/x4/char/detail/basic_chset.hpp>
#include <iris/x4/string/utf8.hpp>
#include <iris/x4/string/case_compare.hpp>

#include <iris/unicode/string.hpp>

#include <format>
#include <ranges>
#include <type_traits>

Expand Down Expand Up @@ -47,6 +49,17 @@ struct char_range : char_parser<Encoding, char_range<Encoding, Attr>>
}

char_type from, to;

[[nodiscard]] std::string get_x4_info() const
{
// TODO: make more user-friendly && make the format consistent with above
// TODO: escape
return std::format(
"char_range \"{}-{}\"",
iris::unicode::transcode<char>(typename Encoding::string_type(1, this->from)),
iris::unicode::transcode<char>(typename Encoding::string_type(1, this->to))
);
}
};

// Parser for a character set
Expand Down Expand Up @@ -103,29 +116,14 @@ struct char_set : char_parser<Encoding, char_set<Encoding, Attr>>
}

detail::basic_chset<char_type> chset;
};

template<class Encoding, X4Attribute Attr>
struct get_info<char_set<Encoding, Attr>>
{
using result_type = std::string;
[[nodiscard]] constexpr std::string operator()(char_set<Encoding, Attr> const& /* p */) const
[[nodiscard]] std::string get_x4_info() const
{
// TODO: escape
return "char-set"; // TODO: make more user-friendly
}
};

template<class Encoding, X4Attribute Attr>
struct get_info<char_range<Encoding, Attr>>
{
using result_type = std::string;
[[nodiscard]] constexpr std::string operator()(char_range<Encoding, Attr> const& p) const
{
// TODO: make more user-friendly && make the format consistent with above
return "char_range \"" + x4::to_utf8(Encoding::toucs4(p.from)) + '-' + x4::to_utf8(Encoding::toucs4(p.to))+ '"';
}
};

} // iris::x4

#endif
23 changes: 12 additions & 11 deletions include/iris/x4/char/literal_char.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
==============================================================================*/

#include <iris/x4/char/char_parser.hpp>
#include <iris/x4/string/utf8.hpp>
#include <iris/x4/string/case_compare.hpp>

#include <iris/unicode/string.hpp>

#include <format>
#include <type_traits>
#include <concepts>

Expand Down Expand Up @@ -51,18 +53,17 @@ struct literal_char : char_parser<Encoding, literal_char<Encoding, Attr>>

[[nodiscard]] constexpr classify_type classify_ch() const noexcept { return classify_ch_; }

private:
classify_type classify_ch_{};
};

template<class Encoding, X4Attribute Attr>
struct get_info<literal_char<Encoding, Attr>>
{
using result_type = std::string;
[[nodiscard]] std::string operator()(literal_char<Encoding, Attr> const& p) const
[[nodiscard]] std::string get_x4_info() const
{
return '\'' + x4::to_utf8(Encoding::toucs4(p.classify_ch())) + '\'';
// TODO: escape quote
return std::format(
"'{}'",
iris::unicode::transcode<char>(typename Encoding::string_type(1, this->classify_ch_))
);
}

private:
classify_type classify_ch_{};
};

} // iris::x4
Expand Down
3 changes: 3 additions & 0 deletions include/iris/x4/char_encoding/standard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#include <string>

#include <cassert>
#include <cstdint>
#include <cctype>
Expand All @@ -22,6 +24,7 @@ namespace iris::x4::char_encoding {
struct standard
{
using char_type = char;
using string_type = std::string;
using classify_type = unsigned char;

[[nodiscard]] static constexpr bool
Expand Down
1 change: 1 addition & 0 deletions include/iris/x4/char_encoding/standard_wide.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace iris::x4::char_encoding {
struct standard_wide
{
using char_type = wchar_t;
using string_type = std::wstring;
using classify_type = wchar_t;

template<class Char>
Expand Down
7 changes: 6 additions & 1 deletion include/iris/x4/char_encoding/unicode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#include <iris/x4/char_encoding/unicode/classification.hpp>
#include <iris/x4/char_encoding/unicode/classify_category.hpp>
#include <iris/x4/char_encoding/unicode/classify_script.hpp>
#include <iris/x4/char_encoding/unicode/classify_case.hpp>

#include <string>

#include <cstdint>

Expand All @@ -20,6 +24,7 @@ namespace iris::x4::char_encoding {
struct unicode
{
using char_type = char32_t;
using string_type = std::u32string;
using classify_type = x4::unicode::classify_type;

[[nodiscard]] static constexpr bool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef IRIS_ZZ_X4_CHAR_ENCODING_UNICODE_CLASSIFICATION_HPP
#define IRIS_ZZ_X4_CHAR_ENCODING_UNICODE_CLASSIFICATION_HPP
#ifndef IRIS_ZZ_X4_CHAR_ENCODING_UNICODE_CATEGORY_HPP
#define IRIS_ZZ_X4_CHAR_ENCODING_UNICODE_CATEGORY_HPP

/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
Expand All @@ -13,11 +13,6 @@
table builder) (c) Peter Kankowski, 2008
==============================================================================*/

#include <iris/x4/char_encoding/unicode/detail/category_table.hpp>
#include <iris/x4/char_encoding/unicode/detail/script_table.hpp>
#include <iris/x4/char_encoding/unicode/detail/lowercase_table.hpp>
#include <iris/x4/char_encoding/unicode/detail/uppercase_table.hpp>

#include <cstdint>

namespace iris::x4::unicode {
Expand Down Expand Up @@ -266,120 +261,6 @@ enum script

} // properties

[[nodiscard]] constexpr properties::category get_category(classify_type ch) noexcept
{
return static_cast<properties::category>(detail::category_lookup(ch) & 0x3F);
}

[[nodiscard]] constexpr properties::major_category get_major_category(classify_type ch) noexcept
{
return static_cast<properties::major_category>(unicode::get_category(ch) >> 3);
}

[[nodiscard]] constexpr bool is_punctuation(classify_type ch) noexcept
{
return unicode::get_major_category(ch) == properties::punctuation;
}

[[nodiscard]] constexpr bool is_decimal_number(classify_type ch) noexcept
{
return unicode::get_category(ch) == properties::decimal_number;
}

[[nodiscard]] constexpr bool is_hex_digit(classify_type ch) noexcept
{
return (detail::category_lookup(ch) & properties::hex_digit) != 0;
}

[[nodiscard]] constexpr bool is_control(classify_type ch) noexcept
{
return unicode::get_category(ch) == properties::control;
}

[[nodiscard]] constexpr bool is_alphabetic(classify_type ch) noexcept
{
return (detail::category_lookup(ch) & properties::alphabetic) != 0;
}

[[nodiscard]] constexpr bool is_alphanumeric(classify_type ch) noexcept
{
return unicode::is_decimal_number(ch) || unicode::is_alphabetic(ch);
}

[[nodiscard]] constexpr bool is_uppercase(classify_type ch) noexcept
{
return (detail::category_lookup(ch) & properties::uppercase) != 0;
}

[[nodiscard]] constexpr bool is_lowercase(classify_type ch) noexcept
{
return (detail::category_lookup(ch) & properties::lowercase) != 0;
}

[[nodiscard]] constexpr bool is_white_space(classify_type ch) noexcept
{
return (detail::category_lookup(ch) & properties::white_space) != 0;
}

[[nodiscard]] constexpr bool is_blank(classify_type ch) noexcept
{
switch (ch)
{
case '\n': case '\v': case '\f': case '\r':
return false;
default:
return unicode::is_white_space(ch) &&
!(
unicode::get_category(ch) == properties::line_separator ||
unicode::get_category(ch) == properties::paragraph_separator
);
}
}

[[nodiscard]] constexpr bool is_graph(classify_type ch) noexcept
{
return !(
unicode::is_white_space(ch) ||
unicode::get_category(ch) == properties::control ||
unicode::get_category(ch) == properties::surrogate ||
unicode::get_category(ch) == properties::unassigned
);
}

[[nodiscard]] constexpr bool is_print(classify_type ch) noexcept
{
return (unicode::is_graph(ch) || unicode::is_blank(ch)) && !unicode::is_control(ch);
}

[[nodiscard]] constexpr bool is_noncharacter_code_point(classify_type ch) noexcept
{
return (detail::category_lookup(ch) & properties::noncharacter_code_point) != 0;
}

[[nodiscard]] constexpr bool is_default_ignorable_code_point(classify_type ch) noexcept
{
return (detail::category_lookup(ch) & properties::default_ignorable_code_point) != 0;
}

[[nodiscard]] constexpr properties::script get_script(classify_type ch) noexcept
{
return static_cast<properties::script>(detail::script_lookup(ch));
}

[[nodiscard]] constexpr classify_type to_lowercase(classify_type ch) noexcept
{
// The table returns 0 to signal that this code maps to itself
classify_type const r = detail::lowercase_lookup(ch);
return r == 0 ? ch : r;
}

[[nodiscard]] constexpr classify_type to_uppercase(classify_type ch) noexcept
{
// The table returns 0 to signal that this code maps to itself
classify_type const r = detail::uppercase_lookup(ch);
return r == 0 ? ch : r;
}

} // iris::x4::unicode

#endif
Loading
Loading