Project

Profile

Help

Revision 0713b7fd

Added by Vincent Le Goff over 4 years ago

Add a SharpScript syntax to support flags

View differences:

src/sharp/engine.py
97 97
                argument = "compile(" + argument + ", 'SharpScript', 'exec')"
98 98
            elif argument.startswith("{"):
99 99
                argument = repr(argument[1:-1])
100
            elif argument.endswith("=True") or argument.endswith("=False"):
101
                pass
100 102
            else:
101 103
                argument = repr(argument)
102 104

  
......
153 155
                    argument = remaining.splitlines()[0]
154 156
                    i += len(argument)
155 157
                    arguments = [argument]
158
            elif remaining[0] in "+-":
159
                argument = remaining.splitlines()[0].split(" ")[0]
160
                flag = argument[1:]
161
                if argument.startswith("+"):
162
                    arguments.append(flag + "=True")
163
                else:
164
                    arguments.append(flag + "=False")
165
                i += len(flag) + 1
156 166
            elif remaining[0] == "{":
157 167
                end = self.find_right_brace(remaining)
158 168
                argument = remaining[:end + 1]
src/tests/sharp/test_syntax.py
84 84
            "trigger('Should it work?', compile('var = 2 + 3\nprint var\n', " \
85 85
            "'SharpScript', 'exec'))"
86 86
        ])
87

  
88
    def test_flag(self):
89
        """Test the SharpScript syntax with flags in funciton calls."""
90
        statements = self.engine.feed("#say {A message} -braille +speech")
91
        self.assertEqual(statements, [
92
            "say('A message', braille=False, speech=True)"
93
        ])

Also available in: Unified diff