MCPcopy
hub / github.com/nltk/nltk / _read_seq_value

Method _read_seq_value

nltk/featstruct.py:2530–2564  ·  view source on GitHub ↗

Helper function used by read_tuple_value and read_set_value.

(
        self, s, position, reentrances, match, close_paren, seq_class, plus_class
    )

Source from the content-addressed store, hash-verified

2528 )
2529
2530 def _read_seq_value(
2531 self, s, position, reentrances, match, close_paren, seq_class, plus_class
2532 ):
2533 """
2534 Helper function used by read_tuple_value and read_set_value.
2535 """
2536 cp = re.escape(close_paren)
2537 position = match.end()
2538 # Special syntax of empty tuples:
2539 m = re.compile(r"\s*/?\s*%s" % cp).match(s, position)
2540 if m:
2541 return seq_class(), m.end()
2542 # Read values:
2543 values = []
2544 seen_plus = False
2545 while True:
2546 # Close paren: return value.
2547 m = re.compile(r"\s*%s" % cp).match(s, position)
2548 if m:
2549 if seen_plus:
2550 return plus_class(values), m.end()
2551 else:
2552 return seq_class(values), m.end()
2553
2554 # Read the next value.
2555 val, position = self.read_value(s, position, reentrances)
2556 values.append(val)
2557
2558 # Comma or looking at close paren
2559 m = re.compile(r"\s*(,|\+|(?=%s))\s*" % cp).match(s, position)
2560 if not m:
2561 raise ValueError("',' or '+' or '%s'" % cp, position)
2562 if m.group(1) == "+":
2563 seen_plus = True
2564 position = m.end()
2565
2566
2567######################################################################

Callers 2

read_tuple_valueMethod · 0.95
read_set_valueMethod · 0.95

Calls 5

read_valueMethod · 0.95
compileMethod · 0.80
endMethod · 0.45
matchMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected