add smali language support

pull/634/head
Evan Richter 2024-02-01 15:41:14 +07:00
parent 6ae210999c
commit d106c979ee
10 changed files with 86 additions and 1 deletions

@ -311,6 +311,11 @@ fn main() {
src_dir: "vendored_parsers/tree-sitter-scss-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-smali",
src_dir: "vendored_parsers/tree-sitter-smali-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-sql",
src_dir: "vendored_parsers/tree-sitter-sql-src",

@ -47,6 +47,7 @@ with `difft --list-languages`.
| Ruby | [tree-sitter/tree-sitter-ruby](https://github.com/tree-sitter/tree-sitter-ruby) |
| Rust | [tree-sitter/tree-sitter-rust](https://github.com/tree-sitter/tree-sitter-rust) |
| Scala | [tree-sitter/tree-sitter-scala](https://github.com/tree-sitter/tree-sitter-scala) |
| Smali | [amaanq/tree-sitter-smali](https://github.com/amaanq/tree-sitter-smali) |
| Solidity | [JoranHonig/tree-sitter-solidity](https://github.com/JoranHonig/tree-sitter-solidity) |
| SQL | [m-novikov/tree-sitter-sql](https://github.com/m-novikov/tree-sitter-sql) |
| Swift | [alex-pinkus/tree-sitter-swift](https://github.com/alex-pinkus/tree-sitter-swift) |

@ -76,6 +76,9 @@ sample_files/haskell_before.hs sample_files/haskell_after.hs
sample_files/hcl_before.hcl sample_files/hcl_after.hcl
52e271ea8ffbe500d6bc3c47d35df13a -
sample_files/hello_world_before.smali sample_files/hello_world_after.smali
c2a686a9d70b8e54d49ef7fdf2f87fb7 -
sample_files/helpful-unit-test-before.el sample_files/helpful-unit-test-after.el
f85460a4e60d77b4cae1a987a5af4c49 -

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Run difftastic on all the sample files, so we can see if any output
# has been changed.

@ -0,0 +1,29 @@
.class public LHelloPerson;
#Ye olde hello world application
#To assemble and run this on a phone or emulator:
#
#java -jar smali.jar a -o classes.dex HelloWorld.smali
#zip HelloWorld.zip classes.dex
#adb push HelloWorld.zip /data/local
#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
#
#if you get out of memory type errors when running smali.jar, try
#java -Xmx512m -jar smali.jar HelloWorld.smali
#instead
.super Ljava/lang/Object;
.method public static main([Ljava/lang/String;)V
.registers 3
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v1, "Hello %s!"
const-string v2, "Evan"
invoke-virtual {v0, v1, v2}, Ljava/io/PrintStream;->printf(Ljava/lang/String;Ljava/lang/String;)V
return-void
.end method

@ -0,0 +1,27 @@
.class public LHelloWorld;
#Ye olde hello world application
#To assemble and run this on a phone or emulator:
#
#java -jar smali.jar a -o classes.dex HelloWorld.smali
#zip HelloWorld.zip classes.dex
#adb push HelloWorld.zip /data/local
#adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
#
#if you get out of memory type errors when running smali.jar, try
#java -Xmx512m -jar smali.jar HelloWorld.smali
#instead
.super Ljava/lang/Object;
.method public static main([Ljava/lang/String;)V
.registers 2
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v1, "Hello World!"
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
return-void
.end method

@ -67,6 +67,7 @@ pub(crate) enum Language {
Rust,
Scala,
Scss,
Smali,
Solidity,
Sql,
Swift,
@ -155,6 +156,7 @@ pub(crate) fn language_name(language: Language) -> &'static str {
Ruby => "Ruby",
Rust => "Rust",
Scala => "Scala",
Smali => "Smali",
Scss => "SCSS",
Solidity => "Solidity",
Sql => "SQL",
@ -341,6 +343,7 @@ pub(crate) fn language_globs(language: Language) -> Vec<glob::Pattern> {
],
Rust => &["*.rs"],
Scala => &["*.scala", "*.sbt", "*.sc"],
Smali => &["*.smali"],
Scss => &["*.scss"],
Solidity => &["*.sol"],
Sql => &["*.sql", "*.pgsql"],

@ -107,6 +107,7 @@ extern "C" {
fn tree_sitter_ruby() -> ts::Language;
fn tree_sitter_rust() -> ts::Language;
fn tree_sitter_scala() -> ts::Language;
fn tree_sitter_smali() -> ts::Language;
fn tree_sitter_scss() -> ts::Language;
fn tree_sitter_solidity() -> ts::Language;
fn tree_sitter_sql() -> ts::Language;
@ -978,6 +979,20 @@ pub(crate) fn from_language(language: guess::Language) -> TreeSitterConfig {
sub_languages: vec![],
}
}
Smali => {
let language = unsafe { tree_sitter_smali() };
TreeSitterConfig {
language,
atom_nodes: HashSet::from(["string"]),
delimiter_tokens: Vec::new(),
highlight_query: ts::Query::new(
language,
include_str!("../../vendored_parsers/highlights/smali.scm"),
)
.unwrap(),
sub_languages: Vec::new(),
}
}
Solidity => {
let language = unsafe { tree_sitter_solidity() };
TreeSitterConfig {

@ -0,0 +1 @@
../tree-sitter-smali/queries/highlights.scm

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