f6b2baa3e8
I wished there was a way to do this in smaller steps, but with every line fixed an error somewhere else became visible. Here is a (probably incomplete) list of the issues: * Only one set of parentheses was supported. This is a hard to solve problem without a real parser (one solution is to use an recursive RE, see below). * The precedence order was wrong. Might have been adapted just to give a positive result for the arbitrary state of the tree. * Numbered match variables (e.g. $1, $2, etc.) are not local. Calling handle_expressions() recursively once with $1, then with $2, resulted in using the final $2 after the first recursive call (garbage, practically). Also, symbol and expression parsing was mixed, making things harder to follow. To remedy the issues: * Split handle_symbol() out. It is called with whitespace stripped, to keep the uglier REs in handle_expressions(). * Match balanced parentheses and quotes when splitting expressions. In this recursive RE /(\((?:[^\(\)]++|(?-1))*\))/ the `(?-1)` references the outer-most group, thus the whole expression itself. So it matches a pair of parentheses with a mix of non-parentheses and the recursive rule itself inside. This allows us to: * Order the expression matches according to their precedence rules. Now we can match `<expr> '||' <expr>` first as we should and everything else falls into its place. * Remove the bail-out that silenced the undefined behavior. Change-Id: Ibc1be79adc07792f0721f0dc08b50422b6da88a9 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/52067 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> |
||
---|---|---|
.. | ||
check-style | ||
check_lint_tests | ||
checkpatch.pl | ||
checkpatch_json.py | ||
const_structs.checkpatch | ||
description.md | ||
kconfig_lint | ||
kconfig_lint_README | ||
lint | ||
lint-000-license-headers | ||
lint-001-no-global-config-in-romstage | ||
lint-007-checkpatch | ||
lint-008-kconfig | ||
lint-014-qualified-types | ||
lint-extended-007-checkpatch | ||
lint-extended-015-final-newlines | ||
lint-extended-020-signed-off-by | ||
lint-stable-000-license-headers | ||
lint-stable-003-whitespace | ||
lint-stable-004-style-labels | ||
lint-stable-005-board-status | ||
lint-stable-006-board-name | ||
lint-stable-008-kconfig | ||
lint-stable-009-old-licenses | ||
lint-stable-010-asm-syntax | ||
lint-stable-012-executable-bit | ||
lint-stable-013-site-local | ||
lint-stable-016-non-ascii | ||
lint-stable-017-configs | ||
lint-stable-018-symlinks | ||
lint-stable-019-header-files | ||
lint-stable-021-coreboot-lowercase | ||
lint-stable-022-clang-format | ||
lint-stable-023-filenames | ||
lint-stable-024-kconfig-no-subsystem | ||
lint-stable-026-line-endings | ||
lint-stable-027-maintainers-syntax | ||
remccoms3.sed | ||
spelling.txt |