This subroutine treats character class expression, and does not call any other recursive procedures.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(tree_t), | intent(inout) | :: | self |
pure subroutine tree_graph__char_class(self) use :: forgex_utf8_m, only: idxutf8, len_utf8, count_token, ichar_utf8 use :: forgex_cube_m, only: cube_t, assignment(=) use :: forgex_enums_m implicit none class(tree_t), intent(inout) :: self ! type(segment_t), allocatable :: seglist(:) type(cube_t) :: cube character(:), allocatable :: buf type(tree_node_t) :: node integer :: siz, ie logical :: is_inverted, backslashed character(:), allocatable :: prev, curr siz = 0 call self%tape%get_token(class_flag=.true.) ! The variable buf stores the string representing the character class. buf = '' prev = '' curr = '' backslashed = .false. outer: do while (self%tape%current_token /= tk_rsbracket) prev = curr if (self%tape%current_token == tk_end) then return end if ie = idxutf8(self%tape%token_char, 1) curr = self%tape%token_char(1:ie) buf = buf//curr if (self%tape%current_token == tk_backslash .and. .not. backslashed) then backslashed = .true. else backslashed = .false. end if call self%tape%get_token(class_flag=.true.) ! for an escaped right square bracket if (self%tape%current_token == tk_rsbracket .and. backslashed) then ie = idxutf8(self%tape%token_char, 1) curr = self%tape%token_char(1:ie) buf = buf//curr call self%tape%get_token(class_flag=.true.) end if end do outer ! If the character class pattern is empty, return false. if (len(buf) == 0) then self%code = SYNTAX_ERR_EMPTY_CHARACTER_CLASS self%is_valid = .false. return end if ! Handling a negative class case. is_inverted = .false. if (buf(1:1) == SYMBOL_CRET) then is_inverted = .true. buf = buf(2:len(buf)) ! May this assignment be a problem? end if ! The variable siz stores the length of buf. siz = len_utf8(buf) if (siz < 1) then self%code = SYNTAX_ERR_EMPTY_CHARACTER_CLASS self%is_valid = .false. return end if call interpret_class_string(buf, cube, self%is_valid, self%code) if (.not. self%is_valid) then return end if ! the seglist array have been allocated near the L362. if (is_inverted) then call cube%invert() end if node = make_tree_node(op_char) ! Manually cube_t copy if (.not. cube%is_switched_to_bmp)then node%c%ascii = cube%ascii else call node%c%switch_bmp() node%c%bmp%b(:) = cube%bmp%b(:) end if node%c%single_flag = cube%single_flag if (allocated(cube%sps)) node%c%sps = cube%sps(:) if (cube%is_flagged_epsilon()) call node%c%flag_epsilon() call self%register_connector(node, terminal, terminal) end subroutine tree_graph__char_class