@@ -592,28 +592,26 @@ def _trace_frontier(self):
592
592
parents_processed = set ()
593
593
594
594
for head in self ._trace_frontier_heads :
595
- self ._dot_trace += '{} [label="{}. {}:{}"];\n ' \
596
- .format (head .key , head .frontier , head .state .state_id ,
597
- dot_escape (head .state .symbol .name ))
595
+ self ._dot_trace += f'{ head .key } [label="{ head .frontier } . ' \
596
+ f'{ head .state .state_id } :{ dot_escape (head .state .symbol .name )} "];\n '
598
597
599
598
for step_no , step in enumerate (self ._trace_frontier_steps ):
600
599
step_no += 1
601
600
from_head , parent = step
602
601
if parent not in parents_processed :
603
- self ._dot_trace += '{} -> {} [label="{}"];\n ' \
604
- .format (parent .head .key , parent .root .key ,
605
- parent .ambiguity )
602
+ self ._dot_trace += f'{ parent .head .key } -> { parent .root .key } ' \
603
+ f'[label="{ parent .ambiguity } "];\n '
606
604
parents_processed .add (parent )
607
605
if parent .production :
608
606
# Reduce step
609
607
label = f"R:{ dot_escape (parent .production )} "
610
608
else :
611
609
# Shift step
612
- label = "S:{}({})" . format ( dot_escape (parent .token .symbol .name ),
613
- dot_escape (parent .token .value ))
614
- self ._dot_trace += '{ } -> {} [label="{}.{} {}" {}]; \n ' . format (
615
- from_head . key , parent . head . key , parent .head .frontier , step_no ,
616
- label , TRACE_DOT_STEP_STYLE )
610
+ label = f "S:{ dot_escape (parent .token .symbol .name )} " \
611
+ f"( { dot_escape (parent .token .value )} )"
612
+ self ._dot_trace += f' { from_head . key } -> { parent . head . key } ' \
613
+ f'[label=" { parent .head .frontier } . { step_no } ' \
614
+ f' { label } " { TRACE_DOT_STEP_STYLE } ]; \n '
617
615
618
616
self ._dot_trace_ranks += \
619
617
'{{rank=same; {}; {}}}\n ' .format (
@@ -627,14 +625,14 @@ def _trace_frontier(self):
627
625
def _trace_step_kill (self , from_head ):
628
626
self ._dot_trace += \
629
627
f'{ from_head .key } _killed [shape="diamond" fillcolor="red" label="killed"];\n '
630
- self ._dot_trace += '{} -> {}_killed [label="{}." {}]; \n ' \
631
- . format ( from_head .key , from_head .key , self . _debug_step_str (),
632
- TRACE_DOT_STEP_STYLE )
628
+ self ._dot_trace += \
629
+ f' { from_head .key } -> { from_head .key } _killed ' \
630
+ f'[label=" { self . _debug_step_str () } ." { TRACE_DOT_STEP_STYLE } ]; \n '
633
631
634
632
@no_colors
635
633
def _trace_step_drop (self , from_head , to_head ):
636
- self ._dot_trace += '{ } -> {} [label="drop empty" {}]; \n ' \
637
- . format ( from_head . key , to_head . key , TRACE_DOT_DROP_STYLE )
634
+ self ._dot_trace += f' { from_head . key } -> { to_head . key } ' \
635
+ f'[label="drop empty" { TRACE_DOT_DROP_STYLE } ]; \n '
638
636
639
637
@no_colors
640
638
def _trace_finish (self ):
@@ -783,9 +781,8 @@ def __hash__(self):
783
781
return hash (self .id )
784
782
785
783
def __str__ (self ):
786
- return '{}({})<-{}({}) [{}]' .format (
787
- self .root .id , self .root .symbol , self .head .id , self .head .symbol ,
788
- self .ambiguity )
784
+ return f'{ self .root .id } ({ self .root .symbol } )<-{ self .head .id } ' \
785
+ f'({ self .head .symbol } ) [{ self .ambiguity } ]'
789
786
790
787
def __repr__ (self ):
791
788
return str (self )
0 commit comments