#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Simple: Tiny Expressions", "SAME;") pattern_action_pair_list = [ # pre-contexted expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. ('[A-Z]+":"', "LABEL"), ('"PRINT"', "KEYWORD"), ('[A-Z]+', "IDENTIFIER"), ('[ \\t]+', "WHITESPACE"), ] test_str = "ABERHALLO: GUGU PRINT PRINT: PRINTERLEIN" generator_test.do(pattern_action_pair_list, test_str, {}, choice)
#! /usr/bin/env python import sys sys.path.append("../../../../") import generator_test choice = generator_test.hwut_input("Simple: Maximum Length Match", "SAME;") pattern_dict = {"DIGIT": "[0-9]"} pattern_action_pair_list = [ # keyword (need to come before identifier, because otherwise they would be overruled by it.) ('"if"', "IF"), ('"else"', "ELSE"), ('"struct"', "STRUCT"), ('"for"', "FOR"), ('"typedef"', "TYPEDEF"), ('"typedefun"', "TYPEDEFUN"), ('"type"', "TYPE"), ('"def"', "DEF"), ('"fun"', "FUN"), ('"while"', "WHILE"), ('"return"', "RETURN"), # identifier ('[_a-zA-Z][_a-zA-Z0-9]*', "IDENTIFIER"), # ('"{"', "BRACKET_OPEN"), ('"}"', "BRACKET_CLOSE"), ('"("', "BRACKET_OPEN"), ('")"', "BRACKET_CLOSE"), ('";"', "SEMICOLON"), ('"="', "OP_ASSIGN"), ('"=="', "OP_COMPARISON"),
#! /usr/bin/env python import generator_test from generator_test import hwut_input choice = hwut_input("Simple: Begin of Line (BOL), End of Line (EOL)", "SAME;") pattern_action_pair_list = [ # pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. ('^[A-Z]+":"', "BOL-LABEL"), ('[A-Z]+":"', "LABEL"), ('"PRINT"', "KEYWORD"), ('[A-Z]+', "IDENTIFIER"), ('[A-Z]+$', "EOL-IDENTIFIER"), ('[ \\t]+', "WHITESPACE"), ('\\n', "NEWNLINE"), ] test_str = \ """HERE: THERE: THIS THAT HERE: THERE: THIS THAT""" generator_test.do(pattern_action_pair_list, test_str, {}, choice)
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input( "Pre Conditions: Multiple Identical Pre-Conditions", "SAME;") pattern_list = [ # -- pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-conditioned patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # repetition of 'x' (one or more) **preceded** by 'good' + whitespace 'ABC/hello/', 'A([bB]+)C/world/', 'AB(C+)/[a-z]{5}/', '(abc|ABC)/worldly/', # normal repetition (one or more) of 'x' '(X+)Y(Z+)/hello/', '[xX][yY][zZ]/world/', 'XYZ/[a-z]{5}/', '(X(Y)+Z)+/worldly/', # whitespace '[ \\t\\n]+', 'ABC|XYZ', ] pattern_action_pair_list = map( lambda re: (re, re.replace("\\t", "\\\\t").replace("\\n", "\\\\n")), pattern_list)
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input( "CONTINUE: Reentry analysis without return from function", "SAME;") pattern_action_pair_list = [ # pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. ('[A-Z]+":"', "LABEL"), ('"PRINT"', "KEYWORD CONTINUE"), ('[A-Z]+', "IDENTIFIER CONTINUE"), ('[ \\t]+', "WHITESPACE CONTINUE"), ] test_str = "ABERHALLO: GUGU PRINT PRINT: PRINTERLEIN" generator_test.do(pattern_action_pair_list, test_str, {}, choice)
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Pre- and Post- Conditions: Priorities", "SAME;") def test(Info, PatternActionPairList, TestStr, Choice): print "==========================================================================" print info generator_test.do(PatternActionPairList, TestStr, {}, Choice) #===================================================================================== pattern_action_pair_list = [ ('"x"', "[A-Z]"), ('[A-Z]', "OTHER"), ('"x"/"Z"', "X / Z"), ('"A"/"x"/', "A / X /"), ('[ ]', "WHITESPACE"), ('"x"/[YZ]', "X / [YZ]"), ] info = \ """ (1) Same Length of Core Pattern -- 'x' preceedes 'A/x/' thus 'A/x/' shall never trigger -- 'x' preceedes 'x/Z', but 'x/Z' is a post conditioned pattern => 'x/Z' succeeds. -- 'x/Z' preceeds 'x/[YZ]', thus for 'xZ' the second shall never match. """
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Pre Conditions: Part 2", "SAME;") pattern_action_pair_list = [ # -- pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-conditioned patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # repetition of 'x' (one or more) **preceded** by 'good' + whitespace ('"aber"/"x"+/', "ABER / X+ /"), # something that catches what detect the pre-condition ('[a-u]+', "IDENITIFIER"), # ('[ \\t]+/"x"+/', "WHITESPACE / X+ /"), # normal repetition (one or more) of 'x' ('"x"+', "X+"), # whitespace ('[ \\t\\n]+', "WHITESPACE") ] test_str = "x xxxxx aberxxx x" generator_test.do(pattern_action_pair_list, test_str, {}, choice)
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Pre Conditions: Multiple Identical Pre-Conditions", "SAME;") pattern_list = [ # -- pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-conditioned patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # repetition of 'x' (one or more) **preceded** by 'good' + whitespace 'ABC/hello/', 'A([bB]+)C/world/', 'AB(C+)/[a-z]{5}/', '(abc|ABC)/worldly/', # normal repetition (one or more) of 'x' '(X+)Y(Z+)/hello/', '[xX][yY][zZ]/world/', 'XYZ/[a-z]{5}/', '(X(Y)+Z)+/worldly/', # whitespace '[ \\t\\n]+', 'ABC|XYZ', ] pattern_action_pair_list = map(lambda re: (re, re.replace("\\t", "\\\\t").replace("\\n", "\\\\n")), pattern_list) test_str = """
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input( "Pseudo Ambgiguous Post Condition: Part II", "SAME;", DeleteChoices=["Cpp-PathUniform", "Cpp-PathUniform-CG"]) pattern_list = [ # -- pre-contexted expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-conditioned patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # normal repetition (one or more) of 'x' 'hey/h', '(hey)+/hey', 'hey', # other characters '[a-z]+', # whitespace '[ \\t\\n]+' ] pattern_action_pair_list = map(lambda x: [x, x.replace("\\", "\\\\")], pattern_list) test_str = "heyheyhey hey yhey eyhey heyhey heyhe" generator_test.do(pattern_action_pair_list,
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Pre- and Post- Conditions: Simple", "SAME;") pattern_action_pair_list = [ # -- pre-contexted expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-contexted patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # other characters ('[a-wz]+', "OTHER+"), # repetition of 'x' (one or more) **preceded** by 'good' + whitespace ('"hello"[ \\t]+/"x"+/[ \\t]+"world"', "HELLO / X+ / WORLD"), # ('"x"+/[ \\t]+"world"', "X+ / WORLD"), # repetition of 'x' (one or more) **preceded** by 'good' + whitespace ('"hello"[ \\t]+/"x"+/', "HELLO WSPC. / X+ /"), # normal repetition (one or more) of 'x' ('"x"+', "X+"), # whitespace ('[ \\t\\n]+', "WHITESPACE") ] test_str = "x hello xxxbonjour hello xx world xx world hello xxx x x" generator_test.do(pattern_action_pair_list, test_str, {}, choice)
#! /usr/bin/env python import sys sys.path.append("../../../../") import generator_test choice = generator_test.hwut_input( "Buffer Reload: No Backward Reload -- Precondition at Border", "SAME;", ["Cpp-ASSERTS", "ANSI-C-ASSERTS"]) if choice.find("-ASSERTS") != -1: choice = choice.replace("-ASSERTS", "") ASSERT_str = "-DQUEX_OPTION_ASSERTS" else: ASSERT_str = "" pattern_action_pair_list = [ # keyword (needs to come before identifier, because otherwise they would be overruled by it.) ('"0xxxxx"/"a"/', "0xxxxx / a"), # identifier ('[0a-z]{2}', "IDENTIFIER"), # ('[ \\t\\n]+', "WHITESPACE") ] print "## NOTE: The following setup guides the lexer into a buffer reload right after" print "## the pre-conditions. No buffer reload backwards is to appear!" test_str = " 0xxxxxa lola" generator_test.do(pattern_action_pair_list, test_str, {}, choice,
#! /usr/bin/env python import sys sys.path.append("../../../../") import generator_test choice = generator_test.hwut_input("Buffer Reload: Forward Position Adaption", "SAME;", ["Cpp-ASSERTS", "ANSI-C-ASSERTS"]) if choice.find("-ASSERTS") != -1: choice = choice.replace("-ASSERTS", "") ASSERT_str = "-DQUEX_OPTION_ASSERTS" else: ASSERT_str = "" pattern_action_pair_list = [ # keyword (needs to come before identifier, because otherwise they would be overruled by it.) ('"X"/"XXXXXXXXX"', "1 X / ... X"), ('"XX"/"XXXXXXXY"', "2 X / ... Y"), ('"XXX"/"XXXXXXZ"', "3 X / ... Z"), ('"XXXX"/"XXXXXA"', "4 X / ... A"), # identifier ('[_a-zA-Z][_a-zA-Z0-9]*', "IDENTIFIER"), # ('[ \\t\\n]+', "WHITESPACE") ] # NOTE: Buffer Length in generator_test.py = 15 # => number of X = 10, so that at lease one buffer load has to occur test_str = """
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Simple: Keywords 'for', 'forest', 'forester', and 'formidable'", "SAME;", DeleteChoices=("Cpp-PathUniform", "Cpp-PathUniform-CG")) pattern_action_pair_list = [ # pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. ('[a-eg-z]+', "IDENTIFIER"), ('" "+', "WHITESPACE"), ('for', "FOR"), ('forest', "FOREST"), ('forester', "FORESTER"), ('formidable', "FORMIDABLE"), ] test_str = "for forester forest formidable forever foresmic foresti foresteri formidablek formidabl" generator_test.do(pattern_action_pair_list, test_str, {}, choice)
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input( "Pseudo Ambgiguous Post Condition: The Philosophical Cut", "SAME;") pattern_list = [ # -- pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-conditioned patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # normal repetition (one or more) of 'x' # 'hey+/hey+', 'hey+/(he[y]?)+', # other characters '[a-z]+', # whitespace '[ \\t\\n]+' ] pattern_action_pair_list = map(lambda x: [x, x.replace("\\", "\\\\")], pattern_list) test_str = "heyheyhe hey yhey eyhey heyhey heyhe" generator_test.do(pattern_action_pair_list, test_str, {}, choice, QuexBufferSize=20)
#! /usr/bin/env python import sys import os sys.path.insert(0, os.environ["QUEX_PATH"]) import generator_test choice = generator_test.hwut_input("Buffer Reload: Backwards", "SAME;", ["Cpp-ASSERTS", "ANSI-C-ASSERTS"], ["Cpp_StrangeStream"]) if choice.find("-ASSERTS") != -1: choice = choice.replace("-ASSERTS", "") ASSERT_str = "-DQUEX_OPTION_ASSERTS" else: ASSERT_str = "" pattern_action_pair_list = [ # keyword (needs to come before identifier, because otherwise they would be overruled by it.) ('"0xxxxxxx"/"a"/', "0xxxxxxx / a"), # identifier ('[0a-z]{2}', "IDENTIFIER"), # ('[ \\t\\n]+', "WHITESPACE") ] # |12456789| test_str = " 0xxxxxxalola 0xxxxxxxa" generator_test.do(pattern_action_pair_list, test_str, {}, Language=choice,
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Pre- and Post- Conditions: Priorities", "SAME;") def test(Info, PatternActionPairList, TestStr, Choice): print "==========================================================================" print info generator_test.do(PatternActionPairList, TestStr, {}, Choice) #===================================================================================== pattern_action_pair_list = [ ('"x"', "[A-Z]"), ('[A-Z]', "OTHER"), ('"x"/"Z"', "X / Z"), ('"A"/"x"/', "A / X /"), ('[ ]', "WHITESPACE"), ('"x"/[YZ]', "X / [YZ]"), ] info = \ """ (1) Same Length of Core Pattern -- 'x' preceedes 'A/x/' thus 'A/x/' shall never trigger -- 'x' preceedes 'x/Z', but 'x/Z' is a post conditioned pattern => 'x/Z' succeeds. -- 'x/Z' preceeds 'x/[YZ]', thus for 'xZ' the second shall never match. """ test_str = "AxZ Ax xY"
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Pre- and Post- Conditions: Simple", "SAME;") pattern_action_pair_list = [ # -- pre-contexted expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-contexted patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # other characters ('[a-wz]+', "OTHER+"), # repetition of 'x' (one or more) **preceded** by 'good' + whitespace ('"hello"[ \\t]+/"x"+/[ \\t]+"world"', "HELLO / X+ / WORLD"), # ('"x"+/[ \\t]+"world"', "X+ / WORLD"), # repetition of 'x' (one or more) **preceded** by 'good' + whitespace ('"hello"[ \\t]+/"x"+/', "HELLO WSPC. / X+ /"), # normal repetition (one or more) of 'x' ('"x"+', "X+"), # whitespace ('[ \\t\\n]+', "WHITESPACE") ] test_str = "x hello xxxbonjour hello xx world xx world hello xxx x x" generator_test.do(pattern_action_pair_list, test_str, {}, choice, QuexBufferSize=13)
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("Pseudo Ambgiguous Post Condition: Part II", "SAME;", DeleteChoices=["Cpp-PathUniform", "Cpp-PathUniform-CG"]) pattern_list = [ # -- pre-contexted expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. # # -- post-conditioned patterns do not need to appear before the same non-postconditioned # patterns, since they are always longer. # # normal repetition (one or more) of 'x' 'hey/h', '(hey)+/hey', 'hey', # other characters '[a-z]+', # whitespace '[ \\t\\n]+' ] pattern_action_pair_list = map(lambda x: [x, x.replace("\\", "\\\\")], pattern_list) test_str = "heyheyhey hey yhey eyhey heyhey heyhe" generator_test.do(pattern_action_pair_list, test_str, {}, choice, QuexBufferSize=20)
#! /usr/bin/env python import sys sys.path.append("../../../../") import generator_test choice = generator_test.hwut_input("Buffer Reload: No Backward Reload -- Precondition at Border", "SAME;", ["Cpp-ASSERTS", "ANSI-C-ASSERTS"]) if choice.find("-ASSERTS") != -1: choice = choice.replace("-ASSERTS", "") ASSERT_str = "-DQUEX_OPTION_ASSERTS" else: ASSERT_str = "" pattern_action_pair_list = [ # keyword (needs to come before identifier, because otherwise they would be overruled by it.) ('"0xxxxx"/"a"/', "0xxxxx / a"), # identifier ('[0a-z]{2}', "IDENTIFIER"), # ('[ \\t\\n]+', "WHITESPACE") ] print "## NOTE: The following setup guides the lexer into a buffer reload right after" print "## the pre-conditions. No buffer reload backwards is to appear!" test_str = " 0xxxxxa lola" generator_test.do(pattern_action_pair_list, test_str, {}, choice, QuexBufferSize=11, QuexBufferFallbackN=2, ShowBufferLoadsF=True, AssertsActionvation_str=ASSERT_str)
#! /usr/bin/env python import generator_test choice = generator_test.hwut_input("CONTINUE: Reentry analysis without return from function", "SAME;") pattern_action_pair_list = [ # pre-conditioned expressions need to preceed same (non-preoconditioned) expressions, # otherwise, the un-conditional expressions gain precedence and the un-conditional # pattern is never matched. ('[A-Z]+":"', "LABEL"), ('"PRINT"', "KEYWORD CONTINUE"), ('[A-Z]+', "IDENTIFIER CONTINUE"), ('[ \\t]+', "WHITESPACE CONTINUE"), ] test_str = "ABERHALLO: GUGU PRINT PRINT: PRINTERLEIN" generator_test.do(pattern_action_pair_list, test_str, {}, choice)
#! /usr/bin/env python import sys sys.path.append("../../../../") import generator_test choice = generator_test.hwut_input("Simple: Maximum Length Match", "SAME;") pattern_dict = { "DIGIT": "[0-9]" } pattern_action_pair_list = [ # keyword (need to come before identifier, because otherwise they would be overruled by it.) ('"if"', "IF"), ('"else"', "ELSE"), ('"struct"', "STRUCT"), ('"for"', "FOR"), ('"typedef"', "TYPEDEF"), ('"typedefun"', "TYPEDEFUN"), ('"type"', "TYPE"), ('"def"', "DEF"), ('"fun"', "FUN"), ('"while"', "WHILE"), ('"return"', "RETURN"), # identifier ('[_a-zA-Z][_a-zA-Z0-9]*', "IDENTIFIER"), # ('"{"', "BRACKET_OPEN"), ('"}"', "BRACKET_CLOSE"), ('"("', "BRACKET_OPEN"), ('")"', "BRACKET_CLOSE"), ('";"', "SEMICOLON"), ('"="', "OP_ASSIGN"), ('"=="', "OP_COMPARISON"),