is_valid__prefix Function

public function is_valid__prefix(pattern, expected_prefix, resulting) result(res)

This function checks whether the correct prefix is extracted for a given pattern.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: pattern
character(len=*), intent(in) :: expected_prefix
character(len=:), allocatable :: resulting

Return Value logical


Source Code

   function is_valid__prefix(pattern, expected_prefix, resulting) result(res)
      use :: forgex_syntax_tree_optimize_m, only: extract_literal
      use :: forgex_utf8_m, only: len_utf8
      implicit none
      character(*), intent(in) :: pattern, expected_prefix
      character(:), allocatable :: resulting
      logical :: res

      character(:), allocatable :: unused_1, unused_2, unused_3 
      type(tree_t) :: tree

      call tree%build(pattern)
      ! resulting = get_prefix_literal(tree)
      call extract_literal(tree, unused_1, resulting, unused_2, unused_3)

      if (len_utf8(expected_prefix) == len_utf8(resulting)) then
         res = expected_prefix == resulting
         return
      end if
      res = .false. 

   end function is_valid__prefix