3.1.6. OpcodeParser

This modules provides tools to parse TeX stream like DVI file and PK Font.

class PyDvi.OpcodeParser.OpcodeParserSet(opcode_definitions)[source]

Bases: list

This class defines an opcode parser set.

The parameter opcode_definitions is a tuple of ‘opcode definition’.

An opcode definition is a tuple that corresponds to the parameters of the OpcodeParser constructor. Except that the opcode byte can be a list that defines a range of opcode bytes. In this case the opcode is duplicated in the opcode range. Moreover the parameter’s definition can be a list that defines a range for a mono parameter set of opcodes. For example [1,4] will create successively an opcode with 1 to 4-byte unsigned parameter with an incremental opcode byte starting from the one specified.

Usage summary:

opcode_definitions : (opcode_definition, ...)

opcode_definition : 
  (opcode_indexes, opcode_name, opcode_description, opcode_parameters=(), opcode_class=None) |
  (opcode_indexes, opcode_parser_class),

opcode_indexes :
  index |
  [lower_index, upper_index] # duplicate the opcode in the range

opcode_parameters :
  (p0, p1, ...) |
  ([lower_n, upper_n]) # opcode at [index + i] has parameter p[i]
_init_opcode_parser(opcode_definition)[source]

Build the set.

class PyDvi.OpcodeParser.OpcodeParser(opcode, name, description, parameters=(), opcode_class=None)[source]

Bases: object

This class implements an opcode parser.

The argument opcode defines the opcode byte.

The argument name and description defines the name and a description string, respectively.

The argument parameters is a tuple that defines the parameters of the opcode. Each item is an integer that gives the number of bytes of the parameter. If this number is negative then the parameter is a signed integer. For example (2, -3) defines an opcode having as parameters a 2-byte unsigned integer followed by a 3-byte signed integer.

The optional opcode_class defines an PyDvi.DviMachine.Opcode subclass for the opcode.

_init_parameter_readers(parameters)[source]
read_parameters(opcode_parser)[source]

Read the opcode parameters.

to_opcode(args)[source]

Return an an PyDvi.DviMachine.Opcode subclass isntance.