-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOCSP-3615: Implement kind-of-working language server
- Loading branch information
Showing
25 changed files
with
633 additions
and
194 deletions.
There are no files selected for viewing
This file contains 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,4 +1,6 @@ | ||
__pycache__/ | ||
.mypy_cache/ | ||
*.pyc | ||
.DS_Store | ||
.DS_Store | ||
parser/snooty.py | ||
*.dist/ |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains 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,54 +1 @@ | ||
import yaml | ||
from yaml.composer import Composer | ||
from yaml.constructor import Constructor | ||
from typing import Dict, List, Tuple, Type, TypeVar | ||
from .flutter import check_type, LoadError | ||
from ..types import SerializableType | ||
from . import steps # NoQA | ||
|
||
_T = TypeVar('_T') | ||
|
||
|
||
class ParseError(Exception): | ||
pass | ||
|
||
|
||
def load_yaml(text: str) -> List[SerializableType]: | ||
loader = yaml.Loader(text) | ||
|
||
def compose_node(parent: yaml.nodes.Node, index: int) -> yaml.nodes.Node: | ||
# the line number where the previous token has ended (plus empty lines) | ||
line = loader.line | ||
node = Composer.compose_node(loader, parent, index) | ||
node.__line__ = line + 1 | ||
return node | ||
|
||
def construct_mapping(node: yaml.nodes.Node, deep: bool = False) -> Dict: | ||
mapping = Constructor.construct_mapping(loader, node, deep=deep) | ||
mapping['__line__'] = node.__line__ | ||
return mapping | ||
|
||
setattr(loader, 'compose_node', compose_node) | ||
setattr(loader, 'construct_mapping', construct_mapping) | ||
result: List[SerializableType] = [] | ||
while True: | ||
data = loader.get_data() | ||
if data: | ||
result.append(data) | ||
else: | ||
break | ||
|
||
return result | ||
|
||
|
||
def parse(ty: Type[_T], path: str) -> Tuple[List[_T], str]: | ||
with open(path, 'r') as f: | ||
text = f.read() | ||
|
||
parsed_yaml = load_yaml(text) | ||
|
||
try: | ||
parsed = [check_type(ty, data) for data in parsed_yaml] | ||
return parsed, text | ||
except LoadError as err: | ||
raise ParseError(str(err)) |
This file contains 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 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 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 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.