Skip to content

Commit 1612029

Browse files
authored
Merge pull request #52 from juanjux/comments
Comments fixes + SDK update
2 parents 948e68e + 683655c commit 1612029

20 files changed

+929
-29547
lines changed

Gopkg.lock

+57-133
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

driver/fixtures/fixtures_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var Suite = &fixtures.Suite{
3333
"word",
3434
"variable",
3535
"assignment_word",
36-
"comment",
36+
"Comment",
3737
"file reference",
3838
"function-def-element",
3939
},

driver/normalizer/annotation.go

+3-20
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55
"gopkg.in/bblfsh/sdk.v2/uast/role"
66
. "gopkg.in/bblfsh/sdk.v2/uast/transformer"
77
"gopkg.in/bblfsh/sdk.v2/uast/transformer/positioner"
8-
9-
"strings"
108
)
119

1210
var Native = Transformers([][]Transformer{
@@ -18,33 +16,19 @@ var Code = []CodeTransformer{
1816
positioner.NewFillLineColFromOffset(),
1917
}
2018

19+
var PreprocessCode = []CodeTransformer{}
20+
2121
func annotateTypeToken(typ, token string, roles ...role.Role) Mapping {
2222
return AnnotateType(typ,
2323
FieldRoles{
2424
uast.KeyToken: {Op: String(token)},
2525
}, roles...)
2626
}
2727

28-
func uncomment_bash(s string) (string, error) {
29-
if strings.HasPrefix(s, "#") {
30-
s = s[1:]
31-
}
32-
return s, nil
33-
}
34-
35-
func comment_bash(s string) (string, error) {
36-
return "#" + s, nil
37-
}
38-
39-
func UncommentBashLike(vr string) Op {
40-
return StringConv(Var(vr), uncomment_bash, comment_bash)
41-
}
42-
43-
4428
var Annotations = []Mapping{
4529
AnnotateType("FILE", nil, role.File),
4630
AnnotateType("Comment", MapObj(Obj{
47-
uast.KeyToken: UncommentBashLike("text"),
31+
uast.KeyToken: Var("text"),
4832
}, Obj{
4933
uast.KeyToken: Var("text"),
5034
}), role.Comment, role.Noop),
@@ -253,5 +237,4 @@ var Annotations = []Mapping{
253237
ObjectRoles("condition", role.While, role.Expression, role.Condition),
254238
ObjectRoles("body", role.While, role.Body, role.Block)),
255239
}), role.While, role.Statement),
256-
257240
}

