-
Notifications
You must be signed in to change notification settings - Fork 736
refman: generate JSON indices #22044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shilangyu
wants to merge
5
commits into
rocq-prover:master
Choose a base branch
from
shilangyu:mw/computer-indices
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+302
−25
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5c205e2
doc: store subdomain data in a class
shilangyu c56278b
doc: serialize syntax for subdomain data
shilangyu 35b4f99
doc: generate JSON indices
shilangyu 93a34dd
doc: generate indices with custom builder
shilangyu 116aff8
doc: encode data unions in indices in an outer manner
shilangyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| from dataclasses import asdict, dataclass | ||
| from typing import Self | ||
|
|
||
| from .parsing import parse | ||
| from .TacticNotationsParser import TacticNotationsParser | ||
| from .TacticNotationsVisitor import TacticNotationsVisitor | ||
|
|
||
|
|
||
| class NotationObject: | ||
| def asdict(self): | ||
| return asdict(self) | ||
|
|
||
| TaggedNotationObject = tuple[str, NotationObject] | ||
|
|
||
| @dataclass | ||
| class Literal(NotationObject): | ||
| value: str | ||
| subscript: str | None | ||
| @classmethod | ||
| def new(cls, value: Self) -> tuple[str, Self]: | ||
| return ("Literal", value) | ||
|
|
||
| @dataclass | ||
| class Reference(NotationObject): | ||
| value: str | ||
| subscript: str | None | ||
| @classmethod | ||
| def new(cls, value: Self) -> tuple[str, Self]: | ||
| return ("Reference", value) | ||
|
|
||
| @dataclass | ||
| class Alternative(NotationObject): | ||
| children: list[TaggedNotationObject] | ||
| @classmethod | ||
| def new(cls, value: Self) -> tuple[str, Self]: | ||
| return ("Alternative", value) | ||
|
|
||
| @dataclass | ||
| class Repeat(NotationObject): | ||
| min: int | ||
| max: int | None | ||
| separator: str | None | ||
| children: list[TaggedNotationObject] | ||
| @classmethod | ||
| def new(cls, value: Self) -> tuple[str, Self]: | ||
| return ("Repeat", value) | ||
|
|
||
| class TacticNotationsToObjectVisitor(TacticNotationsVisitor): | ||
| def defaultResult(self): | ||
| return [] | ||
|
|
||
| def aggregateResult(self, aggregate, nextResult): | ||
| # Flattening results into a single list of nodes | ||
| if nextResult: | ||
| if isinstance(nextResult, list): | ||
| aggregate.extend(nextResult) | ||
| else: | ||
| aggregate.append(nextResult) | ||
| return aggregate | ||
|
|
||
| def visitAlternative(self, ctx: TacticNotationsParser.AlternativeContext): | ||
| return [Alternative.new(Alternative(children=self.visitChildren(ctx)))] | ||
|
|
||
| def visitAltblock(self, ctx: TacticNotationsParser.AltblockContext): | ||
| return self.visitChildren(ctx) | ||
|
|
||
| def visitRepeat(self, ctx: TacticNotationsParser.RepeatContext): | ||
| separator = ctx.ATOM() or ctx.PIPE() | ||
| # skip the '{' | ||
| repeat_marker = ctx.LGROUP().getText()[1] | ||
|
|
||
| min_rep, max_rep = None, None | ||
| match repeat_marker: | ||
| case "?": | ||
| min_rep, max_rep = 0, 1 | ||
| case "+": | ||
| min_rep, max_rep = 1, None | ||
| case "*": | ||
| min_rep, max_rep = 0, None | ||
| case _: | ||
| raise ValueError(f"Unexpected repeat marker: {repeat_marker}") | ||
|
|
||
| return [Repeat.new(Repeat( | ||
| min=min_rep, | ||
| max=max_rep, | ||
| separator=separator.getText() if separator else None, | ||
| children=self.visitChildren(ctx) | ||
| ))] | ||
|
|
||
| def visitCurlies(self, ctx: TacticNotationsParser.CurliesContext): | ||
| return [ | ||
| Literal.new(Literal(value=ctx.LBRACE().getText(), subscript=None)), | ||
| *self.visitChildren(ctx), | ||
| Literal.new(Literal(value=ctx.RBRACE().getText(), subscript=None))] | ||
|
|
||
| def visitAtomic(self, ctx: TacticNotationsParser.AtomicContext): | ||
| return [Literal.new(Literal( | ||
| value=ctx.ATOM().getText(), | ||
| # skip '__' | ||
| subscript=ctx.SUB().getText()[2:] if ctx.SUB() else None | ||
| ))] | ||
|
|
||
| def visitHole(self, ctx: TacticNotationsParser.HoleContext): | ||
| return [Reference.new(Reference( | ||
| value=ctx.ID().getText()[1:], | ||
| # skip '__' | ||
| subscript=ctx.SUB().getText()[2:] if ctx.SUB() else None | ||
| ))] | ||
|
|
||
| def visitEscaped(self, ctx: TacticNotationsParser.EscapedContext): | ||
| return [Literal.new(Literal( | ||
| value=ctx.ESCAPED().getText().replace("%", ""), | ||
| subscript=None | ||
| ))] | ||
|
|
||
| def objectify(notation: str) -> list[TaggedNotationObject]: | ||
| """Translate a notation into an object. | ||
|
|
||
| It is essentially a simplified and normalized version of the ANTLR AST. | ||
| """ | ||
| visitor = TacticNotationsToObjectVisitor() | ||
| return visitor.visit(parse(notation)) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.