U af @sTddlZGdddeZGdddeZGdddeZdd Zd d Zd d ZdS)Nc@s&eZdZdZdZdddZddZdS) Coordz Coordinates of a syntactic element. Consists of: - File name - Line number - (optional) column number, for the Lexer )filelinecolumn __weakref__NcCs||_||_||_dSNrrr)selfrrrr D/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/pycparser/plyparser.py__init__szCoord.__init__cCs(d|j|jf}|jr$|d|j7}|S)Nz%s:%sz:%sr)r strr r r __str__sz Coord.__str__)N)__name__ __module__ __qualname____doc__ __slots__r rr r r r r s rc@s eZdZdS) ParseErrorN)rrrr r r r rsrc@s.eZdZddZd ddZddZdd ZdS) PLYParsercCs<|d}dd}d||f|_d||_t|j|j|dS)z Given a rule name, creates an optional ply.yacc rule for it. The name of the optional rule is _opt Z_optcSs|d|d<dS)Nrr r pr r r optrule*sz+PLYParser._create_opt_rule..optrulez%s : empty | %szp_%sN)rrsetattr __class__)r Zrulenameoptnamerr r r _create_opt_rule#s  zPLYParser._create_opt_ruleNcCst|jj||dS)Nr)rZclexfilename)r linenorr r r _coord1s zPLYParser._coordcCsF|jjjdd||}|dkr&d}|||}||||S)z Returns the coordinates for the YaccProduction object 'p' indexed with 'token_idx'. The coordinate includes the 'lineno' and 'column'. Both follow the lex semantic, starting from 1.  r)lexerZlexdatarfindZlexposr r)r rZ token_idxZlast_crrr r r _token_coord7s zPLYParser._token_coordcCstd||fdS)Nz%s: %s)r)r msgZcoordr r r _parse_errorBszPLYParser._parse_error)N)rrrrr r%r'r r r r r"s  rcsfdd}|S)a Decorator to create parameterized rules. Parameterized rule methods must be named starting with 'p_' and contain 'xxx', and their docstrings may contain 'xxx' and 'yyy'. These will be replaced by the given parameter tuples. For example, ``p_xxx_rule()`` with docstring 'xxx_rule : yyy' when decorated with ``@parameterized(('id', 'ID'))`` produces ``p_id_rule()`` with the docstring 'id_rule : ID'. Using multiple tuples produces multiple rules. cs |_|Sr)_params)Z rule_funcparamsr r decoratePszparameterized..decorater )r*r+r r)r parameterizedFs r,cCsld}t|D]Z}|dr t||}t|dr t|||jdk rNt||q |s tjdt ddd}q |S) z Class decorator to generate rules from parameterized rule templates. See `parameterized` for more information on parameterized rules. FZp_r(Nz@parsing methods must have __doc__ for pycparser to work properly) stacklevelT) dir startswithgetattrhasattrdelattrr_create_param_ruleswarningswarnRuntimeWarning)clsZissued_nodoc_warning attr_namemethodr r r templateVs        r;csVjD]J\}}fdd}jd|d||_jd||_t||j|qdS)a Create ply.yacc rules based on a parameterized rule function Generates new methods (one per each pair of parameters) based on the template rule function `func`, and attaches them to `cls`. The rule function's parameters must be accessible via its `_params` attribute. cs||dSrr rfuncr r param_rule}sz'_create_param_rules..param_rulexxxyyyN)r(rreplacerr)r8r=r?r@r>r r<r r4ts  r4) r5objectr Exceptionrrr,r;r4r r r r  s $