From owner-svn-src-head@freebsd.org Tue Aug 21 23:42:21 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C38931083181; Tue, 21 Aug 2018 23:42:21 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 76229741E5; Tue, 21 Aug 2018 23:42:21 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 573522DF0; Tue, 21 Aug 2018 23:42:21 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7LNgLvF051334; Tue, 21 Aug 2018 23:42:21 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7LNgLp7051333; Tue, 21 Aug 2018 23:42:21 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808212342.w7LNgLp7051333@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 21 Aug 2018 23:42:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338168 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 338168 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Aug 2018 23:42:22 -0000 Author: kevans Date: Tue Aug 21 23:42:20 2018 New Revision: 338168 URL: https://svnweb.freebsd.org/changeset/base/338168 Log: lualoader: Refactor config line expressions A couple of issues addressed: 1.) Modules with - in the name were not recognized as modules 2.) The module regex was repeated for each place a module name may appear 3.) The 'strip leading space' bits were repeated for each expression 4.) The trailing 'comment validation' stuff was repeated every expression #4 still has some more work to be done. exec lines, for instance, don't capture a 'value' -- there's only one capture pattern. This throws off the 'c' value that we match, so the trailing bits aren't *actually* being validated. This isn't a new issue, though, so a future comit will address this. Modified: head/stand/lua/config.lua Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Tue Aug 21 23:34:30 2018 (r338167) +++ head/stand/lua/config.lua Tue Aug 21 23:42:20 2018 (r338168) @@ -54,6 +54,8 @@ local MSG_KERNLOADING = "Loading kernel..." local MSG_MODLOADING = "Loading configured modules..." local MSG_MODLOADFAIL = "Could not load one or more modules!" +local MODULEEXPR = '([%w-_]+)' + local function restoreEnv() -- Examine changed environment variables for k, v in pairs(env_changed) do @@ -121,14 +123,19 @@ local function processEnvVar(value) return value end +-- str in this table is a regex pattern. It will automatically be anchored to +-- the beginning of a line and any preceding whitespace will be skipped. The +-- pattern should have no more than two captures patterns, which correspond to +-- the two parameters (usually 'key' and 'value') that are passed to the +-- process function. All trailing characters will be validated. local pattern_table = { { - str = "^%s*(#.*)", + str = "(#.*)", process = function(_, _) end, }, -- module_load="value" { - str = "^%s*([%w_]+)_load%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = MODULEEXPR .. "_load%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) if modules[k] == nil then modules[k] = {} @@ -138,49 +145,49 @@ local pattern_table = { }, -- module_name="value" { - str = "^%s*([%w_]+)_name%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = MODULEEXPR .. "_name%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) setKey(k, "name", v) end, }, -- module_type="value" { - str = "^%s*([%w_]+)_type%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = MODULEEXPR .. "_type%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) setKey(k, "type", v) end, }, -- module_flags="value" { - str = "^%s*([%w_]+)_flags%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = MODULEEXPR .. "_flags%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) setKey(k, "flags", v) end, }, -- module_before="value" { - str = "^%s*([%w_]+)_before%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = MODULEEXPR .. "_before%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) setKey(k, "before", v) end, }, -- module_after="value" { - str = "^%s*([%w_]+)_after%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = MODULEEXPR .. "_after%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) setKey(k, "after", v) end, }, -- module_error="value" { - str = "^%s*([%w_]+)_error%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = MODULEEXPR .. "_error%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) setKey(k, "error", v) end, }, -- exec="command" { - str = "^%s*exec%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = "exec%s*=%s*\"([%w%s%p]-)\"", process = function(k, _) if cli_execute_unparsed(k) ~= 0 then print(MSG_FAILEXEC:format(k)) @@ -189,7 +196,7 @@ local pattern_table = { }, -- env_var="value" { - str = "^%s*([%w%p]+)%s*=%s*\"([%w%s%p]-)\"%s*(.*)", + str = "([%w%p]+)%s*=%s*\"([%w%s%p]-)\"", process = function(k, v) if setEnv(k, processEnvVar(v)) ~= 0 then print(MSG_FAILSETENV:format(k, v)) @@ -198,7 +205,7 @@ local pattern_table = { }, -- env_var=num { - str = "^%s*([%w%p]+)%s*=%s*(-?%d+)%s*(.*)", + str = "([%w%p]+)%s*=%s*(-?%d+)", process = function(k, v) if setEnv(k, processEnvVar(v)) ~= 0 then print(MSG_FAILSETENV:format(k, tostring(v))) @@ -390,7 +397,8 @@ function config.parse(text) local found = false for _, val in ipairs(pattern_table) do - local k, v, c = line:match(val.str) + local pattern = '^%s*' .. val.str .. '%s*(.*)'; + local k, v, c = line:match(pattern) if k ~= nil then found = true