forgex_segment_m Module

Note

Support for handling many Unicode whitespace characters is currently not available, but will be added in the future.

Note

We would like to add a procedure to merge adjacent segments with the same transition destination into a single segment.



Variables

Type Visibility Attributes Name Initial
type(segment_t), public, parameter :: SEG_ANY = segment_t(UTF8_CODE_MIN, UTF8_CODE_MAX)
type(segment_t), public, parameter :: SEG_CR = segment_t(13, 13)
type(segment_t), public, parameter :: SEG_DIGIT = segment_t(48, 57)
type(segment_t), public, parameter :: SEG_EMPTY = segment_t(UTF8_CODE_EMPTY, UTF8_CODE_EMPTY)
type(segment_t), public, parameter :: SEG_EPSILON = segment_t(-1, -1)
type(segment_t), public, parameter :: SEG_FF = segment_t(12, 12)
type(segment_t), public, parameter :: SEG_INIT = segment_t(UTF8_CODE_MAX+2, UTF8_CODE_MAX+2)
type(segment_t), public, parameter :: SEG_LF = segment_t(10, 10)
type(segment_t), public, parameter :: SEG_LOWERCASE = segment_t(97, 122)
type(segment_t), public, parameter :: SEG_SPACE = segment_t(32, 32)
type(segment_t), public, parameter :: SEG_TAB = segment_t(9, 9)
type(segment_t), public, parameter :: SEG_UNDERSCORE = segment_t(95, 95)
type(segment_t), public, parameter :: SEG_UPPER = segment_t(UTF8_CODE_MAX+1, UTF8_CODE_MAX+1)
type(segment_t), public, parameter :: SEG_UPPERCASE = segment_t(65, 90)
type(segment_t), public, parameter :: SEG_ZENKAKU_SPACE = segment_t(12288, 12288)

Interfaces

public interface operator(.in.)

This interface block provides the .in. operator, which checks whether an integer and a segment, an integer and a list of segments, or a segment and a segment, is contained in the latter, respectively.

  • private pure elemental function arg_in_segment(a, seg) result(res)

    Checks if the given integer is within the specified segment.

    This function determines whether the integer a falls within the range defined by the min and max values of the segment_t type.

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: a
    type(segment_t), intent(in) :: seg

    Return Value logical

  • private pure function arg_in_segment_list(a, seg_list) result(res)

    Check if the ginve integer is within any of specified segments in a list.

    This function determins whether the integer a falls within any of the ranges defined by the min and max value of the segment_t type in the provided list of segments.

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: a
    type(segment_t), intent(in) :: seg_list(:)

    Return Value logical

  • private pure elemental function seg_in_segment(a, b) result(res)

    Check if the one segment is completely within another segment.

    This function determines whether the segment a is entirely within the range specified by the segment b.

    Arguments

    Type IntentOptional Attributes Name
    type(segment_t), intent(in) :: a
    type(segment_t), intent(in) :: b

    Return Value logical

  • private pure function seg_in_segment_list(seg, list) result(res)

    Arguments

    Type IntentOptional Attributes Name
    type(segment_t), intent(in) :: seg
    type(segment_t), intent(in) :: list(:)

    Return Value logical

public interface operator(/=)

This interface block provides a not equal operator for comparing segments.

  • private pure elemental function segment_not_equiv(a, b) result(res)

    Check if two segments are not equivalent.

    This function determines whether the segment a is not equivalent to the segment b, meaning their min or max values are different.

    Arguments

    Type IntentOptional Attributes Name
    type(segment_t), intent(in) :: a
    type(segment_t), intent(in) :: b

    Return Value logical

public interface operator(==)

This interface block provides a equal operator for comparing segments.

  • private pure elemental function segment_equivalent(a, b) result(res)

    Check if the one segment is exactly equal to another segment.

    This function determines wheter the segment a is equivalent to the segment b, meaning both their min and max values are identical.

    Arguments

    Type IntentOptional Attributes Name
    type(segment_t), intent(in) :: a
    type(segment_t), intent(in) :: b

    Return Value logical


Derived Types

type, public ::  segment_t

This derived-type represents a contiguous range of the Unicode character set as a min and max value, providing an effective way to represent ranges of characters when building automata where a range characters share the same transition destination.

Components

Type Visibility Attributes Name Initial
integer(kind=int32), public :: max = UTF8_CODE_MAX+2
integer(kind=int32), public :: min = UTF8_CODE_MAX+2

Type-Bound Procedures

procedure, public :: print => segment_for_print
procedure, public :: validate => segment_is_valid

Functions

public pure function symbol_to_segment(symbol) result(res)

This function convert an input symbol into the segment corresponding it.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: symbol

Return Value type(segment_t)

public pure function which_segment_symbol_belong(segments, symbol) result(res)

This function takes an array of segments and a character as arguments, and returns the segment as rank=1 array to which symbol belongs (included in the segment interval).

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(in) :: segments(:)
character(len=*), intent(in) :: symbol

Return Value type(segment_t)

private pure elemental function arg_in_segment(a, seg) result(res)

Checks if the given integer is within the specified segment.

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: a
type(segment_t), intent(in) :: seg

Return Value logical

private pure function arg_in_segment_list(a, seg_list) result(res)

Check if the ginve integer is within any of specified segments in a list.

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: a
type(segment_t), intent(in) :: seg_list(:)

Return Value logical

private pure elemental function seg_in_segment(a, b) result(res)

Check if the one segment is completely within another segment.

Read more…

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(in) :: a
type(segment_t), intent(in) :: b

Return Value logical

private pure function seg_in_segment_list(seg, list) result(res)

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(in) :: seg
type(segment_t), intent(in) :: list(:)

Return Value logical

private pure elemental function segment_equivalent(a, b) result(res)

Check if the one segment is exactly equal to another segment.

Read more…

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(in) :: a
type(segment_t), intent(in) :: b

Return Value logical

private function segment_for_print(seg) result(res)

Converts a segment to a printable string representation.

Read more…

Arguments

Type IntentOptional Attributes Name
class(segment_t), intent(in) :: seg

Return Value character(len=:), allocatable

private pure elemental function segment_is_valid(self) result(res)

Checks if a segment is valid.

Read more…

Arguments

Type IntentOptional Attributes Name
class(segment_t), intent(in) :: self

Return Value logical

private pure elemental function segment_not_equiv(a, b) result(res)

Check if two segments are not equivalent.

Read more…

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(in) :: a
type(segment_t), intent(in) :: b

Return Value logical


Subroutines

public pure subroutine invert_segment_list(list)

This subroutine inverts a list of segment ranges representing Unicode characters. It compute the complement of the given ranges and modifies the list accordingly.

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(inout), allocatable :: list(:)

public pure subroutine merge_segments(segments)

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(inout), allocatable :: segments(:)

public pure subroutine sort_segment_by_min(segments)

Arguments

Type IntentOptional Attributes Name
type(segment_t), intent(inout), allocatable :: segments(:)