This function handles shorthand escape sequences (\t
, \n
, \r
, \d
, \D
,
\w
, \W
, \s
, \S
).
It does not call any other recursive procedures.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(tree_t), | intent(inout) | :: | self |
pure subroutine tree_graph__shorthand(self) use :: forgex_utf8_m, only: ichar_utf8 implicit none class(tree_t), intent(inout) :: self type(tree_node_t) :: node type(segment_t), allocatable :: seglist(:) type(segment_t) :: seg character(:), allocatable :: chara select case (trim(self%tape%token_char)) case (ESCAPE_T) node = make_atom(SEG_TAB) call self%register_connector(node, terminal, terminal) return case (ESCAPE_N) call self%crlf() return case (ESCAPE_R) node = make_atom(SEG_CR) call self%register_connector(node, terminal, terminal) return case (ESCAPE_D) node = make_atom(SEG_DIGIT) call self%register_connector(node, terminal, terminal) return case (ESCAPE_D_CAPITAL) call node%c%add(SEG_DIGIT) call node%c%invert() ! allocate(seglist(1)) ! seglist(1) = SEG_DIGIT ! call invert_segment_list(seglist) case (ESCAPE_W) call node%c%add(SEG_LOWERCASE) call node%c%add(SEG_UNDERSCORE) call node%c%add(SEG_DIGIT) call node%c%add(SEG_UPPERCASE) ! allocate(seglist(4)) ! seglist(1) = SEG_LOWERCASE ! seglist(2) = SEG_UPPERCASE ! seglist(3) = SEG_DIGIT ! seglist(4) = SEG_UNDERSCORE case (ESCAPE_W_CAPITAL) call node%c%add(SEG_LOWERCASE) call node%c%add(SEG_UNDERSCORE) call node%c%add(SEG_DIGIT) call node%c%add(SEG_UPPERCASE) call node%c%invert() ! allocate(seglist(4)) ! seglist(1) = SEG_LOWERCASE ! seglist(2) = SEG_UPPERCASE ! seglist(3) = SEG_DIGIT ! seglist(4) = SEG_UNDERSCORE ! call invert_segment_list(seglist) case (ESCAPE_S) call node%c%add([SEG_SPACE, SEG_TAB, SEG_CR, SEG_LF, SEG_FF, SEG_ZENKAKU_SPACE]) ! allocate(seglist(6)) ! seglist(1) = SEG_SPACE ! seglist(2) = SEG_TAB ! seglist(3) = SEG_CR ! seglist(4) = SEG_LF ! seglist(5) = SEG_FF ! seglist(6) = SEG_ZENKAKU_SPACE case (ESCAPE_S_CAPITAL) call node%c%add([SEG_SPACE, SEG_TAB, SEG_CR, SEG_LF, SEG_FF, SEG_ZENKAKU_SPACE]) call node%c%invert() ! allocate(seglist(6)) ! seglist(1) = SEG_SPACE ! seglist(2) = SEG_TAB ! seglist(3) = SEG_CR ! seglist(4) = SEG_LF ! seglist(5) = SEG_FF ! seglist(6) = SEG_ZENKAKU_SPACE ! call invert_segment_list(seglist) case (ESCAPE_X) ! Error handling for x escape sequence is handled by hex2seg. call self%hex2seg(seglist) if (.not. self%is_valid) return ! It is not necessary to call self%tape%get_token() procedure. call node%c%add(seglist) case (ESCAPE_P) call self%property(seglist) if (.not. self%is_valid) return case (EMPTY_CHAR) self%code = SYNTAX_ERR_ESCAPED_SYMBOL_MISSING self%is_valid = .false. return case (SYMBOL_LSBK, SYMBOL_RSBK, & SYMBOL_LCRB, SYMBOL_RCRB, & SYMBOL_LPAR, SYMBOL_RPAR, & SYMBOL_DOLL, SYMBOL_BSLH, & SYMBOL_VBAR, SYMBOL_DOT, & SYMBOL_QUES, SYMBOL_CRET, & SYMBOL_STAR, SYMBOL_PLUS, & SYMBOL_HYPN) chara = self%tape%token_char seg = segment_t(ichar_utf8(chara), ichar_utf8(chara)) node%op = op_char call node%c%add(seg) call self%register_connector(node, terminal, terminal) return case default self%code = SYNTAX_ERR_ESCAPED_SYMBOL_INVALID self%is_valid = .false. ! chara = self%tape%token_char ! seg = segment_t(ichar_utf8(chara), ichar_utf8(chara)) ! node = make_atom(seg) ! call self%register_connector(node, terminal, terminal) return end select ! allocate(node%c(size(seglist, dim=1))) ! This size function is safe because it is always allocated ! to the non-returned branches of the select case above. ! node%c(:) = seglist(:) node%op = op_char call self%register_connector(node, terminal, terminal) ! deallocate(seglist) end subroutine tree_graph__shorthand