driver/normalizer/normalizer.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ var Normalizers = []Mapping{
9494
mapIdentifier("variable"),
9595
mapIdentifier("assignment_word"),
9696

97-
MapSemantic("comment", uast.Comment{}, MapObj(
97+
MapSemantic("Comment", uast.Comment{}, MapObj(
9898
Obj{
99-
uast.KeyToken: CommentText([2]string{"#", "\n"}, "comm"),
99+
uast.KeyToken: CommentText([2]string{"#", ""}, "comm"),
100+
"children": Arr(),
100101
},
101102
CommentNode(false, "comm", nil),
102103
)),

driver/normalizer/transforms.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package normalizer
33
import "gopkg.in/bblfsh/sdk.v2/driver"
44

55
var Transforms = driver.Transforms{
6-
Namespace: "bash",
7-
Preprocess: Preprocess,
8-
Normalize: Normalize,
9-
Annotations: Native,
10-
Code: Code,
6+
Namespace: "bash",
7+
Preprocess: Preprocess,
8+
PreprocessCode: PreprocessCode,
9+
Normalize: Normalize,
10+
Annotations: Native,
11+
Code: Code,
1112
}

fixtures/bench_binary_search.bash.sem.uast

+6-4
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,7 @@
909909
},
910910
children: [],
911911
},
912-
{ '@type': "bash:Comment",
913-
'@token': "\techo \"$left\t$mid(${array[$mid]})\t$right\"",
914-
'@role': [Comment, Noop],
912+
{ '@type': "uast:Comment",
915913
'@pos': { '@type': "uast:Positions",
916914
start: { '@type': "uast:Position",
917915
offset: 92,
@@ -924,7 +922,11 @@
924922
col: 43,
925923
},
926924
},
927-
children: [],
925+
Block: false,
926+
Prefix: "\t",
927+
Suffix: "",
928+
Tab: "",
929+
Text: "echo \"$left\t$mid(${array[$mid]})\t$right\"",
928930
},
929931
{ '@type': "bash:if_shellcommand",
930932
'@role': [If, Statement],

fixtures/bench_binary_search.bash.uast

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@
923923
children: [],
924924
},
925925
{ '@type': "Comment",
926-
'@token': "\techo \"$left\t$mid(${array[$mid]})\t$right\"",
926+
'@token': "#\techo \"$left\t$mid(${array[$mid]})\t$right\"",
927927
'@role': [Comment, Noop],
928928
'@pos': { '@type': "uast:Positions",
929929
start: { '@type': "uast:Position",

fixtures/bench_ethopian_multiplication.bash.sem.uast

+6-4
Original file line numberDiff line numberDiff line change
@@ -1829,9 +1829,7 @@
18291829
},
18301830
],
18311831
},
1832-
{ '@type': "bash:Comment",
1833-
'@token': " => 578",
1834-
'@role': [Comment, Noop],
1832+
{ '@type': "uast:Comment",
18351833
'@pos': { '@type': "uast:Positions",
18361834
start: { '@type': "uast:Position",
18371835
offset: 344,
@@ -1844,7 +1842,11 @@
18441842
col: 9,
18451843
},
18461844
},
1847-
children: [],
1845+
Block: false,
1846+
Prefix: " ",
1847+
Suffix: "",
1848+
Tab: "",
1849+
Text: "=> 578",
18481850
},
18491851
],
18501852
}

fixtures/bench_ethopian_multiplication.bash.uast

+1-1
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,7 @@
27472747
],
27482748
},
27492749
{ '@type': "Comment",
2750-
'@token': " => 578",
2750+
'@token': "# => 578",
27512751
'@role': [Comment, Noop],
27522752
'@pos': { '@type': "uast:Positions",
27532753
start: { '@type': "uast:Position",

fixtures/bench_gcd.bash.sem.uast

+24-16
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
Node: { '@type': "uast:Function",
3535
Body: { '@type': "uast:Block",
3636
Statements: [
37-
{ '@type': "bash:Comment",
38-
'@token': " Calculate $1 % $2 until $2 becomes zero.",
39-
'@role': [Comment, Noop],
37+
{ '@type': "uast:Comment",
4038
'@pos': { '@type': "uast:Positions",
4139
start: { '@type': "uast:Position",
4240
offset: 9,
@@ -49,7 +47,11 @@
4947
col: 44,
5048
},
5149
},
52-
children: [],
50+
Block: false,
51+
Prefix: " ",
52+
Suffix: "",
53+
Tab: "",
54+
Text: "Calculate $1 % $2 until $2 becomes zero.",
5355
},
5456
{ '@type': "bash:until_loop",
5557
'@role': [Incomplete, Statement, While],
@@ -229,9 +231,7 @@
229231
},
230232
},
231233
children: [
232-
{ '@type': "bash:Comment",
233-
'@token': " Parallel assignment: set -- 1 2",
234-
'@role': [Comment, Noop],
234+
{ '@type': "uast:Comment",
235235
'@pos': { '@type': "uast:Positions",
236236
start: { '@type': "uast:Position",
237237
offset: 81,
@@ -244,7 +244,11 @@
244244
col: 36,
245245
},
246246
},
247-
children: [],
247+
Block: false,
248+
Prefix: " ",
249+
Suffix: "",
250+
Tab: "",
251+
Text: "Parallel assignment: set -- 1 2",
248252
},
249253
{ '@type': "bash:simple-command",
250254
'@role': [Expression],
@@ -380,9 +384,7 @@
380384
},
381385
],
382386
},
383-
{ '@type': "bash:Comment",
384-
'@token': " Echo absolute value of $1.",
385-
'@role': [Comment, Noop],
387+
{ '@type': "uast:Comment",
386388
'@pos': { '@type': "uast:Positions",
387389
start: { '@type': "uast:Position",
388390
offset: 159,
@@ -395,7 +397,11 @@
395397
col: 30,
396398
},
397399
},
398-
children: [],
400+
Block: false,
401+
Prefix: " ",
402+
Suffix: "",
403+
Tab: "",
404+
Text: "Echo absolute value of $1.",
399405
},
400406
{ '@type': "bash:simple-command",
401407
'@role': [Expression],
@@ -900,9 +906,7 @@
900906
},
901907
],
902908
},
903-
{ '@type': "bash:Comment",
904-
'@token': " => 987",
905-
'@role': [Comment, Noop],
909+
{ '@type': "uast:Comment",
906910
'@pos': { '@type': "uast:Positions",
907911
start: { '@type': "uast:Position",
908912
offset: 265,
@@ -915,7 +919,11 @@
915919
col: 9,
916920
},
917921
},
918-
children: [],
922+
Block: false,
923+
Prefix: " ",
924+
Suffix: "",
925+
Tab: "",
926+
Text: "=> 987",
919927
},
920928
],
921929
}

fixtures/bench_gcd.bash.uast

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
children: [
8080
{ '@type': "Comment",
81-
'@token': " Calculate $1 % $2 until $2 becomes zero.",
81+
'@token': "# Calculate $1 % $2 until $2 becomes zero.",
8282
'@role': [Comment, Noop],
8383
'@pos': { '@type': "uast:Positions",
8484
start: { '@type': "uast:Position",
@@ -313,7 +313,7 @@
313313
},
314314
children: [
315315
{ '@type': "Comment",
316-
'@token': " Parallel assignment: set -- 1 2",
316+
'@token': "# Parallel assignment: set -- 1 2",
317317
'@role': [Comment, Noop],
318318
'@pos': { '@type': "uast:Positions",
319319
start: { '@type': "uast:Position",
@@ -764,7 +764,7 @@
764764
],
765765
},
766766
{ '@type': "Comment",
767-
'@token': " Echo absolute value of $1.",
767+
'@token': "# Echo absolute value of $1.",
768768
'@role': [Comment, Noop],
769769
'@pos': { '@type': "uast:Positions",
770770
start: { '@type': "uast:Position",
@@ -1606,7 +1606,7 @@
16061606
],
16071607
},
16081608
{ '@type': "Comment",
1609-
'@token': " => 987",
1609+
'@token': "# => 987",
16101610
'@role': [Comment, Noop],
16111611
'@pos': { '@type': "uast:Positions",
16121612
start: { '@type': "uast:Position",

0 commit comments

Comments
 (0)