klahnakoski / mo-parsing

fork of pyparsing
MIT License
3 stars 2 forks source link

MatchFirst is slow #25

Open klahnakoski opened 1 year ago

klahnakoski commented 1 year ago

A number of And combined with MatchFirst results in a slow parsing; no regex is used to jump to the matching pattern

Example

        selection = (
            (SELECT + DISTINCT + ON)
            | assign("select distinct", delimited_list(select_column))
            | assign("select as struct", delimited_list(select_column))
            | assign("select as value", delimited_list(select_column))
            | SELECT + tops + delimited_list(select_column)("select")
        )

mo-sql-parsing has this pattern:

  Except  "Expecting values, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                          {{select + * + except + ( + select_column + (, + select_column)* + )} | {select + distinct + on + ( + select_column + (, + select_column)* + ) + select_column + (, + select_column)*} | {select distinct + select_column + (, + select_column)*} | {select as struct + select_column + (, + select_column)*
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                            {select + * + except + ( + select_column + (, + select_column)* + )} | {select + distinct + on + ( + select_column + (, + select_column)* + ) + select_column + (, + select_column)*} | {select distinct + select_column + (, + select_column)*} | {select as struct + select_column + (, + select_column)*}
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                              select + * + except + ( + select_column + (, + select_column)* + )
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                select
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                  select
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                    select
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                              select + distinct + on + ( + select_column + (, + select_column)* + ) + select_column + (, + select_column)*
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                select
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                  select
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                    select
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                              select distinct + select_column + (, + select_column)*
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                select distinct
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                  select distinct
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                    select
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                              select as struct + select_column + (, + select_column)*
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                select as struct
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                  select as struct
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                    select
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                              select as value + select_column + (, + select_column)*
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                select as value
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                  select as value
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                    select
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                              select + tops + select_column + (, + select_column)*
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                select
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                  select
  Attempt "\"2000-01-0 at loc (51,41), index=2964           for                                                                                                                    select
  Except  "Expecting select, found \"\\\"2000-01-0\" (at char 2964), (line:51, col:41)"