regparser.grammar package¶
Submodules¶
regparser.grammar.amdpar module¶
-
regparser.grammar.amdpar.
generate_verb
(word_list, verb, active)[source]¶ Short hand for making tokens.Verb from a list of trigger words
-
regparser.grammar.amdpar.
make_multiple
(to_repeat)[source]¶ Shorthand for handling repeated tokens (‘and’, ‘,’, ‘through’)
regparser.grammar.appendix module¶
regparser.grammar.atomic module¶
Atomic components; probably shouldn’t use these directly
regparser.grammar.delays module¶
regparser.grammar.interpretation_headers module¶
regparser.grammar.terms module¶
regparser.grammar.tokens module¶
Set of Tokens to be used when parsing. @label is a list describing the depth of a paragraph/context. It follows: [ Part, Subpart/Appendix/Interpretations, Section, p-level-1, p-level-2, p-level-3, p-level4, p-level5 ]
-
class
regparser.grammar.tokens.
AndToken
[source]¶ Bases:
regparser.grammar.tokens.Token
The word ‘and’ can help us determine if a Context token should be a Paragraph token. Note that ‘and’ might also trigger the creation of a TokenList, which takes precedent
-
class
regparser.grammar.tokens.
Context
(label, certain=False)[source]¶ Bases:
regparser.grammar.tokens.Token
Represents a bit of context for the paragraphs. This gets compressed with the paragraph tokens to define the full scope of a paragraph. To complicate matters, sometimes what looks like a Context is actually the entity which is being modified (i.e. a paragraph). If we are certain that this is only context, (e.g. “In Subpart A”), use ‘certain’
-
certain
¶
-
label
¶
-
-
class
regparser.grammar.tokens.
Paragraph
(label=NOTHING, field=None)[source]¶ Bases:
regparser.grammar.tokens.Token
Represents an entity which is being modified by the amendment. Label is a way to locate this paragraph (though see the above note). We might be modifying a field of a paragraph (e.g. intro text only, or title only;) if so, set the field parameter.
-
HEADING_FIELD
= 'title'¶
-
KEYTERM_FIELD
= 'heading'¶
-
TEXT_FIELD
= 'text'¶
-
field
¶
-
label
¶
-
classmethod
make
(label=None, field=None, part=None, sub=None, section=None, paragraphs=None, paragraph=None, subpart=None, is_interp=None, appendix=None)[source]¶ label and field are the only “materialized” fields. Everything other field becomes part of the label, offering a more legible API. Particularly useful for writing tests
-
-
class
regparser.grammar.tokens.
Token
[source]¶ Bases:
object
Base class for all tokens. Provides methods for pattern matching and copying this token
-
class
regparser.grammar.tokens.
TokenList
(tokens)[source]¶ Bases:
regparser.grammar.tokens.Token
Represents a sequence of other tokens, e.g. comma separated of created via “through”
-
tokens
¶
-
-
class
regparser.grammar.tokens.
Verb
(verb, active, and_prefix=False)[source]¶ Bases:
regparser.grammar.tokens.Token
Represents what action is taking place to the paragraphs
-
DELETE
= 'DELETE'¶
-
DESIGNATE
= 'DESIGNATE'¶
-
INSERT
= 'INSERT'¶
-
KEEP
= 'KEEP'¶
-
MOVE
= 'MOVE'¶
-
POST
= 'POST'¶
-
PUT
= 'PUT'¶
-
RESERVE
= 'RESERVE'¶
-
active
¶
-
and_prefix
¶
-
verb
¶
-
regparser.grammar.unified module¶
Some common combinations
regparser.grammar.utils module¶
-
class
regparser.grammar.utils.
DocLiteral
(literal, ascii_text)[source]¶ Bases:
pyparsing.Literal
Setting an objects name to a unicode string causes Sphinx to freak out. Instead, we’ll replace with the provided (ascii) text.
-
class
regparser.grammar.utils.
Position
(start, end)¶ Bases:
tuple
-
end
¶ Alias for field number 1
-
start
¶ Alias for field number 0
-
-
class
regparser.grammar.utils.
QuickSearchable
(expr, force_regex_str=None)[source]¶ Bases:
pyparsing.ParseElementEnhance
Pyparsing’s scanString (i.e. searching for a grammar over a string) tests each index within its search string. While that offers maximum flexibility, it is rather slow for our needs. This enhanced grammar type wraps other grammars, deriving from them a first regular expression to use when `scanString`ing. This cuts search time considerably.
-
classmethod
and_case
(*first_classes)[source]¶ “And” grammars are relatively common; while we generally just want to look at their first terms, this decorator lets us describe special cases based on the class type of the first component of the clause
-
classmethod
case
(*match_classes)[source]¶ Add a “case” which will match grammars based on the provided class types. If there’s a match, we’ll execute the function
-
cases
= [<function wordstart>, <function optional>, <function empty>, <function match_and>, <function match_or>, <function suppress>, <function has_re_string>, <function line_start>, <function literal>]¶
-
classmethod
initial_regex
(grammar)[source]¶ Given a Pyparsing grammar, derive a set of suitable initial regular expressions to aid our search. As grammars may Or together multiple sub-expressions, this always returns a set of possible regular expression strings. This is _not_ a complete conversion to regexes nor does it account for every Pyparsing element; add as needed
-
classmethod
-
regparser.grammar.utils.
keep_pos
(expr)[source]¶ Transform a pyparsing grammar by inserting an attribute, “pos”, on the match which describes position information