<s> """<STR_LIT>""" <EOL> import param <EOL> from itertools import groupby <EOL> import pyparsing as pp <EOL> from holoviews . core . options import Options <EOL> from . . operation import Compositor <EOL> ascii_uppercase = '<STR_LIT>' <EOL> allowed = '<STR_LIT>' <EOL> class ParserWarning ( param . Parameterized ) : pass <EOL> parsewarning = ParserWarning ( name = '<STR_LIT>' ) <EOL> class Parser ( object ) : <EOL> """<STR_LIT>""" <EOL> namespace = { } <EOL> abort_on_eval_failure = False <EOL> @ classmethod <EOL> def _strip_commas ( cls , kw ) : <EOL> "<STR_LIT>" <EOL> kw = kw [ : - <NUM_LIT:1> ] if kw [ - <NUM_LIT:1> ] == '<STR_LIT:U+002C>' else kw <EOL> return kw [ <NUM_LIT:1> : ] if kw [ <NUM_LIT:0> ] == '<STR_LIT:U+002C>' else kw <EOL> @ classmethod <EOL> def collect_tokens ( cls , parseresult , mode ) : <EOL> """<STR_LIT>""" <EOL> inner = '<STR_LIT>' if mode == '<STR_LIT>' else '<STR_LIT>' <EOL> if parseresult is None : return [ ] <EOL> tokens = [ ] <EOL> for token in parseresult . asList ( ) : <EOL> if isinstance ( token , list ) : <EOL> tokens [ - <NUM_LIT:1> ] = tokens [ - <NUM_LIT:1> ] + ( inner % '<STR_LIT>' . join ( token ) ) <EOL> else : <EOL> if token . strip ( ) == '<STR_LIT:U+002C>' : continue <EOL> tokens . append ( cls . _strip_commas ( token ) ) <EOL> return tokens <EOL> @ classmethod <EOL> def todict ( cls , parseresult , mode = '<STR_LIT>' , ns = { } ) : <EOL> """<STR_LIT>""" <EOL> grouped , kwargs = [ ] , { } <EOL> tokens = cls . collect_tokens ( parseresult , mode ) <EOL> for group in groupby ( tokens , lambda el : '<STR_LIT:=>' in el ) : <EOL> ( val , items ) = group <EOL> if val is True : <EOL> grouped += list ( items ) <EOL> if val is False : <EOL> elements = list ( items ) <EOL> joiner = '<STR_LIT:U+002C>' if any ( ( ( '<STR_LIT:)>' in el ) or ( '<STR_LIT:}>' in el ) ) <EOL> for el in elements ) else '<STR_LIT>' <EOL> grouped [ - <NUM_LIT:1> ] += joiner + joiner . join ( elements ) <EOL> for keyword in grouped : <EOL> for ( fst , snd ) in [ ( '<STR_LIT>' , '<STR_LIT:(>' ) , ( '<STR_LIT>' , '<STR_LIT:{>' ) , ( '<STR_LIT>' , '<STR_LIT:=>' ) , ( '<STR_LIT>' , '<STR_LIT::>' ) ] : <EOL> keyword = keyword . replace ( fst , snd ) <EOL> try : <EOL> kwargs . update ( eval ( '<STR_LIT>' % keyword , <EOL> dict ( cls . namespace , ** ns ) ) ) <EOL> except : <EOL> if cls . abort_on_eval_failure : <EOL> raise SyntaxError ( "<STR_LIT>" <EOL> % keyword ) <EOL> msg = "<STR_LIT>" <EOL> parsewarning . warning ( msg % keyword ) <EOL> return kwargs <EOL> class OptsSpec ( Parser ) : <EOL> """<STR_LIT>""" <EOL> plot_options_short = pp . nestedExpr ( '<STR_LIT:[>' , <EOL> '<STR_LIT:]>' , <EOL> content = pp . OneOrMore ( pp . Word ( allowed ) ^ pp . quotedString ) <EOL> ) . setResultsName ( '<STR_LIT>' ) <EOL> plot_options_long = pp . nestedExpr ( opener = '<STR_LIT>' , <EOL> closer = '<STR_LIT:]>' , <EOL> content = pp . OneOrMore ( pp . Word ( allowed ) ^ pp . quotedString ) <EOL> ) . setResultsName ( '<STR_LIT>' ) <EOL> plot_options = ( plot_options_short | plot_options_long ) <EOL> style_options_short = pp . nestedExpr ( opener = '<STR_LIT:(>' , <EOL> closer = '<STR_LIT:)>' , <EOL> ignoreExpr = None <EOL> ) . setResultsName ( "<STR_LIT>" ) <EOL> style_options_long = pp . nestedExpr ( opener = '<STR_LIT>' , <EOL> closer = '<STR_LIT:)>' , <EOL> ignoreExpr = None <EOL> ) . setResultsName ( "<STR_LIT>" ) <EOL> style_options = ( style_options_short | style_options_long ) <EOL> norm_options_short = pp . nestedExpr ( opener = '<STR_LIT:{>' , <EOL> closer = '<STR_LIT:}>' , <EOL> ignoreExpr = None <EOL> ) . setResultsName ( "<STR_LIT>" ) <EOL> norm_options_long = pp . nestedExpr ( opener = '<STR_LIT>' , <EOL> closer = '<STR_LIT:}>' , <EOL> ignoreExpr = None <EOL> ) . setResultsName ( "<STR_LIT>" ) <EOL> norm_options = ( norm_options_short | norm_options_long ) <EOL> compositor_ops = pp . MatchFirst ( <EOL> [ pp . Literal ( el . group ) for el in Compositor . definitions ] ) <EOL> dotted_path = pp . Combine ( pp . Word ( ascii_uppercase , exact = <NUM_LIT:1> ) <EOL> + pp . Word ( pp . alphanums + '<STR_LIT>' ) ) <EOL> pathspec = ( dotted_path | compositor_ops ) . setResultsName ( "<STR_LIT>" ) <EOL> spec_group = pp . Group ( pathspec + <EOL> ( pp . Optional ( norm_options ) <EOL> & pp . Optional ( plot_options ) <EOL> & pp . Optional ( style_options ) ) ) <EOL> opts_spec = pp . OneOrMore ( spec_group ) <EOL> aliases = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> @ classmethod <EOL> def process_normalization ( cls , parse_group ) : <EOL> """<STR_LIT>""" <EOL> if ( '<STR_LIT>' not in parse_group ) : return None <EOL> opts = parse_group [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . asList ( ) <EOL> if opts == [ ] : return None <EOL> options = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for normopt in options : <EOL> if opts . count ( normopt ) > <NUM_LIT:1> : <EOL> raise SyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % normopt ) <EOL> if not all ( opt in options for opt in opts ) : <EOL> raise SyntaxError ( "<STR_LIT>" <EOL> % "<STR_LIT:U+002CU+0020>" . join ( options ) ) <EOL> excluded = [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> for pair in excluded : <EOL> if all ( exclude in opts for exclude in pair ) : <EOL> raise SyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( pair [ <NUM_LIT:0> ] , pair [ <NUM_LIT:1> ] ) ) <EOL> if len ( opts ) == <NUM_LIT:1> and opts [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' ) : <EOL> axiswise = False <EOL> framewise = True if '<STR_LIT>' in opts else False <EOL> elif len ( opts ) == <NUM_LIT:1> and opts [ <NUM_LIT:0> ] . endswith ( '<STR_LIT>' ) : <EOL> framewise = False <EOL> axiswise = True if '<STR_LIT>' in opts else False <EOL> else : <EOL> axiswise = True if '<STR_LIT>' in opts else False <EOL> framewise = True if '<STR_LIT>' in opts else False <EOL> return dict ( axiswise = axiswise , <EOL> framewise = framewise ) <EOL> @ classmethod <EOL> def parse ( cls , line , ns = { } ) : <EOL> """<STR_LIT>""" <EOL> parses = [ p for p in cls . opts_spec . scanString ( line ) ] <EOL> if len ( parses ) != <NUM_LIT:1> : <EOL> raise SyntaxError ( "<STR_LIT>" ) <EOL> else : <EOL> ( k , s , e ) = parses [ <NUM_LIT:0> ] <EOL> processed = line [ : e ] <EOL> if ( processed . strip ( ) != line . strip ( ) ) : <EOL> raise SyntaxError ( "<STR_LIT>" % line [ e : ] ) <EOL> parse = { } <EOL> for group in cls . opts_spec . parseString ( line ) : <EOL> options = { } <EOL> normalization = cls . process_normalization ( group ) <EOL> if normalization is not None : <EOL> options [ '<STR_LIT>' ] = Options ( ** normalization ) <EOL> if '<STR_LIT>' in group : <EOL> plotopts = group [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> opts = cls . todict ( plotopts , '<STR_LIT>' , ns = ns ) <EOL> options [ '<STR_LIT>' ] = Options ( ** { cls . aliases . get ( k , k ) : v for k , v in opts . items ( ) } ) <EOL> if '<STR_LIT>' in group : <EOL> styleopts = group [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> opts = cls . todict ( styleopts , '<STR_LIT>' , ns = ns ) <EOL> options [ '<STR_LIT>' ] = Options ( ** { cls . aliases . get ( k , k ) : v for k , v in opts . items ( ) } ) <EOL> if group [ '<STR_LIT>' ] in parse : <EOL> parse [ group [ '<STR_LIT>' ] ] . update ( options ) <EOL> else : <EOL> parse [ group [ '<STR_LIT>' ] ] = options <EOL> return parse <EOL> class CompositorSpec ( Parser ) : <EOL> """<STR_LIT>""" <EOL> mode = pp . Word ( pp . alphas + pp . nums + '<STR_LIT:_>' ) . setResultsName ( "<STR_LIT>" ) <EOL> op = pp . Word ( pp . alphas + pp . nums + '<STR_LIT:_>' ) . setResultsName ( "<STR_LIT>" ) <EOL> overlay_spec = pp . nestedExpr ( opener = '<STR_LIT:(>' , <EOL> closer = '<STR_LIT:)>' , <EOL> ignoreExpr = None <EOL> ) . setResultsName ( "<STR_LIT>" ) <EOL> value = pp . Word ( pp . alphas + pp . nums + '<STR_LIT:_>' ) . setResultsName ( "<STR_LIT:value>" ) <EOL> op_settings = pp . nestedExpr ( opener = '<STR_LIT:[>' , <EOL> closer = '<STR_LIT:]>' , <EOL> ignoreExpr = None <EOL> ) . setResultsName ( "<STR_LIT>" ) <EOL> compositor_spec = pp . OneOrMore ( pp . Group ( mode + op + overlay_spec + value <EOL> + pp . Optional ( op_settings ) ) ) <EOL> @ classmethod <EOL> def parse ( cls , line , ns = { } ) : <EOL> """<STR_LIT>""" <EOL> definitions = [ ] <EOL> parses = [ p for p in cls . compositor_spec . scanString ( line ) ] <EOL> if len ( parses ) != <NUM_LIT:1> : <EOL> raise SyntaxError ( "<STR_LIT>" ) <EOL> else : <EOL> ( k , s , e ) = parses [ <NUM_LIT:0> ] <EOL> processed = line [ : e ] <EOL> if ( processed . strip ( ) != line . strip ( ) ) : <EOL> raise SyntaxError ( "<STR_LIT>" % line [ e : ] ) <EOL> opmap = { op . __name__ : op for op in Compositor . operations } <EOL> for group in cls . compositor_spec . parseString ( line ) : <EOL> if ( '<STR_LIT>' not in group ) or group [ '<STR_LIT>' ] not in [ '<STR_LIT:data>' , '<STR_LIT>' ] : <EOL> raise SyntaxError ( "<STR_LIT>" ) <EOL> mode = group [ '<STR_LIT>' ] <EOL> kwargs = { } <EOL> operation = opmap [ group [ '<STR_LIT>' ] ] <EOL> spec = '<STR_LIT:U+0020>' . join ( group [ '<STR_LIT>' ] . asList ( ) [ <NUM_LIT:0> ] ) <EOL> if group [ '<STR_LIT>' ] not in opmap : <EOL> raise SyntaxError ( "<STR_LIT>" <EOL> % group [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in group : <EOL> kwargs = cls . todict ( group [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , '<STR_LIT>' , ns = ns ) <EOL> definition = Compositor ( str ( spec ) , operation , str ( group [ '<STR_LIT:value>' ] ) , mode , ** kwargs ) <EOL> definitions . append ( definition ) <EOL> return definitions </s>
