Robot Framework
Reserved.py
Go to the documentation of this file.
1 # Copyright 2008-2015 Nokia Networks
2 # Copyright 2016- Robot Framework Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 from robot.running import RUN_KW_REGISTER
17 
18 
19 RESERVED_KEYWORDS = ['for', 'while', 'break', 'continue', 'end',
20  'if', 'else', 'elif', 'else if', 'return']
21 
22 
23 class Reserved:
24  ROBOT_LIBRARY_SCOPE = 'GLOBAL'
25 
26  def __init__(self):
27  for kw in RESERVED_KEYWORDS:
28  self._add_reserved_add_reserved(kw)
29 
30  def _add_reserved(self, kw):
31  RUN_KW_REGISTER.register_run_keyword('Reserved', kw,
32  args_to_process=0,
33  deprecation_warning=False)
34  self.__dict__[kw] = lambda *args, **kwargs: self._run_reserved_run_reserved(kw)
35 
36  def _run_reserved(self, kw):
37  error = "'%s' is a reserved keyword." % kw.title()
38  if kw in ('for', 'end', 'if', 'else', 'else if'):
39  error += " It must be an upper case '%s'" % kw.upper()
40  if kw in ('else', 'else if'):
41  error += " and follow an opening 'IF'"
42  if kw == 'end':
43  error += " when used as a marker to close a block."
44  else:
45  error += " when used as a marker."
46  if kw == 'elif':
47  error += " The marker to use with 'IF' is 'ELSE IF'."
48  raise Exception(error)