Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 from __future__ import absolute_import, print_function
00016
00017 from nose.tools import assert_raises
00018 import rocon_ebnf.rule_parser as rule_parser
00019
00020
00021
00022
00023
00024 def try_using_windoze_attribute(parser_result):
00025 '''
00026 Used to check if one of the parser's variables is set or not. If not, it raises
00027 an AttributeError
00028 '''
00029 print("%s" % parser_result.windoze)
00030
00031 def print_linux_parsing(input_string, parser_result):
00032 print("Input: %s" % input_string)
00033 if parser_result is not None:
00034 try:
00035 print(" OS list: %s" % parser_result.operating_systems_list)
00036 except AttributeError:
00037 pass
00038 try:
00039 print(" Ubuntu : %s" % parser_result.ubuntu)
00040 except AttributeError:
00041 pass
00042 try:
00043 print(" Linux : %s" % parser_result.linux)
00044 except AttributeError:
00045 pass
00046 try:
00047 print(" OS : %s" % parser_result.os)
00048 except AttributeError:
00049 pass
00050
00051 else:
00052 print("Error in parsing")
00053
00054 def test_message_to_string():
00055
00056
00057 operating_systems_rule = [
00058 'init operating_systems_list=[] ',
00059 'pattern ::= os_zero operating_systems*',
00060 'os_zero ::= os @operating_systems_list.append("$os")',
00061 'operating_systems ::= "|" os @operating_systems_list.append("$os")',
00062 'os ::= "*" | windoze | linux | "osx" | "freebsd"',
00063 'windoze ::= "winxp" | "windows7"',
00064 'linux ::= "arch" | "debian" | "fedora" | "gentoo" | "opensuse" | ubuntu | "linux"',
00065 'ubuntu ::= "precise" | "quantal" | "raring" | "ubuntu"'
00066 ]
00067 input_string = "precise|quantal"
00068 result = rule_parser.match(operating_systems_rule, input_string)
00069 assert result is not None
00070 assert "precise" in result.operating_systems_list
00071 assert "quantal" in result.operating_systems_list
00072 assert result.ubuntu == "quantal"
00073 assert result.linux == "quantal"
00074 assert result.os == "quantal"
00075 assert_raises(AttributeError, try_using_windoze_attribute, result)
00076 print_linux_parsing(input_string, result)
00077
00078 input_string = "*"
00079 result = rule_parser.match(operating_systems_rule, input_string)
00080 assert result is not None
00081 assert result.os == "*"
00082 print_linux_parsing(input_string, result)
00083
00084 input_string = "ubuntu"
00085 result = rule_parser.match(operating_systems_rule, input_string)
00086 assert result is not None
00087 assert result.os == "ubuntu"
00088 print_linux_parsing(input_string, result)
00089
00090 rule = [ 'uri ::= sep os* sep system* sep platform* sep name* sep?',
00091 'sep ::= r"/"',
00092 'os ::= "windows" | "linux" | "precise"',
00093 'system ::= "opros" | ros',
00094 'ros ::= "groovy" | "hydro" | "ros"',
00095 'platform ::= r"." ^sep',
00096 'name ::= r"." ^sep',
00097 ]
00098 rocon_uri = "/precise/ros/turtlebot/dude"
00099 print("Input: %s" % rocon_uri)
00100 result = rule_parser.match(rule, rocon_uri)
00101 if result is not None:
00102 print(" os : %s" % result.os)
00103 print(" system : %s" % result.system)
00104 print(" platform: %s" % result.platform)
00105 print(" name : %s" % result.name)
00106 else:
00107 print("Error in parsing")
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154