Skip to content

Commit

Permalink
[devtools] Fix more bad HTML
Browse files Browse the repository at this point in the history
Caught by data_lang/htm8-test.sh

There is some in the clang-coverage report, which is not too surprising!
  • Loading branch information
Andy C committed Jan 10, 2025
1 parent e6e0c65 commit 91263bb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data_lang/htm8-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test-site() {
popd
}

readonly SOIL_ID=8913
readonly SOIL_ID=8915
readonly WWZ_DIR=_tmp/$SOIL_ID

sync-wwz() {
Expand Down
3 changes: 0 additions & 3 deletions doc/proc-func.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,6 @@ This table shows simpler, more common cases.
<td colspan=3 style="text-align: center; padding: 3em">...</td>
</tr>
</td>
</tr>
<tr>
<td>Named Args</td>
<td>
Expand Down
21 changes: 20 additions & 1 deletion lazylex/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ def __str__(self):
return '(LexError %r)' % (self.s[self.start_pos:self.start_pos + 20])


def FindLineNum(s, error_pos):
current_pos = 0
line_num = 1
while True:
newline_pos = s.find('\n', current_pos)
#log('current = %d, N %d, line %d', current_pos, newline_pos, line_num)

if newline_pos == -1: # this is the last line
return line_num
if newline_pos >= error_pos:
return line_num
line_num += 1
current_pos = newline_pos + 1


class ParseError(Exception):
"""
Examples of parse errors
Expand All @@ -58,9 +73,13 @@ def __str__(self):
if self.s is not None:
assert self.start_pos != -1, self.start_pos
snippet = (self.s[self.start_pos:self.start_pos + 20])

line_num = FindLineNum(self.s, self.start_pos)
else:
snippet = ''
return '(ParseError %r %r)' % (self.msg, snippet)
line_num = -1
msg = 'line %d: %r %r' % (line_num, self.msg, snippet)
return msg


class Output(object):
Expand Down
9 changes: 9 additions & 0 deletions lazylex/html_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def testDotAll(self):
print(p4.match('\n'))


class FunctionsTest(unittest.TestCase):

def testFindLineNum(self):
s = 'foo\n' * 3
for pos in [1, 5, 10, 50]: # out of bounds
line_num = html.FindLineNum(s, pos)
print(line_num)


class TagLexerTest(unittest.TestCase):

def testTagLexer(self):
Expand Down
4 changes: 2 additions & 2 deletions soil/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _ParsePullTime(time_p_str):
</tr>
<tr class="spacer">
<td><td/>
<td></td>
</tr>
</table>
Expand Down Expand Up @@ -433,7 +433,7 @@ def ParseJobs(stdin):
</tr>
<tr class="spacer">
<td colspan=2><td/>
<td colspan=2></td>
</tr>
''')

Expand Down
2 changes: 1 addition & 1 deletion test/wild_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def MakeHtmlGroup(title_str, body_str):
{.end}
{.if test top_level_links}
<a href="version-info.txt">Date and OSH version<a>
<a href="version-info.txt">Date and OSH version</a>
{.end}
<!-- page globals -->
Expand Down

0 comments on commit 91263bb

Please sign in to comment.