예제 #1
0
def test(Text):
    global count_n
    count_n += 1

    if Text.find("\n") == -1:
        print "(%i) |%s|\n" % (count_n, Text)
    else:
        print "(%i)\n::\n%s\n::\n" % (count_n, Text)

    sh      = StringIO(Text)
    sh.name = "test_string"

    descr = None
    # descr = counter.parse_line_column_counter(sh)
    try:    
        descr = counter.parse_line_column_counter(sh)
        pass

    except EndOfStreamException:
        error.log("End of file reached while parsing 'counter' section.", sh, DontExitF=True)

    except:
        print "Exception!"

    if descr is not None: print descr.count_command_map
    print
예제 #2
0
def test(Text):
    global count_n
    count_n += 1

    if Text.find("\n") == -1:
        print "(%i) |%s|\n" % (count_n, Text)
    else:
        print "(%i)\n::\n%s\n::\n" % (count_n, Text)

    sh = StringIO(Text)
    sh.name = "test_string"

    descr = None
    # descr = counter.parse_line_column_counter(sh)
    try:
        descr = counter.parse_line_column_counter(sh)
        pass

    except EndOfStreamException:
        error.log("End of file reached while parsing 'counter' section.",
                  sh,
                  DontExitF=True)

    except:
        print "Exception!"

    if descr is not None: print descr.count_command_map
    print
예제 #3
0
def parse(fh, new_mode):
    source_reference = SourceRef.from_FileHandle(fh)

    identifier = read_option_start(fh)
    if identifier is None: return False

    error.verify_word_in_list(identifier, mode_option_info_db.keys(),
                              "mode option", fh)

    if identifier == "skip":
        value = __parse_skip_option(fh, new_mode, identifier)

    elif identifier in ["skip_range", "skip_nested_range"]:
        value = __parse_range_skipper_option(fh, identifier, new_mode)

    elif identifier == "indentation":
        value = counter.parse_indentation(fh)
        value.set_containing_mode_name(new_mode.name)
        blackboard.required_support_indentation_count_set()

    elif identifier == "counter":
        value = counter.parse_line_column_counter(fh)

    elif identifier in ("entry", "exit", "restrict"):
        value = read_option_value(fh, ListF=True)  # A 'list' of strings
    else:
        value = read_option_value(fh)  # A single string

    # Finally, set the option
    new_mode.option_db.enter(identifier, value, source_reference,
                             new_mode.name)
    return True
예제 #4
0
def parse(fh, new_mode):
    source_reference = SourceRef.from_FileHandle(fh)

    identifier = read_option_start(fh)
    if identifier is None: return False

    verify_word_in_list(identifier, mode_option_info_db.keys(),
                        "mode option", fh.name, get_current_line_info_number(fh))

    if   identifier == "skip":
        value = __parse_skip_option(fh, new_mode, identifier)

    elif identifier in ["skip_range", "skip_nested_range"]:
        value = __parse_range_skipper_option(fh, identifier, new_mode)
        
    elif identifier == "indentation":
        value = counter.parse_indentation(fh)
        value.set_containing_mode_name(new_mode.name)
        blackboard.required_support_indentation_count_set()

    elif identifier == "counter":
        value = counter.parse_line_column_counter(fh)

    elif identifier in ("entry", "exit", "restrict"):
        value = read_option_value(fh, ListF=True) # A 'list' of strings
    else:
        value = read_option_value(fh)             # A single string

    # Finally, set the option
    new_mode.option_db.enter(identifier, value, source_reference, new_mode.name)
    return True
예제 #5
0
def counter_db_wo_reference_p():
    """RETURNS: A counter_db that makes it impossible to use a reference pointer.
    """
    # Reference counter is not possible, since we have two space types
    spec_txt = """
       [\\x0A] => newline 1;
       [\\t]   => grid    4;
       [0-9]   => space   10;
       \else   => space   1;>
    """
    fh = StringIO(spec_txt)
    fh.name        = "<string>"
    return counter_parser.parse_line_column_counter(fh)
예제 #6
0
def counter_db_wo_reference_p():
    """RETURNS: A counter_db that makes it impossible to use a reference pointer.
    """
    # Reference counter is not possible, since we have two space types
    spec_txt = """
       [\\x0A] => newline 1;
       [\\t]   => grid    4;
       [0-9]   => space   10;
       \else   => space   1;>
    """
    fh = StringIO(spec_txt)
    fh.name = "<string>"
    return counter_parser.parse_line_column_counter(fh)
예제 #7
0
import quex.input.regular_expression.engine as     core
import quex.input.files.counter             as     counter
from   StringIO                             import StringIO

if "--hwut-info" in sys.argv:
    print "Predetermined Character Count: Newlines"
    sys.exit(0)
    
spec_txt = """
   [\\x0A\\x0b\\x0c\\x85\\X2028\\X2029] => newline 1;
   [\\t]                                => grid    4;
>"""

fh = StringIO(spec_txt)
fh.name = "<string>"
counter_db = counter.parse_line_column_counter(fh)

def test(TestString):
    global counter_db

    #if "BeginOfLine" in sys.argv:
    #    TestString = "^%s" % TestString
    TestString = TestString.replace("\n", "\\n").replace("\t", "\\t")
    print ("expr. = " + TestString).replace("\n", "\\n").replace("\t", "\\t")
    pattern = core.do(TestString, {})
    pattern.prepare_count_info(counter_db, None)
    print ("info  = {\n    %s\n}\n" % str(pattern.count_info()).replace("\n", "\n    "))

test('[0-9]+')
test('"1\n\n\n3"')
test('"1\n\n\n3"|"A\n\n\nC"')