From 0b19bb71ba5a4afa84e673a8239935426fa0db23 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Tue, 9 Aug 2016 21:50:19 +0000 Subject: Remove incorrect tag directory git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/tags/pyparsing_2.1.6@405 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b --- trunk/src/examples/parseTabularData.py | 50 ---------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 trunk/src/examples/parseTabularData.py (limited to 'trunk/src/examples/parseTabularData.py') diff --git a/trunk/src/examples/parseTabularData.py b/trunk/src/examples/parseTabularData.py deleted file mode 100644 index 3846310..0000000 --- a/trunk/src/examples/parseTabularData.py +++ /dev/null @@ -1,50 +0,0 @@ -# -# parseTabularData.py -# -# Example of parsing data that is formatted in a tabular listing, with -# potential for missing values. Uses new addCondition method on -# ParserElements. -# -# Copyright 2015, Paul McGuire -# -from pyparsing import col,Word,Optional,alphas,nums,ParseException - -table = """\ - 1 2 -12345678901234567890 -COLOR S M L -RED 10 2 2 -BLUE 5 10 -GREEN 3 5 -PURPLE 8""" - -# function to create column-specific parse conditions -def mustMatchCols(startloc,endloc): - return lambda s,l,t: startloc <= col(l,s) <= endloc - -# helper to define values in a space-delimited table -# (change empty_cell_is_zero to True if a value of 0 is desired for empty cells) -def tableValue(expr, colstart, colend): - empty_cell_is_zero = False - if empty_cell_is_zero: - return Optional(expr.copy().addCondition(mustMatchCols(colstart,colend), - message="text not in expected columns"), - default=0) - else: - return Optional(expr.copy().addCondition(mustMatchCols(colstart,colend), - message="text not in expected columns")) - - -# define the grammar for this simple table -colorname = Word(alphas) -integer = Word(nums).setParseAction(lambda t: int(t[0])).setName("integer") -row = (colorname("name") + - tableValue(integer, 11, 12)("S") + - tableValue(integer, 15, 16)("M") + - tableValue(integer, 19, 20)("L")) - -# parse the sample text - skip over the header and counter lines -for line in table.splitlines()[3:]: - print(line) - print(row.parseString(line).dump()) - print('') -- cgit v1.2.1