3 L] @sTddlZGdddeZGdddeZGdddeZdd Zd d Zd d ZdS)Nc@s&eZdZdZd Zd ddZd d ZdS) Coordz Coordinates of a syntactic element. Consists of: - File name - Line number - (optional) column number, for the Lexer filelinecolumn __weakref__NcCs||_||_||_dS)N)rrr)selfrrrr:/tmp/pip-install-wfra5znf/pycparser/pycparser/plyparser.py__init__szCoord.__init__cCs(d|j|jf}|jr$|d|j7}|S)Nz%s:%sz:%s)rrr)rstrrrr __str__sz Coord.__str__)rrrr)N)__name__ __module__ __qualname____doc__ __slots__r r rrrr r s rc@s eZdZdS) ParseErrorN)r rrrrrr 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)rprrr optrule*sz+PLYParser._create_opt_rule..optrulez%s : empty | %szp_%sN)rr setattr __class__)rZrulenameoptnamerrrr _create_opt_rule#s  zPLYParser._create_opt_ruleNcCst|jj||dS)N)rrr)rZclexfilename)rlinenorrrr _coord1szPLYParser._coordcCsF|jjjjdd|j|}|dkr&d}|j||}|j|j||S)z Returns the coordinates for the YaccProduction objet 'p' indexed with 'token_idx'. The coordinate includes the 'lineno' and 'column'. Both follow the lex semantic, starting from 1.  rr)lexerZlexdatarfindZlexposrr)rrZ token_idxZlast_crrrrr _token_coord7s zPLYParser._token_coordcCstd||fdS)Nz%s: %s)r)rmsgZcoordrrr _parse_errorBszPLYParser._parse_error)N)r rrrrr"r$rrrr 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 |_|S)N)_params)Z rule_func)paramsrr decoratePszparameterized..decorater)r&r'r)r&r parameterizedFs r(cCspd}xft|D]Z}|jdrt||}t|drt|||jdk rPt||q|stjdt ddd}qW|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_namemethodrrr templateVs      r7csZxTjD]J\}}fdd}jjd|jd||_jjd||_t||j|qWdS)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||dS)Nr)rr)funcrr param_rule}sz'_create_param_rules..param_rulexxxyyyN)r%rreplacer r)r4r8r:r;r9r)r8r r0ts  r0) r1objectr Exceptionrrr(r7r0rrrr  s $