Parsers
ValidationMessage
dataclass
A message from a parser that indicates the result of a validation.
Source code in src/typedlogic/parser.py
10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Parser
dataclass
Bases: ABC
A parser is a class that can parse a source and return a Theory object.
You can use the registry get_parser
method to get a parser for a particular syntax:
>>> from typedlogic.registry import get_parser
>>> parser = get_parser("yaml")
Source code in src/typedlogic/parser.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
parse(source, **kwargs)
abstractmethod
Parse a source and return a Theory object.
TODO: in future, if the source is a text representation, use parse_text() instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Union[Path, str, TextIO]
|
A path to a file, a string representation of the source, or a file-like object. |
required |
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
Theory
|
|
Source code in src/typedlogic/parser.py
46 47 48 49 50 51 52 53 54 55 56 57 |
|
parse_text(source, **kwargs)
Parse a text string and return a Theory object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
|
required |
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
Theory
|
|
Source code in src/typedlogic/parser.py
59 60 61 62 63 64 65 66 67 |
|
parse_to_sentences(source, **kwargs)
Parse a source and return a list of sentences.
.. note::
This method is a convenience method that calls `parse` and returns the sentences from the resulting Theory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Union[Path, str, TextIO]
|
|
required |
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
List[Sentence]
|
|
Source code in src/typedlogic/parser.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
parse_ground_terms(source, **kwargs)
Parse a source and return a list of ground terms (facts).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Union[Path, str, TextIO]
|
|
required |
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
List[Term]
|
|
Source code in src/typedlogic/parser.py
84 85 86 87 88 89 90 91 92 93 |
|
translate(source, **kwargs)
Translate a source object into a Theory object.
The type of the source object may be constrained by individual subclasses
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Any
|
|
required |
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
Theory
|
|
Source code in src/typedlogic/parser.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
validate_iter(source, **kwargs)
Validate a source and return an iterator of validation messages.
Validation might include type checking (for python source), syntax checking (for text source), linting, etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Union[Path, str, TextIO]
|
|
required |
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
Iterator[ValidationMessage]
|
|
Source code in src/typedlogic/parser.py
111 112 113 114 115 116 117 118 119 120 121 122 |
|
validate(source, **kwargs)
Validate a source and return a list of validation messages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
Union[Path, str, TextIO]
|
|
required |
kwargs
|
|
{}
|
Returns:
Type | Description |
---|---|
List[ValidationMessage]
|
|
Source code in src/typedlogic/parser.py
124 125 126 127 128 129 130 131 132 |
|