lib_ruby_parser/
str_term.rs

1pub(crate) mod str_types {
2    pub(crate) const STR_FUNC_ESCAPE: usize = 0x01;
3    pub(crate) const STR_FUNC_EXPAND: usize = 0x02;
4    pub(crate) const STR_FUNC_REGEXP: usize = 0x04;
5    pub(crate) const STR_FUNC_QWORDS: usize = 0x08;
6    pub(crate) const STR_FUNC_SYMBOL: usize = 0x10;
7    pub(crate) const STR_FUNC_INDENT: usize = 0x20;
8    pub(crate) const STR_FUNC_LABEL: usize = 0x40;
9    pub(crate) const STR_FUNC_LIST: usize = 0x4000;
10    pub(crate) const STR_FUNC_TERM: usize = 0x8000;
11
12    #[allow(non_upper_case_globals)]
13    pub(crate) const str_label: usize = STR_FUNC_LABEL;
14    #[allow(non_upper_case_globals)]
15    pub(crate) const str_squote: usize = 0;
16    #[allow(non_upper_case_globals)]
17    pub(crate) const str_dquote: usize = STR_FUNC_EXPAND;
18    #[allow(non_upper_case_globals)]
19    pub(crate) const str_xquote: usize = STR_FUNC_EXPAND;
20    #[allow(non_upper_case_globals)]
21    pub(crate) const str_regexp: usize = STR_FUNC_REGEXP | STR_FUNC_ESCAPE | STR_FUNC_EXPAND;
22    #[allow(non_upper_case_globals)]
23    pub(crate) const str_sword: usize = STR_FUNC_QWORDS | STR_FUNC_LIST;
24    #[allow(non_upper_case_globals)]
25    pub(crate) const str_dword: usize = STR_FUNC_QWORDS | STR_FUNC_EXPAND | STR_FUNC_LIST;
26    #[allow(non_upper_case_globals)]
27    pub(crate) const str_ssym: usize = STR_FUNC_SYMBOL;
28    #[allow(non_upper_case_globals)]
29    pub(crate) const str_dsym: usize = STR_FUNC_SYMBOL | STR_FUNC_EXPAND;
30}
31
32#[derive(Debug, Clone, Default)]
33pub(crate) struct HeredocEnd {
34    pub(crate) start: usize,
35    pub(crate) end: usize,
36    pub(crate) value: Vec<u8>,
37}
38
39#[derive(Debug, Clone, Default)]
40pub(crate) struct StringLiteral {
41    // struct rb_strterm_literal_struct
42    pub(crate) nest: usize,
43    pub(crate) func: usize,
44    pub(crate) paren: Option<u8>,
45    pub(crate) term: u8,
46    pub(crate) heredoc_end: Option<HeredocEnd>,
47}
48
49impl StringLiteral {
50    pub(crate) fn new(
51        nest: usize,
52        func: usize,
53        paren: Option<u8>,
54        term: u8,
55        heredoc_end: Option<HeredocEnd>,
56    ) -> Self {
57        Self {
58            nest,
59            func,
60            paren,
61            term,
62            heredoc_end,
63        }
64    }
65}
66
67#[derive(Debug, Clone, Default)]
68pub(crate) struct HeredocLiteral {
69    pub(crate) lastline: usize, /* the string of line that contains `<<"END"` */
70    pub(crate) offset: usize,   /* the column of END in `<<"END"` */
71    pub(crate) sourceline: usize, /* lineno of the line that contains `<<"END"` */
72    pub(crate) length: usize,   /* the length of END in `<<"END"` */
73
74    pub(crate) quote: usize,
75    pub(crate) func: usize,
76}
77
78impl HeredocLiteral {
79    pub(crate) fn new(
80        lastline: usize,
81        offset: usize,
82        sourceline: usize,
83        length: usize,
84        quote: usize,
85        func: usize,
86    ) -> Self {
87        Self {
88            lastline,
89            offset,
90            sourceline,
91            length,
92            quote,
93            func,
94        }
95    }
96}
97
98#[derive(Debug, Clone)]
99pub(crate) enum StrTerm {
100    // struct rb_strterm_struct
101    StringLiteral(StringLiteral),
102    HeredocLiteral(HeredocLiteral),
103}
104
105impl StrTerm {
106    pub(crate) fn new_literal(literal: StringLiteral) -> Self {
107        Self::StringLiteral(literal)
108    }
109
110    pub(crate) fn new_heredoc(heredoc: HeredocLiteral) -> Self {
111        Self::HeredocLiteral(heredoc)
112    }
113}