Skip to content

Commit

Permalink
sketch trike-literate-include
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Nov 8, 2024
1 parent 0bbc5c3 commit b8c9c2e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmake_modules/trike/test_trike.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def test_basic(tmp_path):
/// s
SCOPED
};
void foo() {
int a;
#/// floating but zeroes
#/// indentation
(void)a;
}
""",
)
file_content = trike.comment_scan(path, clang_args=[])
Expand Down Expand Up @@ -159,6 +168,11 @@ def test_basic(tmp_path):
next_line=11,
text=["/// floating something"],
),
Comment(
path,
next_line=44,
text=["/// floating but zeroes", "/// indentation"],
),
]

state = State.empty()
Expand Down
12 changes: 12 additions & 0 deletions cmake_modules/trike/trike/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def read_from_tokens(file: Path, tokens: Tokens) -> Self | None:

comment = Comment(file, t.extent.end.line + 1, [t.spelling])
for t in tokens:
if t.spelling == "#":
t = next(tokens)
if t.kind != TokenKind.COMMENT or t.extent.start.line > comment.next_line:
tokens.unget(t)
break
Expand Down Expand Up @@ -511,6 +513,15 @@ def run(self) -> list[Node]:
return []


class LiterateIncludeerateIncludeDirective(SphinxDirective):
"Include source files, interpreting floating /// as prose between code blocks"
has_content = False
required_arguments = 1

def run(self) -> list[Node]:
return []


class PutDirective(SphinxDirective):
"""
A directive which looks up a /// using its argument and the current
Expand Down Expand Up @@ -632,6 +643,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.add_directive(f"trike-{name}", PutDirective)

app.add_directive_to_domain("cpp", "module", CppModuleDirective)
#app.add_directive("trike-literate-include", LiterateIncludeDirective)

return {
"version": "0.1",
Expand Down

0 comments on commit b8c9c2e

Please sign in to comment.