PageRenderTime 7ms CodeModel.GetById 3ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/regular_expression/example1.e

http://github.com/tybor/Liberty
Specman e | 48 lines | 33 code | 4 blank | 11 comment | 2 complexity | 68e6ac2581642fab44f26be38fd0f945 MD5 | raw file
 1class EXAMPLE1
 2   --
 3   -- How to do pattern matching with Liberty Eiffel:
 4   --
 5   --            compile -o example1 -boost example1
 6   --
 7
 8create {ANY}
 9   make
10
11feature {ANY}
12   make
13      local
14         factory: REGULAR_EXPRESSION_BUILDER; number: REGULAR_EXPRESSION; tmp: STRING
15      do
16         factory.set_extended_legibility
17         -- Create the regular expression from the pattern.
18         number := factory.convert_perl_pattern("[
19               [0-9]+ # one or more digits
20         ]")
21         check
22         -- The given pattern is valid. Else, consult
23         -- factory.last_error_message and factory.last_error_position
24            number /= Void
25         end
26         io.put_string("Please write some text.%N")
27         io.read_line
28         -- Try if the pattern match some string
29         if number.match(io.last_string) then
30            io.put_string("There is a number in your text. Detected value is : ")
31            tmp := ""
32            -- Access to the matching text
33
34            number.append_pattern_text(io.last_string, tmp)
35            io.put_string(tmp)
36            io.put_new_line
37            -- Try to continue matching on the same string
38            if number.match_next(io.last_string) then
39               io.put_string("There is another number.%N")
40            else
41               io.put_string("There is no other number.%N")
42            end
43         else
44            io.put_string("There is not any number in your text.%N")
45         end
46      end
47
48end -- class EXAMPLE1