How to use the translators.WorkUnit function in translators

To help you get started, we’ve selected a few translators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tallforasmurf / PPQT2 / translators.py View on Github external
# Extract the meaning of the received line.
        mob = TOKEN_X.match(line) # cannot fail
        assert mob is not None # something has to match

        # Store the parser token representing this line's contents
        # for the parser to read.

        tok = TOKEN_VALUE[ mob.lastgroup ]
        self.input = tok

        # If it is an empty line, we are done; we do not make WorkUnits for
        # empty lines.
        if tok == 'E' : return

        # Not an empty line, so make a work unit.
        unit = WorkUnit( self.line_number, tok, line )

        # If starting a bracketed group, set the switch for "looking for a
        # closing bracket". Remove boilerplate from the line text, and put
        # optional items in the stuff dict. Put the group-opening unit on
        # the WORK_UNITS list and continue with a Line unit.
        if tok in 'FIS' :
            self.find_bracket = True
            open_unit = unit.copy() # make an F/I/S unit with no text.
            WORK_UNITS.append( open_unit )
            self.input += 'L' # token input is FL, IL, or SL
            unit.tok = 'L' # second unit is a LINE
            if tok == 'F' :
                # remove [Footnote A: from LINE, save "A" in OPEN stuff
                hob = self.fnrex.match(line)
                open_unit.stuff['key'] = hob.group(1)
            elif tok == 'I' :
github tallforasmurf / PPQT2 / translators.py View on Github external
def event_generator( page_model, edit_model ) :
    global WORK_UNITS

    # When the actual lnum of a unit exceeds expect_lnum, and we are in a
    # no-flow section, we need to generate blank lines to fill in.
    in_no_flow = False
    expect_lnum = 1
    # Stack of container work units. Almost never gets more than 2 deep.
    stack = [ WorkUnit(0,XU.Events.LINE, '') ] # outermost context F/L/R
    # The "bracket" group (fnote, snote, illo) last seen, to be closed
    # when a ']' token appears.
    last_bracket = None
    # The index of the next scan image, if any, and the position at which it
    # starts in the source document. If there are no scan images, store a
    # start position that will never be reached.
    next_scan = 0
    scan_limit = page_model.page_count()
    next_scan_starts = page_model.position(0) if page_model.active() else int( 2**31 )
    # If in a table, all LINEs get special treatment.
    in_table = False
    columns = []

    for unit in WORK_UNITS :

        code = unit.tok
github tallforasmurf / PPQT2 / translators.py View on Github external
def copy( self ) :
        return WorkUnit(self.lnum, self.tok, '')
github tallforasmurf / PPQT2 / translators.py View on Github external
def close_note() :
    global WORK_UNITS
    '''
    A "]" has been parsed ending a Sidenote, Footnote or Illustration.
    Push a work unit to that effect. Get the line number from the
    previous work unit. If it has already happened, don't repeat it.
    '''
    if WORK_UNITS[-1].tok != ']' :
        unit = WorkUnit( WORK_UNITS[-1].lnum, ']', '' )
        WORK_UNITS.append( unit )