Recent Changes

Yesterday

  1. msg Issues with {{oc.py}} example message posted Issues with {{oc.py}} example First of all, It is always a joy to work with PyParsing! I have been using the oc.py example g…
    Issues with {{oc.py}} example
    First of all, It is always a joy to work with PyParsing!

    I have been using the oc.py example grammar from this wiki to parse a C-like language, but have bumped into two issues (not sure if the first one even qualifies as an issue, but I present my solution for it for the sake of completeness:

    • The regexp for assignments (= operator, last in the operatorPrecedence list) captures the next character after the = due to the regex being used ('=[^=]'). This can be inconvenient if no spaces are used between operators and operands. See eg:
    from oc import expr
     
    print(expr.parseString('a = 1').asList())  # ok
    print(expr.parseString('a==1').asList())  # ok
    print(expr.parseString('a=1').asList())  # hmmm
    I have changed the regexp to ('(?<!=)=(?!=)' to cope with this fact, and I guess it would be useful to update the example accordingly if the current behaviour is undesirable.

    • Function-call like syntax inside IF statements is not parsed correctly. For example:
    from oc import ifstmt
     
    print(ifstmt.parseString('if(a == 1){}').asList())  # ok
    print(ifstmt.parseString('if((a+1) == 1){}').asList())  # ok
    print(ifstmt.parseString('if(a() == 1){}').asList())  # bang!
    I have tried adding function-call like expressions to the first argument (baseExpr) of operatorPrecedence, to no avail (which seemed incorrect to start with given that the Optional part of expr does handle func calls, at least outside if statements).

    TL, DR; Could you give me some pointers on how to update oc.py to cope with function calls inside if statements? Thanks!
    7:47 pm

Wednesday, March 22

  1. 2:16 pm

Tuesday, March 7

  1. page WhosUsingPyparsing edited ... FileSystemStorage SQL parser Verilog parser Docket Alarm - Legal Research "Connector&q…
    ...
    FileSystemStorage SQL parser
    Verilog parser
    Docket Alarm - Legal Research "Connector" Language
    Docket Alarm uses pyparsing to support complex legal queries. While searching the law, lawyers regularly use a relatively advanced and unique search syntax, which is similar to Boolean searching, but includes a few additions such as stemming (using the ! mark) and proximity searching (using w/N operator). For example, the following query will find all documents that have the words "employment" or "employee", within ten words of the any word that starts with "discrim".
    (employment or employee) w/10 discrim!
    Full documentation for this query language is outlined in this article. Currently, the library is not publicly released, but please contact [admin at docketalarm dot com] for more info if interested.

    booleano
    Booleano - A Generic Library for Interpreting Boolean Conditions
    ...
    library function. GustavoGustavo gives various
    ...
    multi-lingual examples. DON'TDON'T WRITE ANOTHER
    reverse_snowflake_joins
    Reverse Snowflake Joins - SQL statement grapher
    ...
    SQL statements. Alexandru'sAlexandru's utility parses
    SELECT
    film.film_id AS FID,
    ...
    film.length AS length,
    film.rating AS rating,
    ...
    _utf8' ',
    actor.last_name) SEPARATOR ', ') AS actors FROM
    category LEFT JOIN
    ...
    graph [splines=true];
    rankdir=LR;
    ...
    [style=filled, fillcolor=white,
    label="CATEGORY | (CATEGORY) |<category_id> category_id|name"];
    ...
    [style=filled, fillcolor=white,
    label="FILM_CATEGORY | (FILM_CATEGORY) |<category_id> category_id| <film_id> film_id"];
    ...
    [style=filled, fillcolor=white,
    label="FILM_ACTOR | (FILM_ACTOR) |<actor_id> actor_id|<film_id> film_id"];
    ...
    [style=filled, fillcolor=white,
    label="ACTOR | (ACTOR) | <actor_id> actor_id|first_name|last_name"];
    ...
    [style=filled, fillcolor=white,
    label="FILM | (FILM) | description|<film_id> film_id|GROUP BY film_id|length|rating|rental_rate|title"];
    ACTOR:actor_id -- FILM_ACTOR:actor_id [color = black arrowtail="none" arrowhead="none"];
    ...
    graphite_cli
    Graphite - Enterprise Real-time Graphing Engine Command Line Interface
    ...
    operational parameters. GraphiteGraphite includes a
    ...
    line interface writtenwritten in pyparsing,
    freeode_siml
    Freeode project - SIML language for solving ODE's
    ...
    differential equations. TheThe SIML language
    func dynamic():
    mu = mu_max * S/(S+Ks); #growth speed (of biomass)
    ...
    svg2pycairo
    svg2pycairo - Read SVG files and display using Cairo
    ...
    using Cairo. DonnDonn waxes poetic
    svg2imagemap
    svg2imagemap - Create image maps from SVG files
    ...
    SVG files. HisHis utility uses
    ...
    map definition. HisHis website includes
    {demo_world.png}
    asdox
    ...
    pymlns
    PyMLNs - Python Markov Logic Networks
    ...
    MLN formulas. HereHere is a
    {pymlns_query.jpg}
    dsniff
    (view changes)
    2:21 pm

