Skip to content

Commit

Permalink
Make language loading mechanism tolerant of hyphens in language names
Browse files Browse the repository at this point in the history
  • Loading branch information
ubolonton committed Dec 15, 2020
1 parent 43fc289 commit abfda62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
- Improved language loading mechanism's tolerance of hyphens in language names.

## [0.12.1] - 2020-11-04
- Fixed incorrect parsing when after-change's start position is not the same as before-change's start position. For example, this happens when calling `upcase-region` on a region whose first character is already upcased.
Expand Down
23 changes: 18 additions & 5 deletions lisp/tree-sitter-load.el
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
;;; Code:

(require 'map)
(require 'seq)

(require 'tsc)
(require 'tree-sitter-cli)
Expand Down Expand Up @@ -51,13 +52,25 @@ If FILE is nil, the base name is assumed to be LANG-SYMBOL's name.
If NATIVE-SYMBOL-NAME is nil, the name of the exported native symbol is assumed
to be LANG-SYMBOL's name, prefixed with \"tree_sitter_\"."
(let* ((lang-name (symbol-name lang-symbol))
;; Example: c-sharp -> c_sharp.
(fallback-name (replace-regexp-in-string "-" "_" lang-name))
(native-symbol-name (or native-symbol-name
(format "tree_sitter_%s"
;; Example: c-sharp
(replace-regexp-in-string "-" "_" lang-name))))
(full-path (locate-file (or file lang-name)
tree-sitter-load-path
tree-sitter-load-suffixes)))
fallback-name)))
;; List of base file names to search for.
(files (if file
;; Use only FILE, if it's given.
(list file)
;; Otherwise use LANG-SYMBOL. First, as-is. Then, with hyphens
;; replaced by underscores.
(cons lang-name
(unless (string= lang-name fallback-name)
(list fallback-name)))))
(full-path (seq-some (lambda (base-name)
(locate-file base-name
tree-sitter-load-path
tree-sitter-load-suffixes))
files)))
(unless full-path
;; TODO: Define custom error class.
(error "Cannot find shared library for language: %S" lang-symbol))
Expand Down

0 comments on commit abfda62

Please sign in to comment.