HEX
Server: LiteSpeed
System: Linux br-asc-web1845.main-hosting.eu 5.14.0-611.42.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 24 05:30:20 EDT 2026 x86_64
User: u790421558 (790421558)
PHP: 8.2.30
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/gsutil/third_party/pyparsing/examples/lineno_example.py
#
# lineno_example.py
#
# an example of using the location value returned by pyparsing to
# extract the line and column number of the location of the matched text,
# or to extract the entire line of text.
#
# Copyright (c) 2006, Paul McGuire
#
import pyparsing as pp

data = """Now is the time
for all good men
to come to the aid
of their country."""


# demonstrate use of lineno, line, and col in a parse action
def report_long_words(st, locn, toks):
    word = toks[0]
    if len(word) > 3:
        print(
            f"Found {word!r} on line {pp.lineno(locn, st)} at column {pp.col(locn, st)}"
        )
        print("The full line of text was:")
        print(f"{pp.line(locn, st)!r}")
        print(f" {'^':>{pp.col(locn, st)}}")
        print()


wd = pp.Word(pp.alphas).set_parse_action(report_long_words)
wd[1, ...].parse_string(data)


# demonstrate returning an object from a parse action, containing more information
# than just the matching token text
class Token:
    def __init__(self, st, locn, tok_string):
        self.token_string = tok_string
        self.locn = locn
        self.source_line = pp.line(locn, st)
        self.line_no = pp.lineno(locn, st)
        self.col = pp.col(locn, st)

    def __str__(self):
        return f"{self.token_string!r} (line: {self.line_no}, col: {self.col})"


def create_token_object(st, locn, toks):
    return Token(st, locn, toks[0])


wd = pp.Word(pp.alphas).set_parse_action(create_token_object)

for token_obj in wd[1, ...].parse_string(data):
    print(token_obj)