Skip to content

Commit

Permalink
Add support for missing Drivers languages
Browse files Browse the repository at this point in the history
  • Loading branch information
dacharyc committed Oct 17, 2024
1 parent 5e3dd73 commit 7c0ded3
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 10 deletions.
5 changes: 5 additions & 0 deletions integrationTests/snip/expected/sample.snippet.c-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}
6 changes: 6 additions & 0 deletions integrationTests/snip/expected/sample.snippet.go-test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import "fmt"

func main() {
fmt.Println("hello world")
}

3 changes: 3 additions & 0 deletions integrationTests/snip/expected/sample.snippet.php-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
echo "Hello World!";
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("This line will be printed.")
1 change: 1 addition & 0 deletions integrationTests/snip/expected/sample.snippet.ruby-test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "Hello World"
3 changes: 3 additions & 0 deletions integrationTests/snip/expected/sample.snippet.rust-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello World!");
}
5 changes: 5 additions & 0 deletions integrationTests/snip/expected/sample.snippet.sc-test.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Hello {
def main(args: Array[String]) = {
println("Hello, world")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Hello {
def main(args: Array[String]) = {
println("Hello, world")
}
}
8 changes: 8 additions & 0 deletions integrationTests/snip/input/sample.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// :snippet-start: c-test
#include <stdio.h>
int main() {
// printf() displays the string inside quotation // :remove:
printf("Hello, World!");
return 0;
}
// :snippet-end:
11 changes: 11 additions & 0 deletions integrationTests/snip/input/sample.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

// :snippet-start: go-test
import "fmt"

func main() {
// To FMT or LOG, *that* is the question // :remove:
fmt.Println("hello world")
}

// :snippet-end:
6 changes: 6 additions & 0 deletions integrationTests/snip/input/sample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// :snippet-start: php-test
# Sometimes comments start with octothorps :remove:
<?php
echo "Hello World!";
?>
// :snippet-end:
4 changes: 4 additions & 0 deletions integrationTests/snip/input/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# :snippet-start: python-test
# My comment is the coolest, for real. :remove:
print("This line will be printed.")
# :snippet-end:
3 changes: 3 additions & 0 deletions integrationTests/snip/input/sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# :snippet-start: ruby-test
puts "Hello World"
# :snippet-end:
6 changes: 6 additions & 0 deletions integrationTests/snip/input/sample.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// :snippet-start: rust-test
fn main() {
// Print text to the console. This is a boring comment. :remove:
println!("Hello World!");
}
// :snippet-end:
8 changes: 8 additions & 0 deletions integrationTests/snip/input/sample.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// :snippet-start: sc-test
object Hello {
// Arrrrrrrrrrgs! :remove:
def main(args: Array[String]) = {
println("Hello, world")
}
}
// :snippet-end:
8 changes: 8 additions & 0 deletions integrationTests/snip/input/sample.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// :snippet-start: scala-test
object Hello {
// Why do we pass arguments - that sounds confrontational. :remove:
def main(args: Array[String]) = {
println("Hello, world")
}
}
// :snippet-end:
9 changes: 9 additions & 0 deletions src/bluehawk/actions/snip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,24 @@ export const formatInRst = async (
// nasty hack to cover the suffixes/rst languages we use most often
// TODO: switch to a better mapping
const rstLanguageMap: Map<string, string> = new Map([
[".c", "c"],
[".cpp", "cpp"],
[".cs", "csharp"],
[".go", "golang"],
[".gradle", "groovy"],
[".ipynb", "python"],
[".java", "java"],
[".js", "javascript"],
[".jsx", "javascript"],
[".json", "json"],
[".kt", "kotlin"],
[".m", "objectivec"],
[".php", "php"],
[".py", "python"],
[".rb", "ruby"],
[".rs", "rust"],
[".sc", "scala"],
[".scala", "scala"],
[".swift", "swift"],
[".ts", "typescript"],
[".tsx", "typescript"],
Expand Down
44 changes: 34 additions & 10 deletions src/bluehawk/getBluehawk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,27 @@ export const getBluehawk = async (): Promise<Bluehawk> => {
".c",
".cpp",
".cs",
".dart",
".go",
".gradle",
".groovy",
".gsh",
".gvy",
".gy",
".h",
".hpp",
".kt",
".java",
".js",
".dart",
".jsx",
".kt",
".m",
".mm",
".rs",
".sc",
".scala",
".swift",
".ts",
".tsx",
".gradle",
".groovy",
".gvy",
".gy",
".gsh",
".go",
],
{
languageId: "C-like",
Expand All @@ -78,8 +81,18 @@ export const getBluehawk = async (): Promise<Bluehawk> => {
}
);

// Add all supported extensions here.
bluehawk.addLanguage([".py"], {
bluehawk.addLanguage([".php"], {
languageId: "PHP",
lineComments: [/# ?/],
stringLiterals: [
{
pattern: tokens.PYTHON_STRING_LITERAL_PATTERN,
multiline: true,
},
],
});

bluehawk.addLanguage([".py", ".ipynb"], {
languageId: "Python",
lineComments: [/# ?/],
stringLiterals: [
Expand All @@ -90,6 +103,17 @@ export const getBluehawk = async (): Promise<Bluehawk> => {
],
});

bluehawk.addLanguage([".rb"], {
languageId: "Ruby",
lineComments: [/# ?/],
stringLiterals: [
{
pattern: tokens.PYTHON_STRING_LITERAL_PATTERN,
multiline: true,
},
],
});

bluehawk.addLanguage(["", ".txt", ".rst", ".md", ".json"], {
languageId: "text",
});
Expand Down

0 comments on commit 7c0ded3

Please sign in to comment.