Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CCS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Brice Videau
CCS
Commits
874b12bf
Commit
874b12bf
authored
Aug 07, 2020
by
Brice Videau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unified parsers.
parent
075cc6cf
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
21 deletions
+35
-21
bindings/python/cconfigspace/expression.py
bindings/python/cconfigspace/expression.py
+6
-0
bindings/python/cconfigspace/expression_parser.py
bindings/python/cconfigspace/expression_parser.py
+8
-5
bindings/python/test/test_expression.py
bindings/python/test/test_expression.py
+3
-3
bindings/python/test/test_expression_parser.py
bindings/python/test/test_expression_parser.py
+6
-6
bindings/ruby/lib/cconfigspace/expression.rb
bindings/ruby/lib/cconfigspace/expression.rb
+3
-1
bindings/ruby/lib/cconfigspace/expression_parser.rb
bindings/ruby/lib/cconfigspace/expression_parser.rb
+7
-4
bindings/ruby/test/test_expression_parser.rb
bindings/ruby/test/test_expression_parser.rb
+2
-2
No files found.
bindings/python/cconfigspace/expression.py
View file @
874b12bf
...
@@ -216,6 +216,12 @@ class Literal(Expression):
...
@@ -216,6 +216,12 @@ class Literal(Expression):
v
=
self
.
value
v
=
self
.
value
if
isinstance
(
v
,
str
):
if
isinstance
(
v
,
str
):
return
repr
(
v
)
return
repr
(
v
)
elif
v
is
None
:
return
"none"
elif
v
is
True
:
return
"true"
elif
v
is
False
:
return
"false"
else
:
else
:
return
"{}"
.
format
(
v
)
return
"{}"
.
format
(
v
)
...
...
bindings/python/cconfigspace/expression_parser.py
View file @
874b12bf
...
@@ -21,15 +21,17 @@ list: '[' list_item ']'
...
@@ -21,15 +21,17 @@ list: '[' list_item ']'
list_item: list_item ',' value
list_item: list_item ',' value
| value;
| value;
value: none
value: none
| boolean
| btrue
| bfalse
| string
| string
| identifier
| identifier
| integer
| integer
| float;
| float;
terminals
terminals
none: /None/ {prefer};
none: /none/ {prefer};
boolean: /True|False/ {prefer};
btrue: /true/ {prefer};
bfalse: /false/ {prefer};
identifier: /[a-zA-Z_][a-zA-Z_0-9]*/;
identifier: /[a-zA-Z_][a-zA-Z_0-9]*/;
string: /"([^\0\t\n\r\f"\\]|\\[0tnrf"\\])+"|'([^\0\t\n\r\f'\\]|\\[0tnrf'\\])+'/;
string: /"([^\0\t\n\r\f"\\]|\\[0tnrf"\\])+"|'([^\0\t\n\r\f'\\]|\\[0tnrf'\\])+'/;
integer: /-?[0-9]+/;
integer: /-?[0-9]+/;
...
@@ -53,8 +55,9 @@ _actions["list_item"] = [
...
@@ -53,8 +55,9 @@ _actions["list_item"] = [
lambda
_
,
n
:
n
[
0
]
+
[
n
[
2
]],
lambda
_
,
n
:
n
[
0
]
+
[
n
[
2
]],
lambda
_
,
n
:
[
n
[
0
]]
lambda
_
,
n
:
[
n
[
0
]]
]
]
_actions
[
"none"
]
=
lambda
_
,
value
:
Literal
(
value
=
eval
(
value
))
_actions
[
"none"
]
=
lambda
_
,
value
:
Literal
(
value
=
None
)
_actions
[
"boolean"
]
=
lambda
_
,
value
:
Literal
(
value
=
eval
(
value
))
_actions
[
"btrue"
]
=
lambda
_
,
value
:
Literal
(
value
=
True
)
_actions
[
"bfalse"
]
=
lambda
_
,
value
:
Literal
(
value
=
False
)
_actions
[
"identifier"
]
=
lambda
p
,
value
:
Variable
(
hyperparameter
=
p
.
extra
.
hyperparameter_by_name
(
value
))
_actions
[
"identifier"
]
=
lambda
p
,
value
:
Variable
(
hyperparameter
=
p
.
extra
.
hyperparameter_by_name
(
value
))
_actions
[
"string"
]
=
lambda
_
,
value
:
Literal
(
value
=
eval
(
value
))
_actions
[
"string"
]
=
lambda
_
,
value
:
Literal
(
value
=
eval
(
value
))
_actions
[
"float"
]
=
lambda
_
,
value
:
Literal
(
value
=
float
(
value
))
_actions
[
"float"
]
=
lambda
_
,
value
:
Literal
(
value
=
float
(
value
))
...
...
bindings/python/test/test_expression.py
View file @
874b12bf
...
@@ -32,7 +32,7 @@ class TestExpression(unittest.TestCase):
...
@@ -32,7 +32,7 @@ class TestExpression(unittest.TestCase):
e
=
ccs
.
Literal
(
value
=
15
)
e
=
ccs
.
Literal
(
value
=
15
)
self
.
assertEqual
(
"15"
,
str
(
e
)
)
self
.
assertEqual
(
"15"
,
str
(
e
)
)
e
=
ccs
.
Literal
(
value
=
None
)
e
=
ccs
.
Literal
(
value
=
None
)
self
.
assertEqual
(
"
N
one"
,
str
(
e
)
)
self
.
assertEqual
(
"
n
one"
,
str
(
e
)
)
def
test_variable
(
self
):
def
test_variable
(
self
):
h
=
ccs
.
NumericalHyperparameter
()
h
=
ccs
.
NumericalHyperparameter
()
...
@@ -51,12 +51,12 @@ class TestExpression(unittest.TestCase):
...
@@ -51,12 +51,12 @@ class TestExpression(unittest.TestCase):
def
test_unary
(
self
):
def
test_unary
(
self
):
e
=
ccs
.
Expression
.
unary
(
t
=
ccs
.
NOT
,
node
=
True
)
e
=
ccs
.
Expression
.
unary
(
t
=
ccs
.
NOT
,
node
=
True
)
self
.
assertEqual
(
"!
T
rue"
,
str
(
e
)
)
self
.
assertEqual
(
"!
t
rue"
,
str
(
e
)
)
self
.
assertFalse
(
e
.
eval
()
)
self
.
assertFalse
(
e
.
eval
()
)
def
test_binary
(
self
):
def
test_binary
(
self
):
e
=
ccs
.
Expression
.
binary
(
t
=
ccs
.
OR
,
left
=
True
,
right
=
False
)
e
=
ccs
.
Expression
.
binary
(
t
=
ccs
.
OR
,
left
=
True
,
right
=
False
)
self
.
assertEqual
(
"
True || F
alse"
,
str
(
e
)
)
self
.
assertEqual
(
"
true || f
alse"
,
str
(
e
)
)
self
.
assertTrue
(
e
.
eval
()
)
self
.
assertTrue
(
e
.
eval
()
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
bindings/python/test/test_expression_parser.py
View file @
874b12bf
...
@@ -39,23 +39,23 @@ class TestExpressionParser(unittest.TestCase):
...
@@ -39,23 +39,23 @@ class TestExpressionParser(unittest.TestCase):
self
.
assertFalse
(
res
.
eval
()
)
self
.
assertFalse
(
res
.
eval
()
)
def
test_boolean
(
self
):
def
test_boolean
(
self
):
exp
=
"
T
rue"
exp
=
"
t
rue"
res
=
ccs
.
ccs_parser
.
parse
(
exp
)
res
=
ccs
.
ccs_parser
.
parse
(
exp
)
self
.
assertIsInstance
(
res
,
ccs
.
Literal
)
self
.
assertIsInstance
(
res
,
ccs
.
Literal
)
self
.
assertEqual
(
True
,
res
.
eval
()
)
self
.
assertEqual
(
True
,
res
.
eval
()
)
self
.
assertEqual
(
"
T
rue"
,
res
.
__str__
()
)
self
.
assertEqual
(
"
t
rue"
,
res
.
__str__
()
)
exp
=
"
F
alse"
exp
=
"
f
alse"
res
=
ccs
.
ccs_parser
.
parse
(
exp
)
res
=
ccs
.
ccs_parser
.
parse
(
exp
)
self
.
assertIsInstance
(
res
,
ccs
.
Literal
)
self
.
assertIsInstance
(
res
,
ccs
.
Literal
)
self
.
assertEqual
(
False
,
res
.
eval
()
)
self
.
assertEqual
(
False
,
res
.
eval
()
)
self
.
assertEqual
(
"
F
alse"
,
res
.
__str__
()
)
self
.
assertEqual
(
"
f
alse"
,
res
.
__str__
()
)
def
test_none
(
self
):
def
test_none
(
self
):
exp
=
"
N
one"
exp
=
"
n
one"
res
=
ccs
.
ccs_parser
.
parse
(
exp
)
res
=
ccs
.
ccs_parser
.
parse
(
exp
)
self
.
assertIsInstance
(
res
,
ccs
.
Literal
)
self
.
assertIsInstance
(
res
,
ccs
.
Literal
)
self
.
assertIsNone
(
res
.
eval
()
)
self
.
assertIsNone
(
res
.
eval
()
)
self
.
assertEqual
(
"
N
one"
,
res
.
__str__
()
)
self
.
assertEqual
(
"
n
one"
,
res
.
__str__
()
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
bindings/ruby/lib/cconfigspace/expression.rb
View file @
874b12bf
...
@@ -206,7 +206,9 @@ module CCS
...
@@ -206,7 +206,9 @@ module CCS
def
to_s
def
to_s
case
value
case
value
when
nil
,
String
when
nil
"none"
when
String
value
.
inspect
value
.
inspect
else
else
value
.
to_s
value
.
to_s
...
...
bindings/ruby/lib/cconfigspace/expression_parser.rb
View file @
874b12bf
...
@@ -43,10 +43,12 @@ module CCS
...
@@ -43,10 +43,12 @@ module CCS
rule
(
"]"
)
rule
(
"]"
)
rule
(
","
)
rule
(
","
)
rule
(
:none
=>
/n
il
/
).
as
{
|
b
|
rule
(
:none
=>
/n
one
/
).
as
{
|
b
|
Literal
::
new
(
value:
nil
)
}
Literal
::
new
(
value:
nil
)
}
rule
(
:boolean
=>
/true|false/
).
as
{
|
b
|
rule
(
:btrue
=>
/true/
).
as
{
|
b
|
Literal
::
new
(
value:
eval
(
b
))
}
Literal
::
new
(
value:
true
)
}
rule
(
:bfalse
=>
/false/
).
as
{
|
b
|
Literal
::
new
(
value:
false
)
}
rule
(
:float
=>
/-?[0-9]+([eE][+-]?[0-9]+|\.[0-9]+([eE][+-]?[0-9]+)?)/
).
as
{
|
num
|
rule
(
:float
=>
/-?[0-9]+([eE][+-]?[0-9]+|\.[0-9]+([eE][+-]?[0-9]+)?)/
).
as
{
|
num
|
Literal
::
new
(
value:
Float
(
num
))
}
Literal
::
new
(
value:
Float
(
num
))
}
rule
(
:integer
=>
/-?[0-9]+/
).
as
{
|
num
|
rule
(
:integer
=>
/-?[0-9]+/
).
as
{
|
num
|
...
@@ -58,7 +60,8 @@ module CCS
...
@@ -58,7 +60,8 @@ module CCS
rule
(
:value
)
do
|
r
|
rule
(
:value
)
do
|
r
|
r
[
:none
]
r
[
:none
]
r
[
:boolean
]
r
[
:btrue
]
r
[
:bfalse
]
r
[
:string
]
r
[
:string
]
r
[
:identifier
]
r
[
:identifier
]
r
[
:float
]
r
[
:float
]
...
...
bindings/ruby/test/test_expression_parser.rb
View file @
874b12bf
...
@@ -63,11 +63,11 @@ class CConfigSpaceTestExpressionParser < Minitest::Test
...
@@ -63,11 +63,11 @@ class CConfigSpaceTestExpressionParser < Minitest::Test
def
test_none
def
test_none
m
=
CCS
::
ExpressionParser
.
new
.
method
(
:parse
)
m
=
CCS
::
ExpressionParser
.
new
.
method
(
:parse
)
exp
=
"n
il
"
exp
=
"n
one
"
res
=
m
[
exp
]
res
=
m
[
exp
]
assert
(
res
.
kind_of?
CCS
::
Literal
)
assert
(
res
.
kind_of?
CCS
::
Literal
)
assert_nil
(
res
.
eval
)
assert_nil
(
res
.
eval
)
assert_equal
(
"n
il
"
,
res
.
to_s
)
assert_equal
(
"n
one
"
,
res
.
to_s
)
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment