commit 42c0f415a04631022eb9a77a8b33890247d224ec
parent ffb98de24e80c64f096e40a3b96ec35ee6543aff
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date:   Sat, 18 Jan 2020 14:39:16 +0000
Warn if line starts with tabs rather than spaces
Diffstat:
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/tyarn.lua.in b/tyarn.lua.in
@@ -40,13 +40,23 @@ function normalise_scenario_line(str, step_type)
 end
 
 function parse_implementations(filepath, implementations)
-    file, err = io.open(filepath)
+    local line_no = 0
+    local file, err = io.open(filepath)
     if file == nil then
         io.stderr:write(string.format("Couldn't open implementation file: %s\n", filepath, err))
         os.exit(1)
     end
 
     for line in file:lines() do
+        line_no = line_no + 1
+
+        if tyarn.re_match(line, "^\t+") then
+            io.stderr:write(string.format(
+                "Warning `%s' in implementation file %s (line %s) " ..
+                "starts with tabs instead of spaces, ignoring\n",
+                line, filepath, line_no))
+        end
+
         -- ignore lines that are not indented or blank
         matched, matches = tyarn.re_match(line, "^(    )+[^ \t\n\r\f\v]+")
         line = string.gsub(line, '    ', '', 1) -- strip first 4 spaces
@@ -157,7 +167,8 @@ function parse_scenario_line(scenario, scenario_name, steps_seen,
     return last_step_type
 end
 
-function _parse_scenarios(scenario_list, scenarios, file, scenario_name, scenario_line_no)
+function _parse_scenarios(scenario_list, scenarios, filepath,
+                          file, scenario_name, scenario_line_no)
     debug('Parsing scenario', scenario_name)
     last_step_type = nil
     scenario = {}
@@ -169,6 +180,13 @@ function _parse_scenarios(scenario_list, scenarios, file, scenario_name, scenari
     for line in file:lines() do
         line_no = line_no + 1
 
+        if tyarn.re_match(line, "^\t+") then
+            io.stderr:write(string.format(
+                "Warning `%s' in scenario file %s (line %s) " ..
+                "starts with tabs instead of spaces, ignoring\n",
+                line, filepath, line_no))
+        end
+
         if string.len(line) == 0 then
             -- blank line
             in_scenario = false
@@ -191,7 +209,8 @@ function _parse_scenarios(scenario_list, scenarios, file, scenario_name, scenari
 
             -- now onto the next scenario
             scenario_name = matches[2]
-            _parse_scenarios(scenario_list, scenarios, file, scenario_name, line_no)
+            _parse_scenarios(scenario_list, scenarios, filepath,
+                             file, scenario_name, line_no)
             return
         end
     end
@@ -234,7 +253,7 @@ function parse_scenarios(filepath)
     end
 
     -- now we have the base case, begin the recursion
-    _parse_scenarios(scenario_list, scenarios, file, scenario_name, line_no)
+    _parse_scenarios(scenario_list, scenarios, filepath, file, scenario_name, line_no)
 
     return scenario_list, scenarios
 end