Repository URL to install this package:
|
Version:
2.18 ▾
|
õ±ÂX¦ ã @ sj Gd d d e Z Gd d d e Z Gd d d e Z d d Z d d Z d
d Z d S)
c @ s7 e Z d Z d Z d Z d d d Z d d
Z d S)ÚCoordz Coordinates of a syntactic element. Consists of:
- File name
- Line number
- (optional) column number, for the Lexer
ÚfileÚlineÚcolumnÚ__weakref__Nc C s | | _ | | _ | | _ d S)N)r r r )Úselfr r r © r ú../pycparser/plyparser.pyÚ__init__ s zCoord.__init__c C s4 d | j | j f } | j r0 | d | j 7} | S)Nz%s:%sz:%s)r r r )r Ústrr r r Ú__str__ s z
Coord.__str__)zfilezlinezcolumnz__weakref__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú __slots__r r r r r r r s r c @ s e Z d Z d S)Ú
ParseErrorN)r r
r r r r r r s r c @ sC e Z d Z d d Z d d d Z d d Z d d Z d S)
Ú PLYParserc C sP | d } d d } d | | f | _ d | | _ t | j | j | d S)z Given a rule name, creates an optional ply.yacc rule
for it. The name of the optional rule is
<rulename>_opt
Z_optc S s | d | d <d S)Né é r )r Úpr r r Úoptrule) s z+PLYParser._create_opt_rule.<locals>.optrulez%s : empty
| %szp_%sN)r r ÚsetattrÚ __class__)r ZrulenameZoptnamer r r r Ú_create_opt_rule" s
zPLYParser._create_opt_ruleNc C s t d | j j d | d | S)Nr r r )r ÚclexÚfilename)r Úlinenor r r r Ú_coord0 s zPLYParser._coordc C se | j j j j d d | j | } | d k r9 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.
Ú
r r éÿÿÿÿ)ÚlexerÚlexdataÚrfindÚlexposr r )r r Z token_idxÚlast_crr r r r Ú_token_coord6 s
'zPLYParser._token_coordc C s t d | | f d S)Nz%s: %s)r )r ÚmsgÚcoordr r r Ú_parse_errorA s zPLYParser._parse_error)r r
r r r r% r( r r r r r ! s r c s f d d } | 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.
c s
| _ | S)N)Ú_params)Z rule_func)Úparamsr r ÚdecorateO s zparameterized.<locals>.decorater )r* r+ r )r* r Ú
parameterizedE s
r, c C sb x[ t | D]M } | j d r
t | | } t | d r
t | | t | | q
W| S)z Class decorator to generate rules from parameterized rule templates.
See `parameterized` for more information on parameterized rules.
Úp_r) )ÚdirÚ
startswithÚgetattrÚhasattrÚdelattrÚ_create_param_rules)ÚclsZ attr_nameÚmethodr r r ÚtemplateU s
r6 c s xx j D]m \ } } f d d } j j d | j d | | _ j j d | | _ t | | j | q
Wd S)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.
c s | | d S)Nr )r r )Úfuncr r Ú
param_rulel s z'_create_param_rules.<locals>.param_ruleÚxxxÚyyyN)r) r Úreplacer r )r4 r7 r9 r: r8 r )r7 r r3 c s
$r3 N)Úobjectr Ú Exceptionr r r, r6 r3 r r r r Ú<module> s
$