Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Remove leading # from comments
Browse files Browse the repository at this point in the history
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
  • Loading branch information
Juanjo Alvarez committed Mar 8, 2018
1 parent 436f85c commit bf2fde6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 17 additions & 7 deletions driver/normalizer/tonode.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package normalizer

import "gopkg.in/bblfsh/sdk.v1/uast"
import (
"strings"

"gopkg.in/bblfsh/sdk.v1/uast"
)

// ToNode is an instance of `uast.ObjectToNode`, defining how to transform an
// into a UAST (`uast.Node`).
Expand Down Expand Up @@ -35,12 +39,18 @@ var ToNode = &uast.ObjectToNode{

// Native parser wrongly set positions at individual lines in multiline
// strings at 0, remove the position on those to avoid confusion
if t, ok := n["type"].(string); ok && t == "str" {
if endCol, ok := n["end_col"].(float64); ok && endCol == 0 {
delete(n, "start_col")
delete(n, "end_col")
delete(n, "start_line")
delete(n, "end_line")
if t, ok := n["type"].(string); ok {
if t == "str" {
if endCol, ok := n["end_col"].(float64); ok && endCol == 0 {
delete(n, "start_col")
delete(n, "end_col")
delete(n, "start_line")
delete(n, "end_line")
}
} else if t == "comment" {
if text, ok := n["text"].(string); ok && strings.HasPrefix(text, "#") {
n["text"] = text[1:]
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions fixtures/comments.rb.uast
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ UAST:
. . . . . . documentation: false
. . . . . . inline: true
. . . . . . internalRole: comments
. . . . . . text: # previous
. . . . . . text: previous
. . . . . }
. . . . }
. . . . 1: comment {
Expand All @@ -57,7 +57,7 @@ UAST:
. . . . . . documentation: false
. . . . . . inline: true
. . . . . . internalRole: comments
. . . . . . text: # inline
. . . . . . text: inline
. . . . . }
. . . . }
. . . . 2: comment {
Expand All @@ -76,7 +76,7 @@ UAST:
. . . . . . documentation: false
. . . . . . inline: true
. . . . . . internalRole: comments
. . . . . . text: # after
. . . . . . text: after
. . . . . }
. . . . }
. . . . 3: int {
Expand Down

0 comments on commit bf2fde6

Please sign in to comment.