Skip to content

Commit

Permalink
Allow <<boolean[<<foo>>]>> to be parsed. Also fix some new things fro…
Browse files Browse the repository at this point in the history
…m the ruff update.
  • Loading branch information
tabatkins committed Oct 28, 2024
1 parent 3686d71 commit 57df606
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bikeshed/Spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def printTargets(self) -> None:
def isOpaqueElement(self, el: t.ElementT) -> bool:
if el.tag in self.md.opaqueElements:
return True
if el.get("data-opaque") is not None or el.get("bs-opaque") is not None: # noqa needless-bool
if el.get("data-opaque") is not None or el.get("bs-opaque") is not None: # needless-bool
return True
return False

Expand Down
8 changes: 4 additions & 4 deletions bikeshed/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,12 @@ def handleProfile(options: argparse.Namespace) -> None:
root = f'--root="{options.root}"' if options.root else ""
leaf = f'--leaf="{options.leaf}"' if options.leaf else ""
if options.svgFile:
os.system( # noqa s605
f"time python -m cProfile -o stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} stat.prof | dot -Tsvg -o {options.svgFile} && rm stat.prof",
os.system(
f"time python -m cProfile -o stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} stat.prof | dot -Tsvg -o {options.svgFile} && rm stat.prof", # noqa: S605
)
else:
os.system( # noqa s605
f"time python -m cProfile -o /tmp/stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} /tmp/stat.prof | xdot &",
os.system(
f"time python -m cProfile -o /tmp/stat.prof -m bikeshed -f spec && gprof2dot -f pstats --skew=.0001 {root} {leaf} /tmp/stat.prof | xdot &", # noqa: S605
)


Expand Down
2 changes: 1 addition & 1 deletion bikeshed/doctypes/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def looselyMatch(self, rawStatus: str) -> bool:
orgName, statusName = utils.splitOrg(rawStatus)
if statusName and self.name.upper() != statusName.upper():
return False
if orgName and self.org.name != orgName.upper(): # noqa needless-bool
if orgName and self.org.name != orgName.upper(): # needless-bool
return False
return True

Expand Down
4 changes: 2 additions & 2 deletions bikeshed/h/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def validUrlUnit(char: str) -> bool:
else:
if 0xD800 <= c <= 0xDFFF or 0xFDD0 <= c <= 0xFDEF:
return False
if (c % 0xFFFF) in [0xFFFE, 0xFFFF]: # noqa needless-bool
if (c % 0xFFFF) in [0xFFFE, 0xFFFF]: # needless-bool
# Last two bytes are FFFE or FFFF
return False
return True
Expand Down Expand Up @@ -737,7 +737,7 @@ def isOddNode(node: t.Any) -> bool:
# Something other than an element node or string.
if isinstance(node, str):
return False
if isElement(node): # noqa needless-bool
if isElement(node): # needless-bool
return False
return True

Expand Down
30 changes: 22 additions & 8 deletions bikeshed/h/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ParserNode,
RawElement,
RawText,
SafeText,
SelfClosedTag,
StartTag,
escapeAttr,
Expand Down Expand Up @@ -704,18 +705,31 @@ def parseCSSProduction(s: Stream, start: int) -> Result[list[ParserNode]]:
if text is None:
m.die("Saw the start of a CSS production (like <<foo>>), but couldn't find the end.", lineNum=s.loc(start))
return Result.fail(start)
if "\n" in text:
elif "\n" in text:
m.die(
"Saw the start of a CSS production (like <<foo>>), but couldn't find the end on the same line.",
lineNum=s.loc(start),
)
return Result.fail(start)
if "<" in text or ">" in text:
m.die(
"It seems like you wrote a CSS production (like <<foo>>), but there's more markup inside of it, or you didn't close it properly.",
lineNum=s.loc(start),
)
return Result.fail(start)
elif "<" in text or ">" in text:
# Allow <<boolean [<<foo>>]>>
if "[" in text:
endOfArg = s.skipTo(textEnd, "]").i
newTextEnd = s.skipTo(endOfArg, ">>").i
if endOfArg == textEnd or newTextEnd == endOfArg: # noqa: PLR1714
m.die(
"It seems like you wrote a CSS production with an argument (like <<foo [<<bar>>]>>), but either included more [] in the argument, or otherwise messed up the syntax.",
lineNum=s.loc(start),
)
return Result.fail(start)
textEnd = newTextEnd
text = s[textStart:textEnd]
else:
m.die(
"It seems like you wrote a CSS production (like <<foo>>), but there's more markup inside of it, or you didn't close it properly.",
lineNum=s.loc(start),
)
return Result.fail(start)
nodeEnd = textEnd + 2

startTag = StartTag(
Expand All @@ -724,7 +738,7 @@ def parseCSSProduction(s: Stream, start: int) -> Result[list[ParserNode]]:
tag="fake-production-placeholder",
attrs={"bs-autolink-syntax": s[start:nodeEnd], "class": "production", "bs-opaque": ""},
).finalize()
contents = RawText(
contents = SafeText(
line=s.line(textStart),
endLine=s.line(textEnd),
text=text,
Expand Down
4 changes: 2 additions & 2 deletions bikeshed/h/parser/preds.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ def isTagnameChar(ch: str) -> bool:
return True
if 0xFDF0 <= cp <= 0xFFFD:
return True
if 0x10000 <= cp <= 0xEFFFF: # noqa needless-bool
if 0x10000 <= cp <= 0xEFFFF: # needless-bool
return True
return False


def isAttrNameChar(ch: str) -> bool:
if len(ch) != 1:
return False
if isWhitespace(ch) or ch in "/<>=\"'" or ord(ch) == 0: # noqa needless-bool
if isWhitespace(ch) or ch in "/<>=\"'" or ord(ch) == 0: # needless-bool
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion bikeshed/h/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def needsEndTag(self, el: t.ElementT, nextEl: Nodes | None = None) -> bool:
if el.tag in ["dt", "dd"]:
if nextEl is None:
return False
if self.isElement(nextEl) and nextEl.tag in ["dt", "dd"]: # noqa needless-bool
if self.isElement(nextEl) and nextEl.tag in ["dt", "dd"]: # needless-bool
return False
return True
return False
Expand Down
29 changes: 25 additions & 4 deletions bikeshed/shorthands/oldShorthands.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ def transformProductionPlaceholders(doc: t.SpecT) -> None:
""",
re.X,
)
typeWithArgsRe = re.compile(
r"""
^(?:(\S*)/)?
(\S+)
\s*\[([^\]]+)\]\s*$
""",
re.X,
)
for el in h.findAll("fake-production-placeholder", doc):
addLineNumber(el)
text = h.textContent(el)
h.clearContents(el)
match = propdescRe.match(text)
lt = text
match = propdescRe.match(lt)
if match:
linkFor, lt, linkType = match.groups()
if linkFor == "":
Expand All @@ -55,7 +64,7 @@ def transformProductionPlaceholders(doc: t.SpecT) -> None:
el.set("for", linkFor)
el.text = "<'" + lt + "'>"
continue
match = funcRe.match(text)
match = funcRe.match(lt)
if match:
el.tag = "a"
el.set("data-link-type", "function")
Expand All @@ -64,7 +73,7 @@ def transformProductionPlaceholders(doc: t.SpecT) -> None:
el.set("for", match.group(1))
el.text = "<" + match.group(2) + ">"
continue
match = atruleRe.match(text)
match = atruleRe.match(lt)
if match:
el.tag = "a"
el.set("data-link-type", "at-rule")
Expand All @@ -73,7 +82,7 @@ def transformProductionPlaceholders(doc: t.SpecT) -> None:
el.set("for", match.group(1))
el.text = "<" + match.group(2) + ">"
continue
match = typeRe.match(text)
match = typeRe.match(lt)
if match:
for_, term, rangeStart, rangeEnd = match.groups()
el.tag = "a"
Expand All @@ -98,6 +107,18 @@ def transformProductionPlaceholders(doc: t.SpecT) -> None:
else:
el.text = f"<{term}>"
continue
match = typeWithArgsRe.match(lt)
if match:
for_, term, arg = match.groups()
el.tag = "a"
el.set("data-lt", f"<{term}>")
el.set("data-link-type", "type")
if "<<" in arg:
arg = arg.replace("<<", "<").replace(">>", ">")
el.text = f"<{term}[{arg}]>"
if for_ is not None:
el.set("for", for_)
continue
m.die(f"Shorthand <<{text}>> does not match any recognized shorthand grammar.", el=el)
el.tag = "span"
el.text = el.get("bs-autolink-syntax")
Expand Down
2 changes: 1 addition & 1 deletion bikeshed/stylescript/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def insertable(self, allowList: t.BoolSet) -> bool:
return False
if self.data is None:
return True
if self.data[1]: # noqa needless-bool
if self.data[1]: # needless-bool
return True
return False

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ disable = [
"c-extension-no-member", # seems to be weird false pos
"consider-iterating-dictionary", # lol no
"consider-using-f-string", # don't care
"consider-using-in", # ruff does this
"duplicate-code", # dont' care
"eval-used", # needed
"exec-used", # needed
Expand Down

0 comments on commit 57df606

Please sign in to comment.