Some functional util code

This commit is contained in:
Jamie Hardt
2021-05-31 15:16:23 -07:00
parent 2e08499f70
commit 3502eaddfd
2 changed files with 14 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
from fractions import Fraction from fractions import Fraction
from ptulsconv.broadcast_timecode import smpte_to_frame_count from ptulsconv.broadcast_timecode import smpte_to_frame_count
from typing import Tuple, List from typing import Tuple, List, Generator
from . import apply_appends
from .tagged_string_parser_visitor import parse_tags
class SessionDescriptor: class SessionDescriptor:

View File

@@ -1,5 +1,12 @@
from parsimonious import NodeVisitor, Grammar from parsimonious import NodeVisitor, Grammar
from typing import Dict, Optional from typing import Dict, Optional
from enum import Enum
class TagPreModes(Enum):
NORMAL = 'Normal'
APPEND = 'Append'
TIMESPAN = 'Timespan'
tag_grammar = Grammar( tag_grammar = Grammar(
@@ -16,7 +23,7 @@ tag_grammar = Grammar(
tag_junk = word word_sep? tag_junk = word word_sep?
word = ~"[^ \[\{\$][^ ]*" word = ~"[^ \[\{\$][^ ]*"
word_sep = ~" +" word_sep = ~" +"
modifier = ("@" / "&" / "!") word_sep? modifier = ("@" / "&") word_sep?
""" """
) )
@@ -55,13 +62,11 @@ class TagListVisitor(NodeVisitor):
@staticmethod @staticmethod
def visit_modifier(node, _): def visit_modifier(node, _):
if node.text.startswith('@'): if node.text.startswith('@'):
return 'Timespan' return TagPreModes.TIMESPAN
elif node.text.startswith('&'): elif node.text.startswith('&'):
return 'Append' return TagPreModes.APPEND
elif node.text.startswith('!'):
return 'Movie'
else: else:
return 'Normal' return TagPreModes.NORMAL
@staticmethod @staticmethod
def visit_tag_list(_, visited_children): def visit_tag_list(_, visited_children):