czech_plus.logic.lexer
#
Package for parsing input from the cards.
Submodules#
Package Contents#
Classes#
Main class for transforming raw strings to tokens. |
|
Lexer for nouns. |
|
Lexer for verbs. |
|
Lexer for adjectives. |
Functions#
|
By default, Anki removes all asserts from the code, so we need to craft own assert. |
Attributes#
- assert_that(statement: bool, msg: str = '', /) None [source]#
By default, Anki removes all asserts from the code, so we need to craft own assert.
Example
assert next(generator) == str # if this statement will not be executed - everything will fail.
- class BaseLexer[source]#
Bases:
abc.ABC
Main class for transforming raw strings to tokens.
- property _hooks: dict[str, _HOOK_SIGNATURE][source]#
Dict, where first element is symbol for hook, and value is a hook.
See
_handle_hook()
for hook signature description.
- lex(string: str) collections.abc.Iterator[tokens.BaseToken | str] [source]#
Lex
string
argument.
- _handle_hook(hook: _HOOK_SIGNATURE) _ON_NEXT_HOOK [source]#
Handle hook and yield result.
Note
You can send these params, with
generator.send
method. It takesstring
orNone
, wherestring
means next symbol, andNone
- end of input.- Returns:
Note
This value can be accessed with
StopIteration
.value
.Tuple
with two elements, where both arebool
s. First is whether you need to rerun this symbol with new hook, and second one whether you need to skip next symbol.
Example
handle_hook_generator = _handle_hook(hook) while True: try: token = next(handle_hook_generator) except StopIteration as exception: rerun, skip = exception.value # return statement in generator break else: # some token handling code
Or you can ignore
rerun
andskip
variables:for token in _handle_hook(): # some token handling code
- _escape_one_symbol() _HOOK_GENERATOR_SIGNATURE [source]#
Escape one symbol.
See
_handle_hook()
for signature description.
- _escape_entire_word() _HOOK_GENERATOR_SIGNATURE [source]#
Escape entire word.
See
_handle_hook()
for signature description.
- _separate_words() _HOOK_GENERATOR_SIGNATURE [source]#
Separate words.
See
_handle_hook()
for signature description.
- _additional_separate_words() _HOOK_GENERATOR_SIGNATURE [source]#
Separate words with additional separate symbol.
See
_handle_hook()
for signature description.
- _skip_word() _HOOK_GENERATOR_SIGNATURE [source]#
Skip word.
See
_handle_hook()
for signature description.
- class VerbLexer[source]#
Bases:
BaseLexer
Lexer for verbs.
- property _hooks: dict[str, _HOOK_SIGNATURE][source]#
Dict, where first element is symbol for hook, and value is a hook.
See
_handle_hook()
for hook signature description.
- _future_form_start() _HOOK_GENERATOR_SIGNATURE [source]#
Find future form.
See
_handle_hook()
for signature description.
- _future_form_end() _HOOK_GENERATOR_SIGNATURE [source]#
Find future form.
See
_handle_hook()
for signature description.