* We use a hand-written parser instead of lex/yacc because our commands are
* easy for humans, not for computers. Thus, it’s quite hard to specify a
* context-free grammar for the commands. A PEG grammar would be easier, but
- * there’s downsides to every PEG parser generator I have come accross so far.
+ * there’s downsides to every PEG parser generator I have come across so far.
*
* This parser is basically a state machine which looks for literals or strings
* and can push either on a stack. After identifying a literal or string, it
* input parser-specs/commands.spec.
******************************************************************************/
-#include "GENERATED_enums.h"
+#include "GENERATED_command_enums.h"
typedef struct token {
char *name;
int n;
} cmdp_token_ptr;
-#include "GENERATED_tokens.h"
+#include "GENERATED_command_tokens.h"
/*******************************************************************************
* The (small) stack where identified literals are stored during the parsing
static struct CommandResult subcommand_output;
static struct CommandResult command_output;
-#include "GENERATED_call.h"
+#include "GENERATED_command_call.h"
static void next_state(const cmdp_token *token) {
subcommand_output.json_gen = command_output.json_gen;
subcommand_output.needs_tree_render = false;
GENERATED_call(token->extra.call_identifier, &subcommand_output);
+ state = subcommand_output.next_state;
/* If any subcommand requires a tree_render(), we need to make the
* whole parser result request a tree_render(). */
if (subcommand_output.needs_tree_render)
}
}
-/* TODO: Return parsing errors via JSON. */
struct CommandResult *parse_command(const char *input) {
DLOG("COMMAND: *%s*\n", input);
state = INITIAL;
/* The "<=" operator is intentional: We also handle the terminating 0-byte
* explicitly by looking for an 'end' token. */
- while ((walk - input) <= len) {
+ while ((size_t)(walk - input) <= len) {
/* skip whitespace and newlines before every token */
while ((*walk == ' ' || *walk == '\t' ||
*walk == '\r' || *walk == '\n') && *walk != '\0')
y(map_open);
ystr("success");
y(bool, false);
+ /* We set parse_error to true to distinguish this from other
+ * errors. i3-nagbar is spawned upon keypresses only for parser
+ * errors. */
+ ystr("parse_error");
+ y(bool, true);
ystr("error");
ystr(errormessage);
ystr("input");