Debian Codegraph @

include/ruby/internal/intern/parse.h

raw
1 #ifndef RBIMPL_INTERN_PARSE_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_INTERN_PARSE_H
3 /**
4 * @file
5 * @author Ruby developers <[email protected]>
6 * @copyright This file is a part of the programming language Ruby.
7 * Permission is hereby granted, to either redistribute and/or
8 * modify this file, provided that the conditions mentioned in the
9 * file COPYING are met. Consult the file for details.
10 * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11 * implementation details. Don't take them as canon. They could
12 * rapidly appear then vanish. The name (path) of this header file
13 * is also an implementation detail. Do not expect it to persist
14 * at the place it is now. Developers are free to move it anywhere
15 * anytime at will.
16 * @note To ruby-core: remember that this header can be possibly
17 * recursively included from extension libraries written in C++.
18 * Do not expect for instance `__VA_ARGS__` is always available.
19 * We assume C99 for ruby itself but we don't assume languages of
20 * extension libraries. They could be written in C++98.
21 * @brief Public APIs related to ::rb_cSymbol.
22 */
23 #include "ruby/internal/attr/const.h"
24 #include "ruby/internal/attr/nonnull.h"
25 #include "ruby/internal/dllexport.h"
26 #include "ruby/internal/value.h"
27
28 RBIMPL_SYMBOL_EXPORT_BEGIN()
29
30 /* symbol.c */
31
32 /**
33 * Calculates an ID of attribute writer. For instance it returns `:foo=` when
34 * passed `:foo`.
35 *
36 * @param[in] id An id.
37 * @exception rb_eNameError `id` is not for attributes (e.g. operator).
38 * @return Calculated name of attribute writer.
39 */
40 ID rb_id_attrset(ID id);
41
42 RBIMPL_ATTR_CONST()
43 /**
44 * Classifies the given ID, then sees if it is a constant. In case an ID is in
45 * Unicode (likely), its "constant"-ness is determined if its first character
46 * is either upper case or title case. Otherwise it is detected if case-
47 * folding the first character changes its case or not.
48 *
49 * @param[in] id An id to classify.
50 * @retval 1 It is a constant.
51 * @retval 0 It isn't.
52 */
53 int rb_is_const_id(ID id);
54
55 RBIMPL_ATTR_CONST()
56 /**
57 * Classifies the given ID, then sees if it is a global variable. A global
58 * variable must start with `$`.
59 *
60 * @param[in] id An id to classify.
61 * @retval 1 It is a global variable.
62 * @retval 0 It isn't.
63 */
64 int rb_is_global_id(ID id);
65
66 RBIMPL_ATTR_CONST()
67 /**
68 * Classifies the given ID, then sees if it is an instance variable. An
69 * instance variable must start with `@`, but not `@@`.
70 *
71 * @param[in] id An id to classify.
72 * @retval 1 It is an instance variable.
73 * @retval 0 It isn't.
74 */
75 int rb_is_instance_id(ID id);
76
77 RBIMPL_ATTR_CONST()
78 /**
79 * Classifies the given ID, then sees if it is an attribute writer. An
80 * attribute writer is otherwise a local variable, except it ends with `=`.
81 *
82 * @param[in] id An id to classify.
83 * @retval 1 It is an attribute writer.
84 * @retval 0 It isn't.
85 */
86 int rb_is_attrset_id(ID id);
87
88 RBIMPL_ATTR_CONST()
89 /**
90 * Classifies the given ID, then sees if it is a class variable. A class
91 * variable is must start with `@@`.
92 *
93 * @param[in] id An id to classify.
94 * @retval 1 It is a class variable.
95 * @retval 0 It isn't.
96 */
97 int rb_is_class_id(ID id);
98
99 RBIMPL_ATTR_CONST()
100 /**
101 * Classifies the given ID, then sees if it is a local variable. A local
102 * variable starts with a lowercase character, followed by some alphanumeric
103 * characters or `_`, then ends with anything other than `!`, `?`, or `=`.
104 *
105 * @param[in] id An id to classify.
106 * @retval 1 It is a local variable.
107 * @retval 0 It isn't.
108 */
109 int rb_is_local_id(ID id);
110
111 RBIMPL_ATTR_CONST()
112 /**
113 * Classifies the given ID, then sees if it is a junk ID. An ID with no
114 * special syntactic structure is considered junk. This category includes for
115 * instance punctuation.
116 *
117 * @param[in] id An id to classify.
118 * @retval 1 It is a junk.
119 * @retval 0 It isn't.
120 */
121 int rb_is_junk_id(ID);
122
123 RBIMPL_ATTR_NONNULL(())
124 /**
125 * Sees if the passed C string constructs a valid syntactic symbol. Invalid
126 * ones for instance includes whitespaces.
127 *
128 * @param[in] str A C string to check.
129 * @retval 1 It is a valid symbol name.
130 * @retval 0 It is invalid as a symbol name.
131 */
132 int rb_symname_p(const char *str);
133
134 /* vm.c */
135
136 /**
137 * Queries the last match, or `Regexp.last_match`, or the `$~`. You don't have
138 * to use it, because in reality you can get `$~` using rb_gv_get() as usual.
139 *
140 * @retval RUBY_Qnil The method has not ran a regular expression.
141 * @retval otherwise An instance of ::rb_cMatch.
142 */
143 VALUE rb_backref_get(void);
144
145 /**
146 * Updates `$~`. You don't have to use it, because in reality you can set `$~`
147 * using rb_gv_set() as usual.
148 *
149 * @param[in] md Arbitrary Ruby object.
150 * @post The passed object is assigned to `$~`.
151 *
152 * @internal
153 *
154 * Yes, this function bypasses the Check_Type() that would normally prevent
155 * evil souls from assigning evil objects to `$~`. Use of this function is a
156 * really bad smell.
157 */
158 void rb_backref_set(VALUE md);
159
160 /**
161 * Queries the last line, or the `$_`. You don't have to use it, because in
162 * reality you can get `$_` using rb_gv_get() as usual.
163 *
164 * @retval RUBY_Qnil There has never been a "line" yet.
165 * @retval otherwise The last set `$_` value.
166 */
167 VALUE rb_lastline_get(void);
168
169 /**
170 * Updates `$_`. You don't have to use it, because in reality you can set `$_`
171 * using rb_gv_set() as usual.
172 *
173 * @param[in] str Arbitrary Ruby object.
174 * @post The passed object is assigned to `$_`.
175 *
176 * @internal
177 *
178 * Unlike `$~`, you can assign non-strings to `$_`, even from ruby scripts.
179 */
180 void rb_lastline_set(VALUE str);
181
182 /* symbol.c */
183
184 /**
185 * Collects every single bits of symbols that have ever interned in the entire
186 * history of the current process.
187 *
188 * @return An array that contains all symbols that have ever existed.
189 */
190 VALUE rb_sym_all_symbols(void);
191
192 RBIMPL_SYMBOL_EXPORT_END()
193
194 #endif /* RBIMPL_INTERN_PARSE_H */