Browse code

add support for heredoc folding of lines

this change in the parser allows for us to have heredocs folded
into logical lines.

Change-Id: I51ebe6cd7b89b5f7194e947896f20b6750e972e3

Sean Dague authored on 2013/10/23 00:31:21
Showing 1 changed files
... ...
@@ -55,10 +55,41 @@ def check_indents(line):
55 55
             print_error('E003: Indent not multiple of 4', line)
56 56
 
57 57
 
58
+def starts_multiline(line):
59
+    m = re.search("[^<]<<\s*(?P<token>\w+)", line)
60
+    if m:
61
+        return m.group('token')
62
+    else:
63
+        return False
64
+
65
+
66
+def end_of_multiline(line, token):
67
+    if token:
68
+        return re.search("^%s\s*$" % token, line) is not None
69
+    return False
70
+
71
+
58 72
 def check_files(files):
73
+    in_multiline = False
74
+    logical_line = ""
75
+    token = False
59 76
     for line in fileinput.input(files):
60
-        check_no_trailing_whitespace(line)
61
-        check_indents(line)
77
+        # NOTE(sdague): multiline processing of heredocs is interesting
78
+        if not in_multiline:
79
+            logical_line = line
80
+            token = starts_multiline(line)
81
+            if token:
82
+                in_multiline = True
83
+                continue
84
+        else:
85
+            logical_line = logical_line + line
86
+            if not end_of_multiline(line, token):
87
+                continue
88
+            else:
89
+                in_multiline = False
90
+
91
+        check_no_trailing_whitespace(logical_line)
92
+        check_indents(logical_line)
62 93
 
63 94
 
64 95
 def get_options():