
    6hx<                    ~    S SK Jr  S SKrS SKrSSKJr  SSKJrJr  SSK	J
r
  S r       S
S jr       S
S	 jrg)    )annotationsN   )_)errorpycompat)
stringutilc              #  V  ^^^^^^^^#    U (       d  g[         R                  " [        R                  [        R                  -   5      m0 mSmSmUUU4S jn[         R
                  " U 5      mU4S jmU4S jmU4S jmUUUU4S jnT" 5       nUS	:w  Ga  U[         R                  " [        R                  5      ;   a1  T" 5       nU[         R                  " [        R                  5      ;   a  M1  US
:X  a  STT/44v   TmTS-  mT" 5       nGOUS:X  ab  T" T" 5       [         R                  " [        R                  5      5      u  p4[        U5      n[        SU5       H  nSTT/44v   TmTS-  mM     GOUS;   ap  US:X  a  T" 5       nU" U5      u  p7U/nUS:X  a(  U" T" 5       5      u  p7UR                  U5        US:X  a  M(  U V	s/ s H
  o" U	5      PM     n
n	STU
44v   TmTS-  mGO.US:X  a  U" T" 5       5      u  p9U" U	5      mGOUS:X  a  U" T" 5       5      u  p;TTU'   STU44v   OUS:X  a  U" T" 5       5      u  p<SU4v   OUS:X  aG  T" 5       nUS:X  a)  SnT" 5       nUS;  a  X-  nT" 5       nUS;  a  M  SU4v   OU" U5      u  p=SU4v   OUS:X  a  US;  a  T" 5       nUS;  a  M  OgUS:X  a
  SmT" 5       nOWUS	:X  a  gSnSnUS	:w  a$  US:  a  X-  nUS-  nT" 5       nUS	:w  a  US:  a  M  [        R                  " [        S5      U-  5      eUS	:w  a  GM  ggs  sn	f 7f)a#  parses a DAG from a concise textual description; generates events

    "+n" is a linear run of n nodes based on the current default parent
    "." is a single node based on the current default parent
    "$" resets the default parent to -1 (implied at the start);
        otherwise the default parent is always the last node created
    "<p" sets the default parent to the backref p
    "*p" is a fork at parent p, where p is a backref
    "*p1/p2/.../pn" is a merge of parents p1..pn, where the pi are backrefs
    "/p2/.../pn" is a merge of the preceding node and p2..pn
    ":name" defines a label for the preceding node; labels can be redefined
    "@text" emits an annotation event for text
    "!command" emits an action event for the current node
    "!!my command
" is like "!", but to the end of the line
    "#...
" is a comment up to the end of the line

    Whitespace between the above elements is ignored.

    A backref is either
     * a number n, which references the node curr-n, where curr is the current
       node, or
     * the name of a label you placed earlier using ":name", or
     * empty to denote the default parent.

    All string valued-elements are either strictly alphanumeric, or must
    be enclosed in double quotes ("..."), with "" as escape character.

    Generates sequence of

      ('n', (id, [parentids])) for node creation
      ('l', (id, labelname)) for labels on nodes
      ('a', text) for annotations
      ('c', command) for actions (!)
      ('C', command) for line actions (!!)

    Examples
    --------

    Example of a complex graph (output not shown for brevity):

        >>> len(list(parsedag(b"""
        ...
        ... +3         # 3 nodes in linear run
        ... :forkhere  # a label for the last of the 3 nodes from above
        ... +5         # 5 more nodes on one branch
        ... :mergethis # label again
        ... <forkhere  # set default parent to labeled fork node
        ... +10        # 10 more nodes on a parallel branch
        ... @stable    # following nodes will be annotated as "stable"
        ... +5         # 5 nodes in stable
        ... !addfile   # custom command; could trigger new file in next node
        ... +2         # two more nodes
        ... /mergethis # merge last node with labeled node
        ... +4         # 4 more nodes descending from merge node
        ...
        ... """)))
        34

    Empty list:

        >>> list(parsedag(b""))
        []

    A simple linear run:

        >>> list(parsedag(b"+3"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

    Some non-standard ways to define such runs:

        >>> list(parsedag(b"+1+2"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

        >>> list(parsedag(b"+1*1*"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

        >>> list(parsedag(b"*"))
        [('n', (0, [-1]))]

        >>> list(parsedag(b"..."))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [1]))]

    A fork and a join, using numeric back references:

        >>> list(parsedag(b"+2*2*/2"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [0])), ('n', (3, [2, 1]))]

        >>> list(parsedag(b"+2<2+1/2"))
        [('n', (0, [-1])), ('n', (1, [0])), ('n', (2, [0])), ('n', (3, [2, 1]))]

    Placing a label:

        >>> list(parsedag(b"+1 :mylabel +1"))
        [('n', (0, [-1])), ('l', (0, 'mylabel')), ('n', (1, [0]))]

    An empty label (silly, really):

        >>> list(parsedag(b"+1:+1"))
        [('n', (0, [-1])), ('l', (0, '')), ('n', (1, [0]))]

    Fork and join, but with labels instead of numeric back references:

        >>> list(parsedag(b"+1:f +1:p2 *f */p2"))
        [('n', (0, [-1])), ('l', (0, 'f')), ('n', (1, [0])), ('l', (1, 'p2')),
         ('n', (2, [0])), ('n', (3, [2, 1]))]

        >>> list(parsedag(b"+1:f +1:p2 <f +1 /p2"))
        [('n', (0, [-1])), ('l', (0, 'f')), ('n', (1, [0])), ('l', (1, 'p2')),
         ('n', (2, [0])), ('n', (3, [2, 1]))]

    Restarting from the root:

        >>> list(parsedag(b"+1 $ +1"))
        [('n', (0, [-1])), ('n', (1, [-1]))]

    Annotations, which are meant to introduce sticky state for subsequent nodes:

        >>> list(parsedag(b"+1 @ann +1"))
        [('n', (0, [-1])), ('a', 'ann'), ('n', (1, [0]))]

        >>> list(parsedag(b'+1 @"my annotation" +1'))
        [('n', (0, [-1])), ('a', 'my annotation'), ('n', (1, [0]))]

    Commands, which are meant to operate on the most recently created node:

        >>> list(parsedag(b"+1 !cmd +1"))
        [('n', (0, [-1])), ('c', 'cmd'), ('n', (1, [0]))]

        >>> list(parsedag(b'+1 !"my command" +1'))
        [('n', (0, [-1])), ('c', 'my command'), ('n', (1, [0]))]

        >>> list(parsedag(b'+1 !!my command line\n +1'))
        [('n', (0, [-1])), ('C', 'my command line'), ('n', (1, [0]))]

    Comments, which extend to the end of the line:

        >>> list(parsedag(b'+1 # comment\n+1'))
        [('n', (0, [-1])), ('n', (1, [0]))]

    Error:

        >>> try: list(parsedag(b'+1 bad'))
        ... except Exception as e: print(pycompat.sysstr(bytes(e)))
        invalid character in dag description: bad...

    Nr   c                   > U (       d  T$ U S   [         R                  " [        R                  5      ;   a  T[	        U 5      -
  $ TU    $ )Nr   )r   bytestrstringdigitsint)reflabelsp1rs    5/usr/lib/python3/dist-packages/mercurial/dagparser.pyresolveparsedag.<locals>.resolve   s>    IVx''66s3x<#;    c                    > [        T S5      $ )N    )next)chiters   r   nextchparsedag.<locals>.nextch   s    FE""r   c                <   > SnX;   a  X -  nT" 5       n X;   a  M  X4$ Nr    )callowsr   s      r   nextrunparsedag.<locals>.nextrun   s+    jFAA j tr   c                `   > SnX:w  a  X:X  a  T" 5       n X0-  nT" 5       n X:w  a  M  T" 5       U4$ r   r    )r!   limitescaper#   r   s       r   nextdelimitedparsedag.<locals>.nextdelimited   s<    j{HFAA	 j
 x{r   c                @   > U S:X  a  T" T" 5       SS5      $ T" U T5      $ )N   "   \r    )r!   r   r)   r$   	wordcharss    r   
nextstringparsedag.<locals>.nextstring   s(    9 4771i((r   r      .   nr      +s   */   *   /   <   :   l   @   a   !r   s   
    C   c   #   $
   s+   invalid character in dag description: %s...)r   r   r   ascii_lettersr   iterbytestr
whitespacer   rangeappendr   Abortr   )descr   r/   r!   digsniprefprefsr   psnametextcmdr#   r   r   r   r)   r$   r   r   r.   s                  @@@@@@@@r   parsedagrQ      sG    f    !5!5!EFI F	B	A !!$'F#) ) 	A
u*8##F$5$566A 8##F$5$566 9RD	/!BFAA$Yfh(8(8(GHGAD	A1a[QIo%Q ! %ZDyH mGAFEt)$VX.T" t) +00%3'#,%B0B-BFA$Y)FAB$Y *GAF4LT
""$Y *GA*$YADyHy(HCA y( Ci#ACi$Y9$H 9$$YBA%ZAAu*RQH u*R ++@AAE I u**6 1s9   C"L).CL)L)L$B$L)>1L)1AL)7(L)"L)c              #    ^ ^^^^^^#    S mU UUUUUU4S jnSn	U" 5        HY  n
U
S:X  a  U	(       a  U	v   Sn	M  M  [        U	5      [        U
5      -   U:  a  U	v   Sn	OU(       a  U	(       a  U
S:w  a  U	S-  n	X-  n	M[     U	(       a  U	v   gg7f)z$generates single lines for dagtext()c                    [         R                  " SU 5      (       a  U $ SU R                  SS5      R                  SS5      -   S-   $ )Ns   ^[0-9a-z]*$r,   r-   s   \\)rematchreplace)rO   s    r   
wrapstring dagtextlines.<locals>.wrapstring.  s@    88ND))Kdll5'2::4GG$NNr   c               3    >#    0 n SnSnSnT GHa  u  pEUS:X  Gah  Uu  pgXb:w  a#  [         R                  " [        S5      X&4-  5      eU(       d  S/nO1U H+  nX:  d  M
  [         R                  " [        S5      X4-  5      e   US-  nUS-
  n	[        U5      S:X  a4  US   S:X  a+  U(       a"  U(       a	  SU-  v   SnT(       a  S	v   S
v   Sn	OSn[        U5      S:X  a  US   U	:X  a  T(       a  Sv   M  US-  nM  U(       a	  SU-  v   SnT(       a  S	v   / n
U HK  nX:X  a  U
R	                  S5        M  X;   a  U
R	                  X   5        M5  U
R	                  SXh-
  -  5        MM     SSR                  U
5      -   v   GMu  U(       a	  SU-  v   SnUS:X  a   Uu  pXU'   SU-   v   T(       a  S	v   GM  GM  US:X  a  ST" U5      -   v   T(       a  S	v   GM  GM  US:X  a  SU-   v   S	v   GM  US:X  a  T(       a  S	v   ST" U5      -   v   GM  US:X  a  SU-   v   S	v   GM  [         R                  " [        S5      [        R                  " U5      [        R                  " U5      4-  5      e   U(       a  SU-  v   g g 7f)Nr   Fr2   s   expected id %i, got %ir
   s)   parent id %i is larger than current id %ir   s   +%d   
r?   Tr1   r   s   %dr4   r5   r8   r7   r=   r;   r<   s   !!r:   r9   r>   s'   invalid event type in dag: ('%s', '%s'))r   rF   r   lenrE   joinr   	escapestr)r   runwantrneedrootkinddatar   rM   pr   rL   ridrN   eventsusedotswrapannotationswrapcommands
wraplabelswrapnonlinearrW   s                r   gendagtextlines.<locals>.gen3  s     JDt| :++a(A&BeZ&OPPB6"'++ !%5!" $%&	!)#    
 Ur7a<BqERK"(3,."#C("'K"
#'r7a<BqERK"
q$sl*$#E7!LL-[!LL3!LL!%9   5!111 3,&C4< $IC"&3K+%!# "T\D!111## $T\$,&KT\&#D!111T\+%K++DE&006&006 _ !l 3, s   AJH&Jr   rZ   r1       N)r[   )re   	addspacesri   rg   rh   rj   rf   maxlinewidthrk   linepartrW   s   ` `````    @r   dagtextlinesrr   "  s     O
\ \| D5=
  4y3t9$4
tLD  
 s   BBc                D    SR                  [        U UUUUUUU5      5      $ )a  generates lines of a textual representation for a dag event stream

events should generate what parsedag() does, so:

  ('n', (id, [parentids])) for node creation
  ('l', (id, labelname)) for labels on nodes
  ('a', text) for annotations
  ('c', text) for commands
  ('C', text) for line commands ('!!')
  ('#', text) for comment lines

Parent nodes must come before child nodes.

Examples
--------

Linear run:

    >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [0]))])
    '+2'

Two roots:

    >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [-1]))])
    '+1 $ +1'

Fork and join:

    >>> dagtext([(b'n', (0, [-1])), (b'n', (1, [0])), (b'n', (2, [0])),
    ...          (b'n', (3, [2, 1]))])
    '+2 *2 */2'

Fork and join with labels:

    >>> dagtext([(b'n', (0, [-1])), (b'l', (0, b'f')), (b'n', (1, [0])),
    ...          (b'l', (1, b'p2')), (b'n', (2, [0])), (b'n', (3, [2, 1]))])
    '+1 :f +1 :p2 *f */p2'

Annotations:

    >>> dagtext([(b'n', (0, [-1])), (b'a', b'ann'), (b'n', (1, [0]))])
    '+1 @ann +1'

    >>> dagtext([(b'n', (0, [-1])),
    ...          (b'a', b'my annotation'),
    ...          (b'n', (1, [0]))])
    '+1 @"my annotation" +1'

Commands:

    >>> dagtext([(b'n', (0, [-1])), (b'c', b'cmd'), (b'n', (1, [0]))])
    '+1 !cmd +1'

    >>> dagtext([(b'n', (0, [-1])),
    ...          (b'c', b'my command'),
    ...          (b'n', (1, [0]))])
    '+1 !"my command" +1'

    >>> dagtext([(b'n', (0, [-1])),
    ...          (b'C', b'my command line'),
    ...          (b'n', (1, [0]))])
    '+1 !!my command line\n+1'

Comments:

    >>> dagtext([(b'n', (0, [-1])), (b'#', b' comment'), (b'n', (1, [0]))])
    '+1 # comment\n+1'

    >>> dagtext([])
    ''

Combining parsedag and dagtext:

    >>> dagtext(parsedag(b'+1 :f +1 :p2 *f */p2'))
    '+1 :f +1 :p2 *f */p2'

rZ   )r\   rr   )dagrn   ri   rg   rh   rj   rf   ro   s           r   dagtextru     s6    n ::		
 r   )TFFFFFF   )
__future__r   rT   r   i18nr    r   r   utilsr   rQ   rr   ru   r    r   r   <module>r{      s_    # 	   J^ }D br   