src.fairreckitlib.core.parsing.parse_event
This module contains an event id, event args and print function for a parsing event.
Constants:
ON_PARSE: id of the event that is used when parsing fails.
Classes:
ParseEventArgs: event args related to parsing.
Functions:
print_parse_event: print parse event arguments.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)
1"""This module contains an event id, event args and print function for a parsing event. 2 3Constants: 4 5 ON_PARSE: id of the event that is used when parsing fails. 6 7Classes: 8 9 ParseEventArgs: event args related to parsing. 10 11Functions: 12 13 print_parse_event: print parse event arguments. 14 15This program has been developed by students from the bachelor Computer Science at 16Utrecht University within the Software Project course. 17© Copyright Utrecht University (Department of Information and Computing Sciences) 18""" 19 20from dataclasses import dataclass 21from typing import Any, List, Type 22 23from ..events.event_args import MessageEventArgs 24 25ON_PARSE = 'Config.on_parse' 26 27 28@dataclass 29class ParseEventArgs(MessageEventArgs): 30 """Parse Event Arguments. 31 32 Only the message is required, other variables are optional. 33 34 message: the message describing the parsing failure. 35 one_of_list: a list of values that contains the expected value. 36 expected_type: the type that is expected to be parsed. 37 actual_type: the type that is attempted to be parsed. 38 default_value: the default value that is returned after parsing. 39 """ 40 41 one_of_list: List[Any] = None 42 expected_type: Type = None 43 actual_type: Type = None 44 default_value: Any = None 45 46 47def print_parse_event(event_args: ParseEventArgs) -> None: 48 """Print parse event arguments. 49 50 Args: 51 event_args: the arguments to print. 52 """ 53 if len(event_args.message) > 0: 54 print(event_args.message) 55 if event_args.one_of_list is not None: 56 print('\texpected one of: ' + str(event_args.one_of_list)) 57 if event_args.expected_type is not None: 58 print('\texpect:', event_args.expected_type) 59 if event_args.actual_type is not None: 60 print('\tactual:', event_args.actual_type) 61 if event_args.default_value is not None: 62 print('\tdefault to:', event_args.default_value)
29@dataclass 30class ParseEventArgs(MessageEventArgs): 31 """Parse Event Arguments. 32 33 Only the message is required, other variables are optional. 34 35 message: the message describing the parsing failure. 36 one_of_list: a list of values that contains the expected value. 37 expected_type: the type that is expected to be parsed. 38 actual_type: the type that is attempted to be parsed. 39 default_value: the default value that is returned after parsing. 40 """ 41 42 one_of_list: List[Any] = None 43 expected_type: Type = None 44 actual_type: Type = None 45 default_value: Any = None
Parse Event Arguments.
Only the message is required, other variables are optional.
message: the message describing the parsing failure. one_of_list: a list of values that contains the expected value. expected_type: the type that is expected to be parsed. actual_type: the type that is attempted to be parsed. default_value: the default value that is returned after parsing.
48def print_parse_event(event_args: ParseEventArgs) -> None: 49 """Print parse event arguments. 50 51 Args: 52 event_args: the arguments to print. 53 """ 54 if len(event_args.message) > 0: 55 print(event_args.message) 56 if event_args.one_of_list is not None: 57 print('\texpected one of: ' + str(event_args.one_of_list)) 58 if event_args.expected_type is not None: 59 print('\texpect:', event_args.expected_type) 60 if event_args.actual_type is not None: 61 print('\tactual:', event_args.actual_type) 62 if event_args.default_value is not None: 63 print('\tdefault to:', event_args.default_value)
Print parse event arguments.
Args: event_args: the arguments to print.