![]() |
Qucs-S S-parameter Viewer & RF Synthesis Tools
|
Static Public Member Functions | |
| convert_to_date (str fmt="%Y-%m-%d") | |
| convert_to_datetime (str fmt="%Y-%m-%dT%H:%M:%S.%f") | |
| strip_html_tags (str s, int l, ParseResults tokens) | |
Static Public Attributes | |
| convert_to_integer = token_map(int) | |
| convert_to_float = token_map(float) | |
| integer = Word(nums).set_name("integer").set_parse_action(convert_to_integer) | |
| tuple | hex_integer |
| tuple | signed_integer |
| tuple | fraction |
| tuple | mixed_integer |
| tuple | real |
| tuple | sci_real |
| tuple | number = (sci_real | real | signed_integer).setName("number").streamline() |
| tuple | fnumber |
| identifier = Word(identchars, identbodychars).set_name("identifier") | |
| ipv4_address | |
| ipv6_address | |
| mac_address | |
| iso8601_date | |
| iso8601_datetime | |
| uuid = Regex(r"[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}").set_name("UUID") | |
| comma_separated_list | |
| upcase_tokens = staticmethod(token_map(lambda t: t.upper())) | |
| downcase_tokens = staticmethod(token_map(lambda t: t.lower())) | |
| url | |
| convertToInteger = convert_to_integer | |
| convertToFloat = convert_to_float | |
| convertToDate = convert_to_date | |
| convertToDatetime = convert_to_datetime | |
| stripHTMLTags = strip_html_tags | |
| upcaseTokens = upcase_tokens | |
| downcaseTokens = downcase_tokens | |
Static Protected Attributes | |
| _ipv6_part = Regex(r"[0-9a-fA-F]{1,4}").set_name("hex_integer") | |
| tuple | _full_ipv6_address |
| tuple | _short_ipv6_address |
| tuple | _mixed_ipv6_address = ("::ffff:" + ipv4_address).set_name("mixed IPv6 address") |
| _html_stripper = any_open_tag.suppress() | any_close_tag.suppress() | |
| tuple | _commasepitem |
Here are some common low-level expressions that may be useful in
jump-starting parser development:
- numeric forms (:class:`integers<integer>`, :class:`reals<real>`,
:class:`scientific notation<sci_real>`)
- common :class:`programming identifiers<identifier>`
- network addresses (:class:`MAC<mac_address>`,
:class:`IPv4<ipv4_address>`, :class:`IPv6<ipv6_address>`)
- ISO8601 :class:`dates<iso8601_date>` and
:class:`datetime<iso8601_datetime>`
- :class:`UUID<uuid>`
- :class:`comma-separated list<comma_separated_list>`
- :class:`url`
Parse actions:
- :class:`convert_to_integer`
- :class:`convert_to_float`
- :class:`convert_to_date`
- :class:`convert_to_datetime`
- :class:`strip_html_tags`
- :class:`upcase_tokens`
- :class:`downcase_tokens`
Example::
pyparsing_common.number.run_tests('''
# any int or real number, returned as the appropriate type
100
-100
+100
3.14159
6.02e23
1e-12
''')
pyparsing_common.fnumber.run_tests('''
# any int or real number, returned as float
100
-100
+100
3.14159
6.02e23
1e-12
''')
pyparsing_common.hex_integer.run_tests('''
# hex numbers
100
FF
''')
pyparsing_common.fraction.run_tests('''
# fractions
1/2
-3/4
''')
pyparsing_common.mixed_integer.run_tests('''
# mixed fractions
1
1/2
-3/4
1-3/4
''')
import uuid
pyparsing_common.uuid.set_parse_action(token_map(uuid.UUID))
pyparsing_common.uuid.run_tests('''
# uuid
12345678-1234-5678-1234-567812345678
''')
prints::
# any int or real number, returned as the appropriate type
100
[100]
-100
[-100]
+100
[100]
3.14159
[3.14159]
6.02e23
[6.02e+23]
1e-12
[1e-12]
# any int or real number, returned as float
100
[100.0]
-100
[-100.0]
+100
[100.0]
3.14159
[3.14159]
6.02e23
[6.02e+23]
1e-12
[1e-12]
# hex numbers
100
[256]
FF
[255]
# fractions
1/2
[0.5]
-3/4
[-0.75]
# mixed fractions
1
[1]
1/2
[0.5]
-3/4
[-0.75]
1-3/4
[1.75]
# uuid
12345678-1234-5678-1234-567812345678
[UUID('12345678-1234-5678-1234-567812345678')]
|
static |
Helper to create a parse action for converting parsed date string to Python datetime.date
Params -
- fmt - format to be passed to datetime.strptime (default= ``"%Y-%m-%d"``)
Example::
date_expr = pyparsing_common.iso8601_date.copy()
date_expr.set_parse_action(pyparsing_common.convert_to_date())
print(date_expr.parse_string("1999-12-31"))
prints::
[datetime.date(1999, 12, 31)]
|
static |
Helper to create a parse action for converting parsed
datetime string to Python datetime.datetime
Params -
- fmt - format to be passed to datetime.strptime (default= ``"%Y-%m-%dT%H:%M:%S.%f"``)
Example::
dt_expr = pyparsing_common.iso8601_datetime.copy()
dt_expr.set_parse_action(pyparsing_common.convert_to_datetime())
print(dt_expr.parse_string("1999-12-31T23:59:59.999"))
prints::
[datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
|
static |
Parse action to remove HTML tags from web page HTML source
Example::
# strip HTML links from normal text
text = '<td>More info at the <a href="https://github.com/pyparsing/pyparsing/wiki">pyparsing</a> wiki page</td>'
td, td_end = make_html_tags("TD")
table_text = td + SkipTo(td_end).set_parse_action(pyparsing_common.strip_html_tags)("body") + td_end
print(table_text.parse_string(text).body)
Prints::
More info at the pyparsing wiki page
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |