Autocomplete parser integration

How is full parser processing automatically performed?

If you take an example where I pass the parser:

"int i=2" 

then autocomplete options for this may include:

 "int i=2," "int i=2;" 

Should autocomplete be part of the analyzer?

If not, then in the case of an event-based parser, I assume that the parser will emit an event containing identifiers for these branches in the analyzer's state machine, which are possible. Then the autocomplete module will know what to print for each such state.

For a tree-based parser, the parser will have to return a tree structure, which to some extent contains those branches that are available.

How it's done? What type of analyzer is best suited for command line processing when automatic completion is required?

+4
source share
1 answer

You can read a set of pointers (i.e. suitable types of tokens) from the LR (k) grammar, but such grammars tend to be huge. Various forms of grammar compression (of which LALR (1) are probably still the most common) make it less clear (it will always contain valid types of tokens, but it may also contain invalid ones). Invalid types of tokens in the lookahead set can also be introduced by compressing tables and by deliberately enabling error generation (to improve error messages).

Reading a control set from a recursive descent parser can be more complicated, in part because such parsers are usually open source, and not depending on jump tables. However, in theory, at least the LL (k) grammar also has the ability to compute a control set, although it may also be inaccurate.

The most interesting autocomplete, however, is not punctuation, but symbols. Grammar is not enough to tell you which names are in scope at a given point, although it can tell you which types of names would be feasible. You will need to connect to the character table to get accurate autocomplete information. In languages ​​where identifiers can be used before they are declared, this can be even more complex, although it is likely that the parser does maintain a list of unresolved names.

Another difficulty with using parsers to generate autocomplete information is that parsers are typically optimized for syntactically correct programs and may not work at all after detecting a syntax error. For an IDE user, this can be really annoying; minor punctuation errors turn off autocomplete until the error is tracked and fixed. (Personally, I found that such systems are too distracting from the code, I would rather focus on what I'm writing at the moment than on the missing brackets in other parts of the code.)

IM (H) O, it would be better to use something vaguely similar to parsing packages to highlight enough context at the input point to get a reasonable idea of ​​what might follow. If you have access to the complete correct data type declarations, use them, but there is always backing up something to text that looks like a character in a set for viewing (although this can also be annoying).

In any case, good luck.

+8
source

Source: https://habr.com/ru/post/1435267/


All Articles