feat: Add perl support

Signed-off-by: Xuanwo <github@xuanwo.io>
pull/263/head
Xuanwo 2022-04-22 10:14:19 +07:00
parent 79ee12013c
commit b85f996ff0
No known key found for this signature in database
GPG Key ID: C423B4FA6B48E945
9 changed files with 94 additions and 4 deletions

@ -36,7 +36,10 @@ impl TreeSitterParser {
.cpp(true)
.flag_if_supported("-Wno-implicit-fallthrough")
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-ignored-qualifiers");
.flag_if_supported("-Wno-ignored-qualifiers")
// Workaround for: https://github.com/ganezdragon/tree-sitter-perl/issues/16
// should be removed after fixed.
.flag_if_supported("-Wno-return-type");
if cfg!(windows) {
cpp_build.flag("/std:c++14");
@ -174,6 +177,11 @@ fn main() {
src_dir: "vendor/tree-sitter-php-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-perl",
src_dir: "vendor/tree-sitter-perl-src",
extra_files: vec!["scanner.cc"],
},
TreeSitterParser {
name: "tree-sitter-python",
src_dir: "vendor/tree-sitter-python-src",

@ -106,6 +106,9 @@ sample_files/ocaml_before.ml sample_files/ocaml_after.ml
sample_files/outer_delimiter_before.el sample_files/outer_delimiter_after.el
73130b8572a4f17fa6cf828f74e226ce -
sample_files/perl_before.pl sample_files/perl_after.pl
9f4da9c44da143c236b4e0899d199f0d -
sample_files/preprocesor_before.h sample_files/preprocesor_after.h
3e4331cb935cbe735a79ebc43786cd3a -

@ -0,0 +1,38 @@
use strict 'refs';
use warnings;
use if $] < 5.008, "utf8";
use if WANT_WARNINGS, warnings => qw(all);
use constant PI => 4 * atan2(1, 1);
use constant DEBUG , 0; # comma (,) is also used instead of '=>'
print "Pi equals ", PI, "...\n";
use constant {
SEC => 0,
MIN => 1,
HOUR => 2,
MDAY => 3,
MON => 4,
YEAR => 5,
WDAY => 6,
YDAY => 7,
ISDST => 10,
};
my $setting = {
open => 1,
close => 2,
run => 3,
awesome => 'yes',
};
my %final;
foreach my $key (woof()) {
$final{IRONMAN}{$key} = $setting->{$key};
print Dumper \%final;
}
use constant WEEKDAYS => qw(
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
);

@ -0,0 +1,25 @@
use strict 'refs';
use warnings;
use if $] < 5.008, "utf8";
use if WANT_WARNINGS, warnings => qw(all);
use constant PI => 4 * atan2(1, 1);
use constant DEBUG , 0; # comma (,) is also used instead of '=>'
print "Pi equals ", PI, "...\n";
use constant {
SEC => 0,
MIN => 1,
HOUR => 2,
MDAY => 3,
MON => 4,
YEAR => 5,
WDAY => 6,
YDAY => 7,
ISDST => 8,
};
use constant WEEKDAYS => qw(
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
);

@ -43,6 +43,7 @@ pub enum Language {
OCaml,
OCamlInterface,
Php,
Perl,
Python,
Ruby,
Rust,
@ -112,6 +113,7 @@ fn from_emacs_mode_header(src: &str) -> Option<Language> {
"java" => Some(Java),
"js" | "js2" => Some(JavaScript),
"lisp" => Some(CommonLisp),
"perl" => Some(Perl),
"python" => Some(Python),
"rjsx" => Some(Jsx),
"ruby" => Some(Ruby),
@ -153,6 +155,7 @@ fn from_shebang(src: &str) -> Option<Language> {
"chakra" | "d8" | "gjs" | "js" | "node" | "nodejs" | "qjs" | "rhino" | "v8"
| "v8-shell" => return Some(JavaScript),
"ocaml" | "ocamlrun" | "ocamlscript" => return Some(OCaml),
"perl" => return Some(Perl),
"python" | "python2" | "python3" => return Some(Python),
"ruby" | "macruby" | "rake" | "jruby" | "rbx" => return Some(Ruby),
"deno" | "ts-node" => return Some(TypeScript),
@ -220,6 +223,7 @@ pub fn from_extension(extension: &OsStr) -> Option<Language> {
"ml" => Some(OCaml),
"mli" => Some(OCamlInterface),
"php" => Some(Php),
"pm" | "pl" => Some(Perl),
"py" | "py3" | "pyi" | "bzl" => Some(Python),
"rb" | "builder" | "spec" | "rake" => Some(Ruby),
"rs" => Some(Rust),

@ -61,8 +61,8 @@ fn prefer_outer_delimiter(language: guess_language::Language) -> bool {
// languages have syntax like `foo(bar)` or `foo[bar]` where
// the inner delimiter is more relevant.
Bash | C | CPlusPlus | CSharp | Css | Dart | Elixir | Elm | Gleam | Go | Haskell | Java
| JavaScript | Jsx | Kotlin | Lua | Nix | OCaml | OCamlInterface | Php | Python | Ruby
| Rust | Scala | Tsx | TypeScript | Yaml | Zig => false,
| JavaScript | Jsx | Kotlin | Lua | Nix | OCaml | OCamlInterface | Perl | Php | Python
| Ruby | Rust | Scala | Tsx | TypeScript | Yaml | Zig => false,
}
}

@ -67,6 +67,7 @@ extern "C" {
fn tree_sitter_ocaml() -> ts::Language;
fn tree_sitter_ocaml_interface() -> ts::Language;
fn tree_sitter_php() -> ts::Language;
fn tree_sitter_perl() -> ts::Language;
fn tree_sitter_python() -> ts::Language;
fn tree_sitter_ruby() -> ts::Language;
fn tree_sitter_rust() -> ts::Language;
@ -473,6 +474,16 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
.unwrap(),
}
}
Perl => {
let language = unsafe { tree_sitter_perl() };
TreeSitterConfig {
name: "Perl",
language,
atom_nodes: vec!["string"].into_iter().collect(),
delimiter_tokens: vec![("(", ")"), ("{", "}"), ("[", "]")],
highlight_query: ts::Query::new(language, "").unwrap(),
}
}
Python => {
let language = unsafe { tree_sitter_python() };
TreeSitterConfig {

@ -0,0 +1 @@
tree-sitter-perl/src