Skip to content

Commit e6a01cf

Browse files
committed
lint: style fixes
1 parent a5f53db commit e6a01cf

File tree

5 files changed

+33
-40
lines changed

5 files changed

+33
-40
lines changed

parglare/cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ def viz(ctx, grammar_file):
113113
grammar, table = compile_get_grammar_table(grammar_file, debug, colors,
114114
prefer_shifts,
115115
prefer_shifts_over_empty)
116-
prints("Generating '%s.dot' file for the grammar PDA." % grammar_file)
116+
prints(f"Generating '{grammar_file}.dot' file for the grammar PDA.")
117117
prints("Use dot viewer (e.g. xdot) "
118-
"or convert to pdf by running 'dot -Tpdf -O %s.dot'" % grammar_file)
118+
f"or convert to pdf by running 'dot -Tpdf -O {grammar_file}.dot'")
119119
t.colors = False
120-
grammar_pda_export(table, "%s.dot" % grammar_file)
120+
grammar_pda_export(table, f"{grammar_file}.dot")
121121

122122

123123
@pglr.command()

parglare/exceptions.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ def __init__(self, context, actions):
7474
self.actions = actions
7575

7676
from parglare.parser import SHIFT
77-
message = "{}\nIn state {}:{} and input symbol '{}' after calling"\
78-
" dynamic disambiguation still can't decide "\
79-
.format(str(state), state.state_id, state.symbol, token)
77+
message = f"{str(state)}\nIn state {state.state_id}:{state.symbol} "\
78+
f"and input symbol '{token}' after calling"\
79+
" dynamic disambiguation still can't decide "
8080
if actions[0].action == SHIFT:
8181
prod_str = " or ".join([f"'{str(a.prod)}'"
8282
for a in actions[1:]])
@@ -140,9 +140,8 @@ def __str__(self):
140140
class LRConflicts(Exception):
141141
def __init__(self, conflicts):
142142
self.conflicts = conflicts
143-
message = "\n{} conflicts in following states: {}"\
144-
.format(self.kind,
145-
set([c.state.state_id for c in conflicts]))
143+
message = f"\n{self.kind} conflicts in following states: "\
144+
f"{set([c.state.state_id for c in conflicts])}"
146145
super().__init__(message)
147146

148147

parglare/glr.py

+16-19
Original file line numberDiff line numberDiff line change
@@ -592,28 +592,26 @@ def _trace_frontier(self):
592592
parents_processed = set()
593593

594594
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'
598597

599598
for step_no, step in enumerate(self._trace_frontier_steps):
600599
step_no += 1
601600
from_head, parent = step
602601
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'
606604
parents_processed.add(parent)
607605
if parent.production:
608606
# Reduce step
609607
label = f"R:{dot_escape(parent.production)}"
610608
else:
611609
# 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'
617615

618616
self._dot_trace_ranks += \
619617
'{{rank=same; {}; {}}}\n'.format(
@@ -627,14 +625,14 @@ def _trace_frontier(self):
627625
def _trace_step_kill(self, from_head):
628626
self._dot_trace += \
629627
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'
633631

634632
@no_colors
635633
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'
638636

639637
@no_colors
640638
def _trace_finish(self):
@@ -783,9 +781,8 @@ def __hash__(self):
783781
return hash(self.id)
784782

785783
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}]'
789786

790787
def __repr__(self):
791788
return str(self)

parglare/grammar.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,9 @@ def _make_symbols_resolution_map(self):
523523
if rec.value in terminals_by_str_rec:
524524
raise GrammarError(
525525
location=terminal.location,
526-
message='Terminals "{}" and "{}" match '
527-
'the same string.'
528-
.format(terminal.name,
529-
terminals_by_str_rec[rec.value].name))
526+
message=f'Terminals "{terminal.name}" and '
527+
f'"{terminals_by_str_rec[rec.value].name}" match '
528+
'the same string.')
530529
terminals_by_str_rec[rec.value] = terminal
531530
terminals_by_name[terminal.name] = terminal
532531

@@ -647,8 +646,8 @@ def _load_recognizers(self):
647646
if not isinstance(symbol, Terminal):
648647
raise GrammarError(
649648
location=Location(file_name=recognizers_file),
650-
message='Recognizer given for non-terminal "{}".'
651-
.format(recognizer_name))
649+
message='Recognizer given for non-terminal '
650+
f'"{recognizer_name}".')
652651
symbol.recognizer = recognizer
653652

654653
def resolve_symbol_by_name(

parglare/trees.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ def is_nonterm(self):
142142
return True
143143

144144
def __str__(self):
145-
return 'NonTerm({}, {}-{})'\
146-
.format(self.production.symbol,
147-
self.start_position, self.end_position)
145+
return f'NonTerm({self.production.symbol}, '\
146+
f'{self.start_position}-{self.end_position})'
148147

149148
def __iter__(self):
150149
return iter(self.children)
@@ -179,9 +178,8 @@ def is_term(self):
179178
return True
180179

181180
def __str__(self):
182-
return 'Term({} "{}", {}-{})'\
183-
.format(self.symbol, self.value[:20],
184-
self.start_position, self.end_position)
181+
return f'Term({self.symbol} "{self.value[:20]}", '\
182+
f'{self.start_position}-{self.end_position})'
185183

186184

187185
class Tree:

0 commit comments

Comments
 (0)