-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from Vanderhoof/feat/catch_up_syntax
Feat/catch up syntax
- Loading branch information
Showing
31 changed files
with
384 additions
and
29 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import re | ||
from typing import Any | ||
|
||
from pydbml.tools import indent | ||
|
||
|
||
class StickyNote: | ||
dont_compare_fields = ('database',) | ||
|
||
def __init__(self, name: str, text: Any) -> None: | ||
self.name = name | ||
self.text = str(text) if text is not None else '' | ||
|
||
self.database = None | ||
|
||
def __str__(self): | ||
''' | ||
>>> print(StickyNote('mynote', 'Note text')) | ||
StickyNote('mynote', 'Note text') | ||
''' | ||
|
||
return self.__class__.__name__ + f'({repr(self.name)}, {repr(self.text)})' | ||
|
||
def __bool__(self): | ||
return bool(self.text) | ||
|
||
def __repr__(self): | ||
''' | ||
>>> StickyNote('mynote', 'Note text') | ||
<StickyNote 'mynote', 'Note text'> | ||
''' | ||
|
||
return f'<{self.__class__.__name__} {self.name!r}, {self.text!r}>' | ||
|
||
def _prepare_text_for_dbml(self): | ||
'''Escape single quotes''' | ||
pattern = re.compile(r"('''|')") | ||
return pattern.sub(r'\\\1', self.text) | ||
|
||
@property | ||
def dbml(self): | ||
text = self._prepare_text_for_dbml() | ||
if '\n' in text: | ||
note_text = f"'''\n{text}\n'''" | ||
else: | ||
note_text = f"'{text}'" | ||
|
||
note_text = indent(note_text) | ||
result = f'Note {self.name} {{\n{note_text}\n}}' | ||
return result |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pyparsing as pp | ||
|
||
from .common import _, end, _c | ||
from .generic import string_literal, name | ||
from ..parser.blueprints import StickyNoteBlueprint | ||
|
||
sticky_note = _c + pp.CaselessLiteral('note') + _ + (name('name') + _ - '{' + _ - string_literal('text') + _ - '}') + end | ||
|
||
|
||
def parse_sticky_note(s, loc, tok): | ||
''' | ||
Note single_line_note { | ||
'This is a single line note' | ||
} | ||
''' | ||
init_dict = {'name': tok['name'], 'text': tok['text']} | ||
|
||
return StickyNoteBlueprint(**init_dict) | ||
|
||
|
||
sticky_note.set_parse_action(parse_sticky_note) |
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.