[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: lpeg.U ?
From: Albert Dinero <albertmcchan () yahoo ! com>
Date: 2018-01-27 2:25:07
Message-ID: 54919189.68794.1517019907475 () mail ! yahoo ! com
[Download RAW message or body]
Does lpeg.B(-n) has any real meaning ?I did a patch that use B(-n) for the behind n \
instructionNOTE: %b == lpge.B(-1) == behind 1
Example: lua patten "(.*)and(.*)"
pat = re.compile "{(g <- 'and' / . [^a]* g)+ %b%b%b} ... {.*}"
= pat:match 'this and that and whatever'
this and that
whatever
Example: capture chars in groups of 3's
pat = re.compile "({...} %b%b)+"
= pat:match "123456789"
123 234 345 456 567 678 789
----
Follwing is the patches if anyone interested (ONLY 4 lines !)
> diff lpeg\lptree.c lpeg-1.0.1\lptree.c
430d429
< tree->u.n = n; // TNot, \
possibly UNDO 689d687
< if (sib1(tree)->tag == TNot) n = sib1(tree)->u.n;
> diff lpeg\lpcode.c lpeg-1.0.1\lpcode.c
661d661
< if (sib1(tree)->tag != TNot) // TNot == UNDO
> diff lpeg\re.lua lpeg-1.0.1\re.lua
23c27,28
< local Predef = { nl = m.P"\n", b = m.B(-1) }
---
> local Predef = { nl = m.P"\n" }
[Attachment #3 (text/html)]
<html><head></head><body><div style="color:#000; background-color:#fff; \
font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, \
sans-serif;font-size:13px"><div id="yui_3_16_0_ym19_1_1517019474308_3075" \
dir="ltr">Does lpeg.B(-n) has any real meaning ?</div><div \
id="yui_3_16_0_ym19_1_1517019474308_3314" dir="ltr">I did a patch that use B(-n) for \
the behind n instruction</div><div id="yui_3_16_0_ym19_1_1517019474308_3254" \
dir="ltr">NOTE: %b == lpge.B(-1) == behind 1</div><div \
id="yui_3_16_0_ym19_1_1517019474308_3294" dir="ltr"><br></div><div \
id="yui_3_16_0_ym19_1_1517019474308_3078" dir="ltr">Example: lua patten \
"(.*)and(.*)"</div><div id="yui_3_16_0_ym19_1_1517019474308_3253" \
dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1517019474308_3079" dir="ltr">pat = \
re.compile "{(g <- 'and' / . [^a]* g)+ %b%b%b} ... {.*}"<br \
id="yui_3_16_0_ym19_1_1517019474308_3080">= pat:match 'this and that and whatever'<br \
id="yui_3_16_0_ym19_1_1517019474308_3081">this and that<br \
id="yui_3_16_0_ym19_1_1517019474308_3082">whatever</div><div \
id="yui_3_16_0_ym19_1_1517019474308_3351" dir="ltr"><br></div><div \
id="yui_3_16_0_ym19_1_1517019474308_3083" dir="ltr">Example: capture chars in groups \
of 3's</div><div id="yui_3_16_0_ym19_1_1517019474308_3202" dir="ltr"><br></div><div \
id="yui_3_16_0_ym19_1_1517019474308_3084" dir="ltr">pat = re.compile "({...} \
%b%b)+"<br id="yui_3_16_0_ym19_1_1517019474308_3085">= pat:match "123456789"<br \
id="yui_3_16_0_ym19_1_1517019474308_3086">123 \
234 345 456 \
567 678 789</div><div \
dir="ltr"><br></div><div dir="ltr">----<br \
id="yui_3_16_0_ym19_1_1517019474308_3088">Follwing is the patches if anyone \
interested (ONLY 4 lines !)</div><div dir="ltr"><br></div><div \
id="yui_3_16_0_ym19_1_1517019474308_3089" dir="ltr">>diff lpeg\lptree.c \
lpeg-1.0.1\lptree.c<br id="yui_3_16_0_ym19_1_1517019474308_3090">430d429<br \
id="yui_3_16_0_ym19_1_1517019474308_3091">< \
tree->u.n = n; \
// TNot, possibly UNDO<br \
id="yui_3_16_0_ym19_1_1517019474308_3092">689d687<br \
id="yui_3_16_0_ym19_1_1517019474308_3093">< if (sib1(tree)->tag == \
TNot) n = sib1(tree)->u.n;</div><div dir="ltr"><br></div><div \
id="yui_3_16_0_ym19_1_1517019474308_3094" dir="ltr">>diff lpeg\lpcode.c \
lpeg-1.0.1\lpcode.c<br id="yui_3_16_0_ym19_1_1517019474308_3095">661d661<br \
id="yui_3_16_0_ym19_1_1517019474308_3096">< if (sib1(tree)->tag != \
TNot) // TNot == UNDO</div><div \
id="yui_3_16_0_ym19_1_1517019474308_3394" dir="ltr"><br></div><div \
id="yui_3_16_0_ym19_1_1517019474308_3395" dir="ltr">>diff lpeg\re.lua \
lpeg-1.0.1\re.lua<br id="yui_3_16_0_ym19_1_1517019474308_3098">23c27,28<br \
id="yui_3_16_0_ym19_1_1517019474308_3099">< local Predef = { nl = m.P"\n", b = \
m.B(-1) }<br id="yui_3_16_0_ym19_1_1517019474308_3100">---<br \
id="yui_3_16_0_ym19_1_1517019474308_3101">> local Predef = { nl = m.P"\n" \
}</div><div id="yui_3_16_0_ym19_1_1517019474308_3396" dir="ltr"><br \
id="yui_3_16_0_ym19_1_1517019474308_3102"></div></div></body></html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic