expressions.h
Go to the documentation of this file.
1 #ifndef NVIM_VIML_PARSER_EXPRESSIONS_H
2 #define NVIM_VIML_PARSER_EXPRESSIONS_H
3 
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <stdbool.h>
7 
8 #include "nvim/types.h"
10 #include "nvim/eval/typval.h"
11 
12 // Defines whether to ignore case:
13 // == kCCStrategyUseOption
14 // ==# kCCStrategyMatchCase
15 // ==? kCCStrategyIgnoreCase
16 typedef enum {
17  kCCStrategyUseOption = 0, // 0 for xcalloc
21 
23 typedef enum {
28 
38 
40 
48 
55  // XXX When modifying this enum you need to also modify eltkn_type_tab in
56  // expressions.c and tests and, possibly, viml_pexpr_repr_token.
58 
59 typedef enum {
66 
68 typedef enum {
72 } ExprOptScope;
73 
75 typedef enum {
81 
82 #define EXPR_OPT_SCOPE_LIST \
83  ((char[]){ kExprOptScopeGlobal, kExprOptScopeLocal })
84 
86 typedef enum {
96 } ExprVarScope;
97 
98 #define EXPR_VAR_SCOPE_LIST \
99  ((char[]) { \
100  kExprVarScopeScript, kExprVarScopeGlobal, kExprVarScopeVim, \
101  kExprVarScopeBuffer, kExprVarScopeWindow, kExprVarScopeTabpage, \
102  kExprVarScopeLocal, kExprVarScopeBuffer, kExprVarScopeArguments, \
103  })
104 
106 typedef struct {
108  size_t len;
110  union {
111  struct {
114  bool inv;
115  } cmp;
116 
117  struct {
118  enum {
122  } type;
123  } mul;
124 
125  struct {
126  bool closing;
127  } brc;
128 
129  struct {
130  int name;
131  } reg;
132 
133  struct {
134  bool closed;
135  } str;
136 
137  struct {
138  const char *name;
139  size_t len;
141  } opt;
142 
143  struct {
145  bool autoload;
146  } var;
147 
148  struct {
150  const char *msg;
151  } err;
152 
153  struct {
154  union {
157  } val;
158  uint8_t base;
159  bool is_float;
160  } num;
161 
162  struct {
164  } ass;
165  } data;
166 } LexExprToken;
167 
168 typedef enum {
170  kELFlagPeek = (1 << 0),
172  kELFlagForbidScope = (1 << 1),
177  kELFlagAllowFloat = (1 << 2),
181  kELFlagIsNotCmp = (1 << 3),
187  kELFlagForbidEOC = (1 << 4),
188  // XXX Whenever you add a new flag, alter klee_assume() statement in
189  // viml_expressions_lexer.c.
190 } LexExprFlags;
191 
193 typedef enum {
252  // XXX When modifying this list also modify east_node_type_tab both in parser
253  // and in tests, and you most likely will also have to alter list of
254  // highlight groups stored in highlight_init_cmdline variable.
256 
257 typedef struct expr_ast_node ExprASTNode;
258 
261  ExprASTNodeType type;
269  size_t len;
270  union {
271  struct {
272  int name;
273  } reg;
274  struct {
276  struct {
283  } type_guesses;
286  } fig;
287  struct {
289  const char *ident;
293  size_t ident_len;
294  } var;
295  struct {
296  bool got_colon;
297  } ter;
298  struct {
301  bool inv;
302  } cmp;
303  struct {
305  } num;
306  struct {
308  } flt;
309  struct {
310  char *value;
311  size_t size;
312  } str;
313  struct {
315  const char *ident;
316  size_t ident_len;
318  } opt;
319  struct {
320  const char *ident;
321  size_t ident_len;
322  } env;
323  struct {
325  } ass;
326  } data;
327 };
328 
329 enum {
333  kExprFlagsMulti = (1 << 0),
343  kExprFlagsParseLet = (1 << 2),
344  // XXX whenever you add a new flag, alter klee_assume() statement in
345  // viml_expressions_parser.c, nvim_parse_expression() flags parsing
346  // alongside with its documentation and flag sets in check_parsing()
347  // function in expressions parser functional and unit tests.
349 
351 typedef struct {
353  const char *msg;
355  const char *arg;
357  int arg_len;
358 } ExprASTError;
359 
361 typedef struct {
368 } ExprAST;
369 
371 extern const uint8_t node_maxchildren[];
372 
374 extern const char *const east_node_type_tab[];
375 
377 extern const char *const eltkn_cmp_type_tab[];
378 
380 extern const char *const ccs_tab[];
381 
383 extern const char *const expr_asgn_type_tab[];
384 
385 #ifdef INCLUDE_GENERATED_DECLARATIONS
386 # include "viml/parser/expressions.h.generated.h"
387 #endif
388 
389 #endif // NVIM_VIML_PARSER_EXPRESSIONS_H
List literal.
Definition: expressions.h:200
const char * arg
Error message argument: points to the location of the error.
Definition: expressions.h:355
ParserPosition start
Definition: expressions.h:268
size_t len
Option name length.
Definition: expressions.h:108
int name
Register name, may be -1 if name not present.
Definition: expressions.h:130
const uint8_t node_maxchildren[]
Array mapping ExprASTNodeType to maximum amount of children node may have.
Definition: expressions.c:938
Double quoted string literal.
Definition: expressions.h:43
const char * msg
Error message.
Definition: expressions.h:150
Dictionary literal.
Definition: expressions.h:220
ExprASTNodeType
Expression AST node type.
Definition: expressions.h:193
ExprASTNode * children
Node children: e.g. for 1 + 2 nodes 1 and 2 will be children of +.
Definition: expressions.h:263
Definition: expressions.h:91
Modulo.
Definition: expressions.h:121
Definition: expressions.h:244
ExprOptScope scope
Option scope: &l:, &g: or not specified.
Definition: expressions.h:317
Register.
Definition: expressions.h:198
int name
Register name, may be -1 if name not present.
Definition: expressions.h:272
Definition: expressions.h:242
Definition: expressions.h:18
Definition: expressions.h:236
Not: !.
Definition: expressions.h:39
struct expr_ast_node::@81::@83::@93 type_guesses
Which nodes UnknownFigure can’t possibly represent.
End of command character: NL, |, just end of stream.
Definition: expressions.h:27
Lexer token.
Definition: expressions.h:106
Definition: expressions.h:70
size_t ident_len
Actual identifier length.
Definition: expressions.h:293
struct expr_ast_node::@81::@88 flt
For kExprNodeFloat.
Assignment: = or {op}=.
Definition: expressions.h:54
struct expr_ast_node::@81::@86 cmp
For kExprNodeComparison.
float_T value
Definition: expressions.h:307
const char *const east_node_type_tab[]
Array mapping ExprASTNodeType values to their stringified versions.
Definition: expressions.c:815
Colon, for use in ternary.
Definition: expressions.h:30
Arrow, like from lambda expressions.
Definition: expressions.h:53
Definition: expressions.h:343
Definition: expressions.h:247
struct expr_ast_node::@81::@82 reg
For kExprNodeRegister.
Integer number literal, or part of a float.
Definition: expressions.h:41
Logical and operator.
Definition: expressions.h:32
struct expr_ast_node::@81::@92 ass
For kExprNodeAssignment.
Definition: expressions.h:204
struct expr_ast_node::@81::@83 fig
For kExprNodeUnknownFigure.
Comma “operator”.
Definition: expressions.h:222
int len
Definition: helpers.c:1459
Definition: expressions.h:245
ExprComparisonType type
Comparison type.
Definition: expressions.h:112
Definition: expressions.h:251
ExprAssignmentType
All possible assignment types: = and {op}=.
Definition: expressions.h:75
ExprVarScope
All possible variable scopes.
Definition: expressions.h:86
struct expr_ast_node::@81::@90 opt
For kExprNodeOption.
ExprASTError err
Definition: expressions.h:365
struct expr_ast_node::@81::@87 num
For kExprNodeInteger.
Definition: expressions.h:95
Definition: expressions.h:243
&optionname option value.
Definition: expressions.h:44
Definition: expressions.h:93
Identifier without scope: abc, foo::bar.
Definition: expressions.h:47
Definition: expressions.h:333
ExprASTNode * root
Root node of the AST.
Definition: expressions.h:367
ExprCaseCompareStrategy ccs
Case comparison strategy.
Definition: expressions.h:113
Nested parenthesised expression.
Definition: expressions.h:203
float_T floating
Definition: expressions.h:155
Invalid token, indicaten an error.
Definition: expressions.h:24
bool allow_dict
True if UnknownFigure may actually represent dictionary literal.
Definition: expressions.h:278
Definition: expressions.h:195
struct expr_ast_node::@81::@85 ter
For kExprNodeTernaryValue.
const char * msg
Error message. Must contain a single printf format atom: %.*s.
Definition: expressions.h:353
Spaces, tabs, newlines, etc.
Definition: expressions.h:26
bool allow_ident
True if UnknownFigure may actually be part of curly braces name.
Definition: expressions.h:282
Assignment augmented with concatenation: .=.
Definition: expressions.h:79
ExprAssignmentType type
Definition: expressions.h:163
bool closing
True if bracket/etc is a closing one.
Definition: expressions.h:126
struct expr_ast_node::@81::@89 str
Question mark, for use in ternary.
Definition: expressions.h:29
Comma.
Definition: expressions.h:52
Matches regex, not matches regex.
Definition: expressions.h:61
> or <=
Definition: expressions.h:62
enum @67 ExprParserFlags
Definition: expressions.h:90
Definition: expressions.h:71
uint64_t uvarnumber_T
Definition: typval.h:27
uint8_t base
Base: 2, 8, 10 or 16.
Definition: expressions.h:158
const char * name
Option name start.
Definition: expressions.h:138
const char *const eltkn_cmp_type_tab[]
Array mapping ExprComparisonType values to their stringified versions.
Definition: expressions.c:696
ExprVarScope scope
Scope character or 0 if not present.
Definition: expressions.h:144
Part of the curly braces name.
Definition: expressions.h:221
Definition: expressions.h:92
Parser position in the input.
Definition: parser.h:26
Assignment augmented with subtraction: -=.
Definition: expressions.h:78
>= or <.
Definition: expressions.h:63
Definition: expressions.h:87
Definition: expressions.h:194
Definition: expressions.h:187
size_t opening_hl_idx
Highlight chunk index, used for rehighlighting if needed.
Definition: expressions.h:285
struct expr_ast_node::@81::@91 env
For kExprNodeEnvironment.
Parenthesis, either opening or closing.
Definition: expressions.h:51
Assignment augmented with addition: +=.
Definition: expressions.h:77
bool got_colon
True if colon was seen.
Definition: expressions.h:296
ExprCaseCompareStrategy ccs
Case comparison strategy.
Definition: expressions.h:300
ExprASTNodeType type
Definition: expressions.h:261
AST error definition.
Definition: expressions.h:351
Floating-point number.
Definition: expressions.h:238
Arrow “operator”.
Definition: expressions.h:224
Structure representing complety AST for one expression.
Definition: expressions.h:361
const char *const expr_asgn_type_tab[]
Array mapping ExprAssignmentType values to their stringified versions.
Definition: expressions.c:704
Definition: expressions.h:89
Missing token, for use in parser.
Definition: expressions.h:25
LexExprTokenType type
Suggested type for parsing incorrect code.
Definition: expressions.h:109
void char_u * var
Definition: env.c:416
Definition: expressions.h:181
uvarnumber_T value
Definition: expressions.h:304
Multiplication, division or modulo operator.
Definition: expressions.h:37
LexExprTokenType
Lexer token type.
Definition: expressions.h:23
ParserPosition start
Definition: expressions.h:107
One of the comparison operators.
Definition: expressions.h:33
Integral number.
Definition: expressions.h:237
If set, “pointer” to the current byte in pstate will not be shifted.
Definition: expressions.h:170
Definition: expressions.h:209
Definition: expressions.h:250
ExprAssignmentType type
Definition: expressions.h:324
Real multiplication.
Definition: expressions.h:119
Definition: expressions.h:246
Figure brace, either opening or closing.
Definition: expressions.h:50
Structure representing one AST node.
Definition: expressions.h:260
int arg_len
Message argument length: length till the end of string.
Definition: expressions.h:357
union expr_ast_node::@81 data
Definition: expressions.h:177
Complex identifier: variable/function name with curly braces.
Definition: expressions.h:213
Logical or operator.
Definition: expressions.h:31
Definition: expressions.h:88
Definition: expressions.h:229
Colon “operator”.
Definition: expressions.h:223
Determines whether scope is allowed to come before the identifier.
Definition: expressions.h:172
Subscript.
Definition: expressions.h:199
uvarnumber_T integer
Definition: expressions.h:156
* reg
Definition: ops.c:6025
bool is_float
True if number is a floating-point.
Definition: expressions.h:159
Definition: expressions.h:201
Definition: expressions.h:241
ExprOptScope
All possible option scopes.
Definition: expressions.h:68
Equality, unequality.
Definition: expressions.h:60
ExprComparisonType
Definition: expressions.h:59
Definition: expressions.h:94
double float_T
Type used for VimL VAR_FLOAT values.
Definition: typval.h:30
size_t size
Definition: expressions.h:311
Minus sign.
Definition: expressions.h:35
ExprComparisonType type
Comparison type.
Definition: expressions.h:299
const char * ident
Option name start.
Definition: expressions.h:292
Ternary operator, colon.
Definition: expressions.h:197
ExprVarScope scope
Definition: expressions.h:288
size_t len
Definition: expressions.h:269
Plus sign.
Definition: expressions.h:34
ExprCaseCompareStrategy
Definition: expressions.h:16
bool inv
True if comparison is to be inverted.
Definition: expressions.h:114
Division.
Definition: expressions.h:120
Definition: expressions.h:249
bool autoload
Has autoload characters.
Definition: expressions.h:145
Definition: expressions.h:239
Plain assignment: =.
Definition: expressions.h:76
Definition: expressions.h:248
is or isnot
Definition: expressions.h:64
Ternary operator.
Definition: expressions.h:196
const char *const ccs_tab[]
Array mapping ExprCaseCompareStrategy values to their stringified versions.
Definition: expressions.c:711
Lambda.
Definition: expressions.h:219
Environment $variable value.
Definition: expressions.h:46
Single quoted string literal.
Definition: expressions.h:42
Definition: expressions.h:225
Definition: expressions.h:69
register value.
Definition: expressions.h:45
Bracket, either opening or closing.
Definition: expressions.h:49
err type
Definition: helpers.c:1468
ExprOpAssociativity ass
Definition: expressions.c:1101
bool inv
True if comparison is to be inverted.
Definition: expressions.h:301
ExprOptScope scope
Option scope: &l:, &g: or not specified.
Definition: expressions.h:140
bool allow_lambda
True if UnknownFigure may actually represent lambda.
Definition: expressions.h:280
struct expr_ast_node::@81::@84 var
For kExprNodePlainIdentifier and kExprNodePlainKey.
ExprASTNode * next
Definition: expressions.h:267
Definition: expressions.h:19
Plain dictionary key, for use with kExprNodeConcatOrSubscript.
Definition: expressions.h:211
Definition: expressions.h:240
LexExprFlags
Definition: expressions.h:168
Definition: expressions.h:17
char * value
Definition: expressions.h:310
bool closed
True if quote was closed.
Definition: expressions.h:134
Dot: either concat or subscript, also part of the float.
Definition: expressions.h:36
Definition: expressions.h:218
Definition: expressions.h:338
Definition: expressions.h:202