lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thanks for the suggestion I just extended a bit the original lpegrex.lua debug info and added statistics about the total/succeed/fail for each rule in a grammar.

it can be seen on https://mingodad.github.io/lua-wasm-playground/ with the Json parser** where I inlined "lpegrex.lua" to test/show it.

====

ENTER Json (1:1)
ENTER SKIP (1:1)
OK SKIP (1:1)
ENTER Object (1:1)
ENTER { (1:1)
FAILED { (1:1)
FAILED Object (1:1)
ENTER Array (1:1)
ENTER [ (1:1)
ENTER SKIP (1:2)
OK SKIP (1:2)
OK [ (1:2)
ENTER Value (1:2)
ENTER String (1:2)
FAILED String (1:2)
ENTER Number (1:2)
FAILED Number (1:2)
ENTER Object (1:2)
ENTER { (1:2)
ENTER SKIP (2:0)
OK SKIP (2:5)
OK { (2:5)
ENTER Member (2:5)
ENTER String (2:5)
ENTER SKIP (2:13)
OK SKIP (2:13)
OK String (2:13)
ENTER : (2:13)
ENTER SKIP (2:14)
OK SKIP (2:15)
OK : (2:15)
ENTER Value (2:15)
ENTER String (2:15)
ENTER ESCAPE (2:21)
OK ESCAPE (2:22)
ENTER SKIP (2:27)
OK SKIP (2:27)
OK String (2:27)
OK Value (2:27)
OK Member (2:27)
ENTER , (2:27)
ENTER SKIP (3:0)
OK SKIP (3:5)
OK , (3:5)
ENTER Member (3:5)
ENTER String (3:5)
ENTER SKIP (3:14)
OK SKIP (3:14)
OK String (3:14)
ENTER : (3:14)
ENTER SKIP (3:15)
OK SKIP (3:16)
OK : (3:16)
ENTER Value (3:16)
ENTER String (3:16)
FAILED String (3:16)
ENTER Number (3:16)
FAILED Number (3:16)
ENTER Object (3:16)
ENTER { (3:16)
FAILED { (3:16)
FAILED Object (3:16)
ENTER Array (3:16)
ENTER [ (3:16)
FAILED [ (3:16)
FAILED Array (3:16)
ENTER Boolean (3:16)
ENTER NAME_SUFFIX (3:20)
FAILED NAME_SUFFIX (3:20)
ENTER SKIP (3:20)
OK SKIP (3:20)
OK Boolean (3:20)
OK Value (3:20)
OK Member (3:20)
ENTER , (3:20)
ENTER SKIP (4:0)
OK SKIP (4:5)
OK , (4:5)
ENTER Member (4:5)
ENTER String (4:5)
ENTER SKIP (4:13)
OK SKIP (4:13)
OK String (4:13)
ENTER : (4:13)
ENTER SKIP (4:14)
OK SKIP (4:15)
OK : (4:15)
ENTER Value (4:15)
ENTER String (4:15)
FAILED String (4:15)
ENTER Number (4:15)
ENTER SKIP (4:22)
OK SKIP (4:22)
OK Number (4:22)
OK Value (4:22)
OK Member (4:22)
ENTER , (4:22)
ENTER SKIP (5:0)
OK SKIP (5:5)
OK , (5:5)
ENTER Member (5:5)
ENTER String (5:5)
ENTER SKIP (5:11)
OK SKIP (5:11)
OK String (5:11)
ENTER : (5:11)
ENTER SKIP (5:12)
OK SKIP (5:13)
OK : (5:13)
ENTER Value (5:13)
ENTER String (5:13)
FAILED String (5:13)
ENTER Number (5:13)
FAILED Number (5:13)
ENTER Object (5:13)
ENTER { (5:13)
FAILED { (5:13)
FAILED Object (5:13)
ENTER Array (5:13)
ENTER [ (5:13)
FAILED [ (5:13)
FAILED Array (5:13)
ENTER Boolean (5:13)
FAILED Boolean (5:13)
ENTER Null (5:13)
ENTER NAME_SUFFIX (6:0)
FAILED NAME_SUFFIX (6:0)
ENTER SKIP (6:0)
OK SKIP (6:1)
OK Null (6:1)
OK Value (6:1)
OK Member (6:1)
ENTER , (6:1)
FAILED , (6:1)
ENTER } (6:1)
ENTER SKIP (6:2)
OK SKIP (6:2)
OK } (6:2)
OK Object (6:2)
OK Value (6:2)
ENTER , (6:2)
FAILED , (6:2)
ENTER ] (6:2)
ENTER SKIP (7:0)
OK SKIP (7:0)
OK ] (7:0)
OK Array (7:0)
OK Json (7:0)
= Rule counters:
    Total    Succed    %    Failed    %    Rule
    74    52    70.27    22    29.73    all rules
    20    20    100.00    0    0.00    SKIP
    9    5    55.56    4    44.44    String
    5    5    100.00    0    0.00    Value
    5    3    60.00    2    40.00    ,
    4    1    25.00    3    75.00    Number
    4    1    25.00    3    75.00    Object
    4    4    100.00    0    0.00    Member
    4    1    25.00    3    75.00    {
    4    4    100.00    0    0.00    :
    3    1    33.33    2    66.67    Array
    3    1    33.33    2    66.67    [
    2    1    50.00    1    50.00    Boolean
    2    0    0.00    2    100.00    NAME_SUFFIX
    1    1    100.00    0    0.00    ESCAPE
    1    1    100.00    0    0.00    }
    1    1    100.00    0    0.00    ]
    1    1    100.00    0    0.00    Null
    1    1    100.00    0    0.00    Json
Array
| Object
| | Member
| | | "string"
| | | "some\ntext"
| | Member
| | | "boolean"
| | | true
| | Member
| | | "number"
| | | -150.0
| | Member
| | | "null"

====

On 9/12/22 16:48, Roberto Ierusalimschy wrote:
Then I tried to improve it a bit (noticed return false in "failed"):

[...]
           local failed = lpeg.Cmt(lpeg.P(true), function(s, p)
             local lineno, colno = lpegrex.calcline(s, p)
             io.stderr:write(string.format('FAILED %s (%d:%d)\n', k, lineno,
colno))
             return false
           end)

Has anyone any idea of a workaround ?
LPeg does not know that 'failed' cannot succeed, but you can try to
include that information:

-- UNTESTED, but it probably will work

   local failed = lpeg.P(function(s, p) <as before> end) * false

-- Roberto