Tuesday, February 14

  1. 4:20 am

Wednesday, February 8

  1. msg Multiline Expression message posted Multiline Expression Hi, I'm just learing pyparsing and would like to use it to parse out cisco show command files. …
    Multiline Expression
    Hi,

    I'm just learing pyparsing and would like to use it to parse out cisco show command files. The first thing I want to do is extract the inventory information for a device.

    Each item is in a two line section which needs to be grouped together and each line has two or more comma delimited keyword/value pairs.

    Here is what I've been trying (various permutations) but none give me a single "record" of the inventory item. I'm using scanString as I'm reading in a file with a bunch of show commands.

    Any pointers in the right direction would be most appreciated!!

    Thanks in advance!



    # Open and read in a text file full of show command output
    ParserElement.setDefaultWhitespaceChars(" \t")

    inv_key = Word(alphas)
    inv_value = Word(alphanums)

    first_element = Word('NAME' + ':') + inv_value

    pattern = Combine(OneOrMore(inv_key + ':' + inv_value), adjacent=False)

    first_line = first_element + pattern

    Line = delimitedList(first_line)


    Lines = OneOrMore(Group(Line))

    grammar = Lines
    my_list = grammar.scanString(file_contents)



    N7010# show inventory
    NAME: "Chassis", DESCR: "Nexus7000 C7010 (10 Slot) Chassis "
    PID: N7K-C7010 , VID: V03 , SN: JAF1721XYZA

    NAME: "Slot 1", DESCR: "1/10 Gbps Ethernet Module"
    PID: N7K-F248XP-25E , VID: V01 , SN: JAF1734EFGH

    NAME: "Slot 2", DESCR: "1/10 Gbps Ethernet Module"
    PID: N7K-F248XP-25E , VID: V01 , SN: JAF1748ABCD

    NAME: "Slot 5", DESCR: "Supervisor Module-2"
    PID: N7K-SUP2 , VID: V03 , SN: JAF1804UHM
    6:43 am

Tuesday, February 7

  1. 11:03 pm
  2. msg White Space and LineStart message posted White Space and LineStart (note the lead whitespace in " foo")
    White Space and LineStart
    (note the lead whitespace in " foo")
    8:36 am
  3. msg White Space and LineStart message posted White Space and LineStart Sadly I am being dense. I tried both your approaches and do to misinterpreting (I suspect) they bot…
    White Space and LineStart
    Sadly I am being dense. I tried both your approaches and do to misinterpreting (I suspect) they both fail. Here is my test string:
    simple_str = " foo"
    here is first approach:
    patt = lineStart + Optional(White) + "foo"
    I get a crash using patt.searchSTring(simple_str)
    "type object 'White' has no attribute 'mayIndexError'
    Then tried alternative pattern:
    patt = lineStart + empty + "foo"
    I get no match (returns "[]")
    :-(
    Please advise this simpleton :-)
    8:36 am

Sunday, February 5

  1. 7:56 am

Saturday, February 4

  1. msg there's a bug in fnumber message posted there's a bug in fnumber right now a single '+' is interpreted as a valid number a fix: inumber = Combine(Option…
    there's a bug in fnumber
    right now a single '+' is interpreted as a valid number

    a fix:
    inumber = Combine(Optional(Word("+-", max=1)) + Word(nums))
    fnumber = Combine( inumber +
    Optional( point + Optional( Word( nums ) ) ) +
    Optional( e + inumber))
    5:24 pm

More