Skip to content

yex.parse.ListSource

yex.parse.ListSource(contents, name=None) #

Bases: yex.parse.source.Source

A source based on a list. Generally this is a list of strings, although you can use anything you want the tokeniser to find.

Multi-character strings are split into their component characters; any other entries are left as-is. For example, if you passed in

['a', 177, 'b', 'fred', 'c']
the tokeniser would receive

  • "a"
  • 177
  • "b"
  • "f"
  • "r"
  • "e"
  • "d"
  • "c"

Attributes:

Name Type Description
contents typing.List[typing.Any]

the list.

Source code in yex/parse/source.py
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
def __init__(self,
        contents,
        name = None):

    super().__init__(
            name = name or '<list>',
            )

    self.contents = []

    for item in list(contents):
        if isinstance(item, str) and len(item)>1:
            self.contents.extend([x for x in item])
        else:
            self.contents.append(item)

    logger.debug("%s:   -- list is: %s",
            self, contents)

    self.contents = contents
    self.column_number = 0
    self.line_number = None