kojismokydingo.sift.parse

Koji Smoky Dingo - Sifty Dingo Parser

This is the parser for the Sift Dingo filtering language.

author:

Christopher O'Brien <obriencj@gmail.com>

license:

GPL v3

class AllItems[source]

Bases: Item

Seeks all path members

get(d)[source]
Parameters:

d (dict)

Return type:

Iterator

class Glob(src, ignorecase=False)[source]

Bases: Matcher

A glob is a quoted literal using pipes as quotes

Examples:

  • |*foo| is a case-sensitive match for text ending in foo

  • |*foo|i is a case-insensitive match for text ending in foo

class Item(key)[source]

Bases: object

Seeks path members by an int or str key.

Parameters:

key (int | str | slice | Matcher)

get(d)[source]
Parameters:

d (dict)

Return type:

Iterator

class ItemMatch(key)[source]

Bases: Item

Seeks path members by comparison of keys to a matcher (eg. a Glob or Regex)

Parameters:

key (int | str | slice | Matcher)

get(d)[source]
Parameters:

d (dict)

Return type:

Iterator

class ItemPath(*paths)[source]

Bases: object

Represents a collection of elements inside a nested tree of lists and dicts

Parameters:

paths (Item | Matcher | str | int | slice)

get(data)[source]
Parameters:

data (dict)

Return type:

Iterator

class Matcher[source]

Bases: object

Base class for special comparison types

class Null[source]

Bases: Matcher

An empty literal, represented by the symbols null or None. Matches only with the python None value.

class Number[source]

Bases: int, Matcher

A number is a literal made entirely of digits. It can compare with both the python int and str types.

class Reader(source)[source]

Bases: StringIO

Parameters:

source (str)

peek(count=1)[source]
Parameters:

count (int)

Return type:

str

class Regex(src, flags=None)[source]

Bases: Matcher

A regex is a quoted literal using forward-slashes as quotes

Examples:

  • /.*foo$/ is a case-sensitive match for text ending in foo

  • /.*foo$/i is a case-insensitive match for text ending in foo

exception RegexError[source]

Bases: ParserError

complaint: str = 'Error compiling Regex'
class Symbol[source]

Bases: str, Matcher

An unquoted literal series of characters. A symbol can compare with python str instances.

class SymbolGroup(src, groups)[source]

Bases: Matcher

A symbol group is a literal symbol with multiple permutations. It is represented as a symbol containing groups within curly-braces

Examples:

  • {foo,bar}-candidate is equal to foo-candidate and bar-candidate

  • foo-{1..3} is equal to any of foo-1, foo-2, foo-3

convert_escapes(val)[source]

Decodes common escape sequences embedded in a str

Parameters:

val (str) -- source str to decode

Return type:

str

convert_token(val)[source]

Converts unquoted values to a Matcher instance.

Parameters:

val (str) -- token value to be converted

Return type:

Matcher | str | bool

parse_exprs(reader, start=None, stop=None)[source]

Simple s-expr parser. Reads from a string or character iterator, emits expressions as nested lists.

Parameters:
Return type:

Iterator