Skip to content

Commit

Permalink
update sdk version and fix normalization code
Browse files Browse the repository at this point in the history
Signed-off-by: Denys Smirnov <[email protected]>
  • Loading branch information
Denys Smirnov authored and dennwc committed Mar 19, 2019
1 parent 1612029 commit 3e2bcee
Show file tree
Hide file tree
Showing 54 changed files with 29,183 additions and 12,547 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
language: go

go:
- '1.10'
- '1.11'

services:
- docker

env:
- BBLFSHD_VERSION=v2.9.1
- BBLFSHD_VERSION=v2.11.7

install:
- curl -L https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 > $GOPATH/bin/dep
Expand Down
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[[constraint]]
name = "gopkg.in/bblfsh/sdk.v2"
version = "2.12.x"
version = "2.15.x"

[prune]
go-tests = true
Expand Down
13 changes: 4 additions & 9 deletions driver/fixtures/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,17 @@ var Suite = &fixtures.Suite{
BenchName: "very_long",
Semantic: fixtures.SemanticConfig{
BlacklistTypes: []string{
"unevaluated string (STRING2)",
"string",
"string content",
"backquote shellcommand",
"File reference",
"unevaluated_string2",
"string_content",
"File_reference",
"word",
"variable",
"assignment_word",
"Comment",
"file reference",
"file_reference",
"function-def-element",
},
},
Docker: fixtures.DockerConfig{
Image: "bash:latest",
},
}

func TestBashDriver(t *testing.T) {
Expand Down
62 changes: 45 additions & 17 deletions driver/normalizer/normalizer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package normalizer

import (
. "gopkg.in/bblfsh/sdk.v2/uast/transformer"
"gopkg.in/bblfsh/sdk.v2/uast"
. "gopkg.in/bblfsh/sdk.v2/uast/transformer"
)

var Preprocess = Transformers([][]Transformer{
Expand All @@ -21,14 +21,17 @@ var Normalize = Transformers([][]Transformer{
// Preprocessors is a block of AST preprocessing rules rules.
var Preprocessors = []Mapping{
ObjectToNode{
OffsetKey: "startOffset",
OffsetKey: "startOffset",
EndOffsetKey: "endOffset",
}.Mapping(),
}

func mapString(key string) Mapping {
return MapSemantic(key, uast.String{}, MapObj(
Obj{uast.KeyToken: Var("val")},
Obj{
uast.KeyToken: Var("val"),
"children": Arr(),
},
Obj{
"Value": Var("val"),
"Format": String(""),
Expand All @@ -38,8 +41,13 @@ func mapString(key string) Mapping {

func mapIdentifier(key string) Mapping {
return MapSemantic(key, uast.Identifier{}, MapObj(
Obj{uast.KeyToken: Var("val")},
Obj{"Name": Var("val")},
Obj{
uast.KeyToken: Var("val"),
"children": Arr(),
},
Obj{
"Name": Var("val"),
},
))
}

Expand All @@ -50,19 +58,19 @@ var Normalizers = []Mapping{
"children": Arr(
Obj{
uast.KeyType: Var("_type_namedsymbol"),
uast.KeyPos: Var("_pos_namedsymbol"),
uast.KeyPos: Var("_pos_namedsymbol"),
"children": Arr(
Obj{
uast.KeyType: Var("_type_identifier"),
uast.KeyPos: Var("_pos_identifier"),
"Name": Var("name"),
uast.KeyPos: Var("_pos_identifier"),
"Name": Var("name"),
},
),
},
Obj{
uast.KeyType: Var("_type_groupelem"),
uast.KeyPos: Var("_pos_groupelem"),
"children": Var("body"),
uast.KeyPos: Var("_pos_groupelem"),
"children": Var("body"),
},
),
},
Expand All @@ -73,8 +81,7 @@ var Normalizers = []Mapping{
"Name": Var("name"),
}),
"Node": UASTType(uast.Function{}, Obj{
"Type": UASTType(uast.FunctionType{}, Obj{
}),
"Type": UASTType(uast.FunctionType{}, Obj{}),
"Body": UASTType(uast.Block{}, Obj{
"Statements": Var("body"),
}),
Expand All @@ -84,10 +91,31 @@ var Normalizers = []Mapping{
},
)),

mapString("unevaluated_string2"),
mapString("string"),
mapString("string_content"),
mapString("backquote_shellcommand"),
mapString("string"),

// replace "string" (aka string interpolation) with a single "string_content"
// to a single uast:String node (already replace by previous transform)
Map(
Obj{
uast.KeyType: String("string"),
uast.KeyToken: Any(), // escaped string, don't need it in Semantic mode
uast.KeyPos: Var("pos"), // same as in the child node
"children": One(
Part("inner", Obj{
uast.KeyType: String(uast.TypeOf(uast.String{})),
uast.KeyPos: Any(), // position without quotes; don't need it
}),
),
},
// TODO(dennwc): won't work for reversal
Part("inner", Obj{
uast.KeyType: String(uast.TypeOf(uast.String{})),
uast.KeyPos: Var("pos"), // position without quotes; don't need it
}),
),

mapString("unevaluated_string2"),
mapString("File_reference"),

mapIdentifier("word"),
Expand All @@ -97,18 +125,18 @@ var Normalizers = []Mapping{
MapSemantic("Comment", uast.Comment{}, MapObj(
Obj{
uast.KeyToken: CommentText([2]string{"#", ""}, "comm"),
"children": Arr(),
"children": Arr(),
},
CommentNode(false, "comm", nil),
)),

MapSemantic("file_reference", uast.RuntimeImport{}, MapObj(
Obj{
uast.KeyToken: Var("file"),
"children": Arr(),
},
Obj{
"Path": Var("file"),
},
)),

}
Loading

0 comments on commit 3e2bcee

Please sign in to comment.