-
Notifications
You must be signed in to change notification settings - Fork 5
new syntaxes #2
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
Draft
Kyrela
wants to merge
12
commits into
w4rum:new-syntaxes
Choose a base branch
from
Kyrela:master
base: new-syntaxes
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.
Draft
new syntaxes #2
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f2940ea
Own implementation
Vioshim be4a614
Update parser.py
Vioshim 3a340b6
Update parser.py
Vioshim 7d7258d
Relative imports
Kyrela a23c122
Better Typehints
Kyrela 182b444
Missing NodeTypes (EMOJI_CUSTOM_ANIMATED, TIMESTAMP)
Kyrela 9eb841b
Better url regex (not vulnerable to ReDoS)
Kyrela 8d17721
Corrected style code
Kyrela 4d6ddcf
Match one-letter domains
Kyrela b936df8
Avoid complicated url regex
Kyrela 604231f
Update README.md
Kyrela 9e38d04
Follow RFC 1034 on TLD max length
Kyrela 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ venv | |
| .env | ||
| __pycache__ | ||
| runtime | ||
| poetry.lock | ||
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 |
|---|---|---|
| @@ -1,23 +1,30 @@ | ||
| from typing import Any, Dict, List | ||
| from typing import Any, Dict, List, Union | ||
|
|
||
| from discord_markdown_ast_parser.lexer import lex | ||
| from discord_markdown_ast_parser.parser import Node, parse_tokens | ||
| from .lexer import lex, Lexing | ||
| from .parser import Node, parse_tokens | ||
|
|
||
|
|
||
| def parse(text) -> List[Node]: | ||
| def lexing_list_convert(lexing: Union[List[Lexing], Lexing]) -> List[Lexing]: | ||
| if not isinstance(lexing, list): | ||
| lexing = [lexing] | ||
| return [Lexing(item) if isinstance(item, str) else item for item in lexing] | ||
|
|
||
|
|
||
| def parse(text, custom: Dict[str, List[Lexing]] = None) -> List[Node]: | ||
| """ | ||
| Parses the text and returns an AST, using this package's internal Node | ||
| representation. | ||
| See parse_to_dict for a more generic string representation. | ||
| """ | ||
| tokens = list(lex(text)) | ||
| return parse_tokens(tokens) | ||
| custom = custom if custom is not None else {} | ||
| custom = {k: lexing_list_convert(v) for k, v in custom.items()} | ||
| tokens = list(lex(text, custom)) | ||
| return parse_tokens(tokens, custom) | ||
|
|
||
|
|
||
| def parse_to_dict(text) -> List[Dict[str, Any]]: | ||
| def parse_to_dict(text, custom: Dict[str, List[Lexing]] = None) -> List[Dict[str, Any]]: | ||
| """ | ||
| Parses the text and returns an AST, represented as a dict. | ||
| See the README for information on the structure of this dict. | ||
| """ | ||
| node_ast = parse(text) | ||
| return [node.to_dict() for node in node_ast] | ||
| return [node.to_dict() for node in parse(text, custom)] |
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
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.
Uh oh!
There was an error while loading. Please reload this page.