Token, Lexer and Parser

Token

class stilus.lexer.Token(type, value=None, space=None, lineno=None, column=None)[source]
__eq__(other)[source]

Return self==value.

__hash__()[source]

Return hash(self).

__init__(type, value=None, space=None, lineno=None, column=None)[source]

A token.

__repr__()[source]

Return the value if available, the tokens type otherwise.

__str__()[source]

Return the value if available, the tokens type otherwise.

__weakref__

list of weak references to the object (if defined)

Lexer

class stilus.lexer.Lexer(s: str, options: dict)[source]
__eq__(other)[source]

Return self==value.

__init__(s: str, options: dict)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

anonymous_function()[source]

‘@(‘

atrule()[source]

# ‘@’ (-(w+)-)?[a-zA-Z0-9-_]+

boolean()[source]

true | false

brace()[source]

‘{‘ | ‘}’

comment()[source]

‘//’ *

eol()[source]

eos()[source]

eos | trailing outdents

escaped()[source]

‘’ . ‘ ‘*

function()[source]

-[_a-zA-Z$] [-wd$] ‘(‘

ident()[source]

-[_a-zA-Z$] [-wd$]

important()[source]

‘!important’ ‘ ‘*

keyword()[source]

‘if’ | ‘else’ | ‘unless’ | ‘return’ | ‘for’ | ‘in’

literal()[source]

@css’ ‘ ‘* ‘{‘ .* ‘}’ ‘ ‘*

n()[source]

#n

namedop()[source]

‘not’ | ‘and’ | ‘or’ | ‘is’ | ‘is not’ | ‘isnt’ | ‘is a’ | ‘is defined’

newline()[source]

‘ ‘ ‘+

nn()[source]

#nn

null()[source]
op()[source]

‘,’ | ‘+’ | ‘+=’ | ‘-‘ | ‘-=’ | ‘*’ | ‘=’ | ‘/’ | ‘/=’ | ‘%’ | ‘%=’ | ‘*’ | ‘!’ | ‘&’ | ‘&&’ | ‘||’ | ‘>’ | ‘>=’ | ‘<’ | ‘<=’ | ‘=’ | ‘==’ | ‘!=’ | ‘!’ | ‘~’ | ‘?=’ | ‘:=’ | ‘?’ | ‘:’ | ‘[‘ | ‘]’ | ‘.’ | ‘..’ |’…’

paren()[source]

‘(‘ | ‘)’ ‘ ‘*

rgb()[source]

#rgb

rgba()[source]

#rgba

rrggbb()[source]

#rrggbb

rrggbbaa()[source]

#rrggbbaa

selector()[source]
^|[^

,;]+

sep()[source]

‘;’ [ ]*

space()[source]

‘ ‘+ | ‘ ‘+

string()[source]

‘”’ [^”]+ ‘”’ | “’”” [^’]+ “’”

unicode()[source]

‘U+’ [0-9A-Fa-f?]{1,6}(?:-[0-9A-Fa-f]{1,6})?

unit()[source]

‘-‘? (digit+ | digit* ‘.’ digit+) unit

urlchars()[source]

url char

Parser

class stilus.parser.Parser(s, options: dict)[source]
__init__(s, options: dict)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

expression()[source]

negation+

is_selector_token(n: int) → bool[source]

Check if the token at n is a valid selector token. :param n: :return:

list()[source]

expression (‘,’ expression)*

parse() → stilus.nodes.node.Node[source]

Parse the given source string.

Returns:The root Node.
Return type:Node
selector_parts() → collections.deque[source]

Selector candidates, stitched together to form a selector.

selector_token()[source]

Valid selector tokens.