Skip to content

Commit

Permalink
feat: Add R support (#332)
Browse files Browse the repository at this point in the history
Updates #1

Signed-off-by: Ian Lewis <ianlewis@google.com>
  • Loading branch information
ianlewis committed Aug 25, 2023
1 parent b9152db commit 2016c43
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for Erlang, SQL, and Haskell programming languages has been added.
- Support for Erlang, Haskell, R, and SQL programming languages has been added.

## [0.4.0] - 2023-08-23

Expand Down
11 changes: 11 additions & 0 deletions internal/scanner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ var (
escapeFunc: backslashEscape,
}

// RConfig is a config for R.
RConfig = Config{
LineCommentStart: []string{"#"},
// NOTE: R has no multi-line comments.
Strings: [][2]string{
{"\"", "\""},
{"'", "'"},
},
escapeFunc: backslashEscape,
}

// RubyConfig is a config for Ruby.
RubyConfig = Config{
LineCommentStart: []string{"#"},
Expand Down
77 changes: 77 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,83 @@ var scannerTestCases = []*struct {
},
},

// R
{
name: "line_comments.r",
src: `# file comment
# TODO is a function
TODO <- function() {
print("Hello World") # Random comment
`,
config: RConfig,
comments: []struct {
text string
line int
}{
{
text: "# file comment",
line: 1,
},
{
text: "# TODO is a function",
line: 3,
},
{
text: "# Random comment",
line: 5,
},
},
},
{
name: "comments_in_string.r",
src: `# file comment
# TODO is a function
TODO <- function() {
print("# Random comment")
print('# Random comment')
`,
config: RConfig,
comments: []struct {
text string
line int
}{
{
text: "# file comment",
line: 1,
},
{
text: "# TODO is a function",
line: 3,
},
},
},
{
name: "escaped_string.r",
src: `# file comment
# TODO is a function
TODO <- function() {
print("\"# Random comment")
print('\'# Random comment')
`,
config: RConfig,
comments: []struct {
text string
line int
}{
{
text: "# file comment",
line: 1,
},
{
text: "# TODO is a function",
line: 3,
},
},
},

// Ruby
{
name: "raw_string.rb",
Expand Down

0 comments on commit 2016c43

Please sign in to comment.