ngdb.parser
Norton Guide parser for the text inside a guide.
CTRL_CHAR
module-attribute
CTRL_CHAR = '^'
The control character that marks an upcoming attribute.
BaseParser
BaseParser(line)
The base text parsing class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The raw string to parse. |
required |
bold
bold()
Handle being asked to go to bold mode.
char
char(char)
Handle an individual character value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The character value to handle. |
required |
colour
colour(colour)
Handle the given colour value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
int
|
The colour value to handle. |
required |
normal
normal()
Handle being asked to go to normal mode.
reverse
reverse()
Handle being asked to go to reverse mode.
text
text(text)
Handle the given text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The text to handle. |
required |
unbold
unbold()
Handle being asked to go out of bold mode.
underline
underline()
Handle being asked to go in underline mode.
unreverse
unreverse()
Handle being asked to go out of reverse mode.
ununderline
ununderline()
Handle being asked to go out of underline mode.
MarkupText
MarkupText(line)
Read a line of Norton Guide text and mark up with start/end tags.
This is an abstract base class for other parser classes that will implement start and end tags where necessary.
begin_markup
begin_markup(cls)
Start a section of markup.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The class for the markup. |
required |
Note
As a side-effect of calling on this, the close_markup
for
the same class will be placed on an internal stack, for use when
end_markup
is called.
close_markup
abstractmethod
close_markup(cls)
end_markup
end_markup()
End a section of markup.
normal
normal()
Handle being asked to go to normal mode.
Note
Internally this also clears the whole stack of closing tags.
ParseState
ParseState(line)
Raw text parsing state tracking class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The line to work on. |
required |
ctrl_id
property
ctrl_id
The current control ID.
last_attr
instance-attribute
last_attr = -1
The last attribute encountered.
work_left
property
work_left
Is there any work left to do?
PlainText
PlainText(line)
RichText
RichText(line)
Bases: MarkupText
Read a line of Norton Guide text and mark up with Rich console markup.
Note
This is implemented in a way that doesn't require that Rich is a dependency of this library. This is provided here as a test and a handy example, and one that uses Rich's plain text BBCode-a-like markup.
COLOUR_MAP
class-attribute
instance-attribute
COLOUR_MAP = {
1: 4,
3: 6,
4: 1,
6: 3,
9: 21,
11: 14,
12: 196,
14: 11,
}
DOS to Rich colour mapping. This is just the exceptions.