summaryrefslogtreecommitdiffstats
path: root/lib/command_parse.y (follow)
Commit message (Collapse)AuthorAgeFilesLines
* lib: assign CLI varnames while parsingDavid Lamparter2021-10-181-6/+8
| | | | | | ... rather than running a costly extra pass across the finished tree. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: fix spelling nits in more lib filesewlumpkin2021-10-051-1/+1
| | | | Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
* lib: add `![...]` syntax for easy "no" formsDavid Lamparter2021-08-261-0/+16
| | | | | | | | | | This allows defining a CLI command like this: `[no] some setting ![VALUE]` with VALUE being optional for the "no" form, but required for the positive form. It's just a `[...]` where the empty branch can only be taken for commands starting with `no`. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* build: make builddir include path consistentDavid Lamparter2021-04-211-1/+1
| | | | | | | ... by referencing all autogenerated headers relative to the root directory. (90% of the changes here is `version.h`.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* *: require semicolon after DEFINE_MTYPE & coDavid Lamparter2021-03-171-2/+2
| | | | | | | | | | | | | | | | | Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
* *: remove tabs & newlines from log messagesDavid Lamparter2021-02-141-1/+1
| | | | | | | Neither tabs nor newlines are acceptable in syslog messages. They also break line-based parsing of file logs. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: Change zlog_debug to zlog_err for doc string issuesDonald Sharp2020-11-171-5/+5
| | | | | | | | | | | Modify the code to change from zlog_debug to zlog_err. vtysh was not outputting the vtysh doc string issues after a change a couple of months back. By changing to error level we start seeing them on vtysh start up again. This will allow us to catch these issues in the CI runs again. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* lib: make cmd_element & qobj_type constDavid Lamparter2019-11-301-4/+4
| | | | Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: add a check for {[...]} in DEFUNsDavid Lamparter2019-06-251-0/+36
| | | | | | | | Our command matcher doesn't handle {[...]} correctly; let's warn about it so the DEFUN can be changed to [{...}] (which does work as expected.) Fixes: #4594 Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: Convert zlog_err for clippy buildDonald Sharp2018-08-141-4/+4
| | | | | | | | | | | The clippy code does not need to log the error messages as errors as that it is only run as part of the build itself and as long as we see the notifications we are good. So convert zlog_err to zlog_notice so that we do not think we have any zlog_err's in lib anymore Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
* lib: add CLI token for 48-bit mac addressesQuentin Young2017-08-111-0/+12
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* build: convert lib/ to non-recursive buildDavid Lamparter2017-07-311-2/+2
| | | | Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: warn about too much docstringQuentin Young2017-07-051-0/+8
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: fix CLI parser memleakDavid Lamparter2017-06-141-1/+1
| | | | Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* build: fix some cross-compilation issuesDavid Lamparter2017-06-141-0/+2
| | | | Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: split off & rename graph handlingDavid Lamparter2017-05-151-13/+13
| | | | | | | Put core CLI graph stuff in lib/command_graph.[ch] and consistently prefix all function names with "cmd_". Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: add named variables in CLIDavid Lamparter2017-05-151-5/+37
| | | | | | | | | struct cmd_token now has a "varname" field which is derived from the DEFUN's string definition. It can be manually specified with "$name" after some token, e.g. "foo WORD$var". A later commit adds code to automatically fill the value if nothing is specified. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: remove previous deduplication codeDavid Lamparter2017-02-101-108/+3
| | | | | | Rewritten in next commit. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: fix allocation countingDavid Lamparter2017-01-311-7/+12
| | | | | | | command_lex.l was allocating as MTYPE_TMP, while command_parse.y would just call free(). Make both use MTYPE_LEX. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* Merge pull request #105 from opensourcerouting/cli_merge_step_prepDonald Sharp2017-01-251-138/+84
|\ | | | | Prepare for split-off cli parser "merge" step
| * build: support bison < 3.0 for parse.error=verboseDavid Lamparter2017-01-231-1/+1
| | | | | | | | | | | | *sigh* Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
| * lib: parser: add error location reportingDavid Lamparter2017-01-231-10/+42
| | | | | | | | | | | | | | | | flex+bison have nice capabilities to track the location that is currently being processed; let's enable these and get better warnings for broken CLI specs. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
| * lib: parser: unify subgraphs & simplify even moreDavid Lamparter2017-01-231-93/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | This cuts a large piece of complexity from the parser by making the sequences between | the same, no matter whether it's <> () or []. This causes some changes in behaviour: - [foo|bar] is now accepted - <foo|[bar]> is now accepted (yes it's stupid) - {a|b} is now means "at least one of these, in any order"; to allow zero use [{a|b}] instead. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
| * lib: parser: keep subgraph pointers on stackDavid Lamparter2017-01-231-86/+64
| | | | | | | | | | | | | | | | There's no need to malloc() these, we can just keep them on the stack. The entire struct will get copied around, but replacing a 2-pointer copy with a 1-pointer copy + malloc + free overhead is not quite efficient. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
| * lib: parser: track matching FORK_TKN & JOIN_TKNDavid Lamparter2017-01-231-0/+6
| | | | | | | | | | | | | | This associates pairs of FORK and JOIN tokens, so the merge function can identify where a subgraph begins and ends. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
| * lib: parser: simplify OPTION_TKN & SELECTOR_TKNDavid Lamparter2017-01-231-9/+8
| | | | | | | | | | | | These are functionally identical as "fork" tokens. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* | lib: parser: fix memory managementDavid Lamparter2017-01-251-17/+14
|/ | | | | | | | | | | | | | | | | | | | | | command.c had: DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command desc") while command_match.c had: DEFINE_MTYPE_STATIC(LIB, CMD_TOKENS, "Command Tokens") ... which means that there are 2 distinct MTYPE_CMD_TOKENS. (The description text being different does not matter, even with the same text it'd be 2 distinct types.) command_match.c allocates token->arg in command_match_r() while command.c frees it in del_cmd_token(). Therefore with each command being executed, the allocation count goes up on one, down on the other. => clean up parser allocation counting. Also, use separate MTYPEs for the different fields in struct cmd_token. Fixes: #108 / ee9216cf ("lib, ripngd: clean up merge leftovers") Signed-off-by: David Lamparter <equinox@opensourcerouting.org> Cc: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: parser: remove startnode & sentence_rootDavid Lamparter2016-12-161-22/+6
| | | | | | | | | | | | | This removes an artificial restriction for the first token in a command's graph to be a WORD_TKN. The intention seems to be to prohibit empty paths through a command, and to restrict "explosion" of choices in the root node. The better approach to the former is to check for an empty path after the definition is parsed. The latter will happen anyway, by duplication of the command, which just makes it worse... Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: move allowrepeat to cmd_tokenDavid Lamparter2016-12-161-1/+1
| | | | | | | struct graph_node isn't quite the right place to control matcher behaviour. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: reorder bison incarnationsDavid Lamparter2016-12-161-23/+26
| | | | | | | | | | | This shuffles the code blocks in command_parser.y to match file output order, then adjusts things to make the include handling less messy. (also dropped unused DECIMAL_STRLEN_MAX define.) This should hopefully fix the build on NetBSD 6. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* build: fix bison < 3.0 compatibilityDavid Lamparter2016-12-161-1/+1
| | | | | | | bison-2.7.x really wants "foo" for api.prefix while bison-3.0.x really wants {foo} ... great. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: support keyword argumentsDavid Lamparter2016-12-151-0/+22
| | | | | | | | | | | This re-adds "{foo WORD|bar WORD}" keyword-argument support to the CLI parser. Note that token graphs may now contain loops for this purpose; therefore the matching functions retain a history of already-matched tokens. Each token can thus only be consumed once. And then LINE... gets its special treatment with allowrepeat. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: Add back prototypes for lexer helper funcsQuentin Young2016-12-021-3/+3
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: remove misleading copy/del_cmd_elementDavid Lamparter2016-12-011-1/+1
| | | | | | | struct cmd_element items are static global variables, they are never allocated, copied or freed. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: use reentrant mode on flex & bisonDavid Lamparter2016-12-011-21/+29
| | | | | | | | | | | | This removes remaining global variables from the lexer, pushing the lexer state into struct parser_ctx too. At the same time, "cmd_yy" is used as prefix for all parser & lexer routines. The result is that (a) there is no collision anymore if a program uses flex/bison and links libzebra, and (b) the parser is fully encapsulated and could be called in parallel from multiple threads. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: parser: wrap state in struct parser_ctxDavid Lamparter2016-12-011-79/+83
| | | | | | | | This encapsulates all parser state into a new "struct parser_ctx", which is allocated on stack and passed around as pointer. The parser no longer has any global variables with this. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: move command_parse_format prototypeDavid Lamparter2016-12-011-2/+0
| | | | | | | | The function prototype for command_parse_format() is better left in command.h, so that the bison-generated header file doesn't need to be included for that. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: use traditional yacc empty statementDavid Lamparter2016-11-291-1/+1
| | | | | | | %empty was added in bison 2.7.1, which seems to not be available on some of the BSDs by default. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib, vtysh: Fix memory leaks, change cmd_element to constQuentin Young2016-11-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix a few memory issues: * Not freeing tab-completions upon input match failure * Invalid write when null-terminating tab-completions * Not freeing argv[] itself in additinon to elements * Use XFREE() instead of free() as appropriate * Not freeing final token of an [option] during parsing Make a few minor changes to CLI internals: * Improve documentation on matching & completion functions * Only make one copy of cmd_token's when building argv, instead of three * Don't make a copy of the matching cmd_element Make one major(ish) change to CLI internals: * Change all pointers to struct cmd_element to const Code outside of the core CLI units should never have an occasion to modify the internal state of the command system. Doing so could easily amount to having a CLI interface that changes during runtime, and could conceivably lead to security issues. Explicitly disallowing this removes any chance of confusion. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: Implement hidden and deprecated commandsQuentin Young2016-11-111-25/+38
| | | | | | | | | | Each token now knows whether it is part of a hidden or deprecated command. Command completion logic hides such tokens when generating completions. Command matching logic works as before and will still match on hidden and deprecated commands. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* ospfd, lib: Fix `no pce address` syntaxQuentin Young2016-11-041-1/+1
| | | | | | And change parser debugging messages to zlog_debug Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: Log warning when commands have underfull doc stringQuentin Young2016-10-281-15/+30
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: allow nesting selectorsQuentin Young2016-10-021-0/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: fix double free in parserQuentin Young2016-10-011-1/+0
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib, vtysh: refactor vtysh.c, allow parser continuanceQuentin Young2016-10-011-1/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: Remove NUMBER_TKN leftoversQuentin Young2016-09-221-4/+0
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: Update copyright headersQuentin Young2016-09-221-1/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* Merge remote-tracking branch 'origin/cmaster-next' into vtysh-grammarDonald Sharp2016-09-211-34/+35
|
* lib: Initial refactor pass on CLI backendQuentin Young2016-09-201-9/+7
| | | | | | | | | | | | Shotgun commit: * Remove shim sources from Makefile.am * Move new types to command.c / command.h * Rewrite command.c / command.h * Refactor shim types to real types in matcher and parser * Initial refactor pass on vty.c Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: Allow nesting options in selectorsQuentin Young2016-09-181-138/+139
| | | | | | | Options may now be nested in selectors as long as they are not the first token in sequence. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>