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

/src/lib/cli/internal/clarg_options.e

http://github.com/tybor/Liberty
Specman e | 111 lines | 78 code | 10 blank | 23 comment | 4 complexity | 46282d6d07308cc0dd3b68ebca87d2f8 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4deferred class CLARG_OPTIONS
  5
  6feature {ANY}
  7   short: FIXED_STRING
  8   long: FIXED_STRING
  9
 10feature {} -- patterns
 11   short_pattern: REGULAR_EXPRESSION
 12      local
 13         re: REGULAR_EXPRESSION_BUILDER
 14      once
 15         Result := re.convert_python_pattern("^(?:-|/)(?P<options>[A-Za-z0-9]+)$")
 16      end
 17
 18   long_pattern: REGULAR_EXPRESSION
 19      local
 20         re: REGULAR_EXPRESSION_BUILDER
 21      once
 22         Result := re.convert_python_pattern("^(?:--)(?P<name>[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?)$")
 23      end
 24
 25   long_equal_pattern: REGULAR_EXPRESSION
 26      local
 27         re: REGULAR_EXPRESSION_BUILDER
 28      once
 29         Result := re.convert_python_pattern("^(?:--)(?P<name>[A-Za-z0-9]([A-Za-z0-9_-]*[A-Za-z0-9])?)=(?P<value>.+)$")
 30      end
 31
 32feature {} -- queries
 33   is_short (arg: STRING; a_index: INTEGER): BOOLEAN
 34      require
 35         short /= Void
 36      local
 37         options: STRING
 38      do
 39         if short_pattern.match(arg) and then short_pattern.named_group_matched(once "options") then
 40            options := short_pattern.named_group_value(arg, once "options")
 41            if options.valid_index(a_index) then
 42               Result := options.item(a_index) = short.first
 43            end
 44         end
 45      end
 46
 47   is_long (arg: STRING): BOOLEAN
 48      require
 49         long /= Void
 50      local
 51         name_: FIXED_STRING
 52      do
 53         if long_pattern.match(arg) and then long_pattern.named_group_matched(once "name") then
 54            name_ := long_pattern.named_group_value(arg, once "name").intern
 55            Result := name_ = long
 56         end
 57      end
 58
 59   is_long_equal (arg: STRING): BOOLEAN
 60      require
 61         long /= Void
 62      local
 63         name_: FIXED_STRING
 64      do
 65         if long_equal_pattern.match(arg) and then long_equal_pattern.named_group_matched(once "name") then
 66            name_ := long_equal_pattern.named_group_value(arg, once "name").intern
 67            Result := name_ = long
 68         end
 69      ensure
 70         Result implies long_equal_pattern.named_group_matched(once "value")
 71      end
 72
 73feature {} -- usage output helpers
 74   put_short (stream: OUTPUT_STREAM)
 75      require
 76         short /= Void
 77      do
 78         stream.put_character('-')
 79         stream.put_character(short.first)
 80      end
 81
 82   put_long (stream: OUTPUT_STREAM)
 83      require
 84         long /= Void
 85      do
 86         stream.put_character('-')
 87         stream.put_character('-')
 88         stream.put_string(long)
 89      end
 90
 91end -- class CLARG_OPTIONS
 92--
 93-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
 94--
 95-- Permission is hereby granted, free of charge, to any person obtaining a copy
 96-- of this software and associated documentation files (the "Software"), to deal
 97-- in the Software without restriction, including without limitation the rights
 98-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 99-- copies of the Software, and to permit persons to whom the Software is
100-- furnished to do so, subject to the following conditions:
101--
102-- The above copyright notice and this permission notice shall be included in
103-- all copies or substantial portions of the Software.
104--
105-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
111-- THE SOFTWARE.