How to auto-complete JSON syntax strings?

26 views Asked by At

Specifically, it is required that given the string above, the output will be the next character set that matches the JSON syntax.

Example 1: All Possible Next Tokens for the empty text ("") is

['{', '[', '"', '0', /[1-9]/, '-', 't', 'f', 'n']

Where /[1-9]/ denotes a rule that matches a single character.

Example 2: The next character set for ´{ "key"´ above is

[':', ' ', '\t', '\r', '\n']

Example 3: The next character set of 0 above is null, which means that the EOF of the JSON has been reached, since a number starting with 0 can only be 0.

JSON syntax can be found at JSON.org. I've been trying to figure this out for 4 days, and I've deleted most of the code I've written, but I can't get it to work.

Tag: grammar, LL grammar, context-independent grammar, compilation principle

I tried Antlr4's API and its Auto Complete Core and found that it makes errors and misses possible characters.

0

There are 0 answers