Skip to content

Commit 3e2bcee

Browse files
Denys Smirnovdennwc
authored andcommitted
update sdk version and fix normalization code
Signed-off-by: Denys Smirnov <[email protected]>
1 parent 1612029 commit 3e2bcee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+29183
-12547
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
language: go
22

33
go:
4-
- '1.10'
4+
- '1.11'
55

66
services:
77
- docker
88

99
env:
10-
- BBLFSHD_VERSION=v2.9.1
10+
- BBLFSHD_VERSION=v2.11.7
1111

1212
install:
1313
- curl -L https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 > $GOPATH/bin/dep

Gopkg.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[[constraint]]
55
name = "gopkg.in/bblfsh/sdk.v2"
6-
version = "2.12.x"
6+
version = "2.15.x"
77

88
[prune]
99
go-tests = true

driver/fixtures/fixtures_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,17 @@ var Suite = &fixtures.Suite{
2525
BenchName: "very_long",
2626
Semantic: fixtures.SemanticConfig{
2727
BlacklistTypes: []string{
28-
"unevaluated string (STRING2)",
29-
"string",
30-
"string content",
31-
"backquote shellcommand",
32-
"File reference",
28+
"unevaluated_string2",
29+
"string_content",
30+
"File_reference",
3331
"word",
3432
"variable",
3533
"assignment_word",
3634
"Comment",
37-
"file reference",
35+
"file_reference",
3836
"function-def-element",
3937
},
4038
},
41-
Docker: fixtures.DockerConfig{
42-
Image: "bash:latest",
43-
},
4439
}
4540

4641
func TestBashDriver(t *testing.T) {

driver/normalizer/normalizer.go

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package normalizer
22

33
import (
4-
. "gopkg.in/bblfsh/sdk.v2/uast/transformer"
54
"gopkg.in/bblfsh/sdk.v2/uast"
5+
. "gopkg.in/bblfsh/sdk.v2/uast/transformer"
66
)
77

88
var Preprocess = Transformers([][]Transformer{
@@ -21,14 +21,17 @@ var Normalize = Transformers([][]Transformer{
2121
// Preprocessors is a block of AST preprocessing rules rules.
2222
var Preprocessors = []Mapping{
2323
ObjectToNode{
24-
OffsetKey: "startOffset",
24+
OffsetKey: "startOffset",
2525
EndOffsetKey: "endOffset",
2626
}.Mapping(),
2727
}
2828

2929
func mapString(key string) Mapping {
3030
return MapSemantic(key, uast.String{}, MapObj(
31-
Obj{uast.KeyToken: Var("val")},
31+
Obj{
32+
uast.KeyToken: Var("val"),
33+
"children": Arr(),
34+
},
3235
Obj{
3336
"Value": Var("val"),
3437
"Format": String(""),
@@ -38,8 +41,13 @@ func mapString(key string) Mapping {
3841

3942
func mapIdentifier(key string) Mapping {
4043
return MapSemantic(key, uast.Identifier{}, MapObj(
41-
Obj{uast.KeyToken: Var("val")},
42-
Obj{"Name": Var("val")},
44+
Obj{
45+
uast.KeyToken: Var("val"),
46+
"children": Arr(),
47+
},
48+
Obj{
49+
"Name": Var("val"),
50+
},
4351
))
4452
}
4553

@@ -50,19 +58,19 @@ var Normalizers = []Mapping{
5058
"children": Arr(
5159
Obj{
5260
uast.KeyType: Var("_type_namedsymbol"),
53-
uast.KeyPos: Var("_pos_namedsymbol"),
61+
uast.KeyPos: Var("_pos_namedsymbol"),
5462
"children": Arr(
5563
Obj{
5664
uast.KeyType: Var("_type_identifier"),
57-
uast.KeyPos: Var("_pos_identifier"),
58-
"Name": Var("name"),
65+
uast.KeyPos: Var("_pos_identifier"),
66+
"Name": Var("name"),
5967
},
6068
),
6169
},
6270
Obj{
6371
uast.KeyType: Var("_type_groupelem"),
64-
uast.KeyPos: Var("_pos_groupelem"),
65-
"children": Var("body"),
72+
uast.KeyPos: Var("_pos_groupelem"),
73+
"children": Var("body"),
6674
},
6775
),
6876
},
@@ -73,8 +81,7 @@ var Normalizers = []Mapping{
7381
"Name": Var("name"),
7482
}),
7583
"Node": UASTType(uast.Function{}, Obj{
76-
"Type": UASTType(uast.FunctionType{}, Obj{
77-
}),
84+
"Type": UASTType(uast.FunctionType{}, Obj{}),
7885
"Body": UASTType(uast.Block{}, Obj{
7986
"Statements": Var("body"),
8087
}),
@@ -84,10 +91,31 @@ var Normalizers = []Mapping{
8491
},
8592
)),
8693

87-
mapString("unevaluated_string2"),
88-
mapString("string"),
8994
mapString("string_content"),
90-
mapString("backquote_shellcommand"),
95+
mapString("string"),
96+
97+
// replace "string" (aka string interpolation) with a single "string_content"
98+
// to a single uast:String node (already replace by previous transform)
99+
Map(
100+
Obj{
101+
uast.KeyType: String("string"),
102+
uast.KeyToken: Any(), // escaped string, don't need it in Semantic mode
103+
uast.KeyPos: Var("pos"), // same as in the child node
104+
"children": One(
105+
Part("inner", Obj{
106+
uast.KeyType: String(uast.TypeOf(uast.String{})),
107+
uast.KeyPos: Any(), // position without quotes; don't need it
108+
}),
109+
),
110+
},
111+
// TODO(dennwc): won't work for reversal
112+
Part("inner", Obj{
113+
uast.KeyType: String(uast.TypeOf(uast.String{})),
114+
uast.KeyPos: Var("pos"), // position without quotes; don't need it
115+
}),
116+
),
117+
118+
mapString("unevaluated_string2"),
91119
mapString("File_reference"),
92120

93121
mapIdentifier("word"),
@@ -97,18 +125,18 @@ var Normalizers = []Mapping{
97125
MapSemantic("Comment", uast.Comment{}, MapObj(
98126
Obj{
99127
uast.KeyToken: CommentText([2]string{"#", ""}, "comm"),
100-
"children": Arr(),
128+
"children": Arr(),
101129
},
102130
CommentNode(false, "comm", nil),
103131
)),
104132

105133
MapSemantic("file_reference", uast.RuntimeImport{}, MapObj(
106134
Obj{
107135
uast.KeyToken: Var("file"),
136+
"children": Arr(),
108137
},
109138
Obj{
110139
"Path": Var("file"),
111140
},
112141
)),
113-
114142
}

0 commit comments

Comments
 (0)