File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed
src/main/java/io/github/treesitter/jtreesitter Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -31,21 +31,29 @@ public Parser() {
3131 self = ts_parser_new ().reinterpret (arena , TreeSitter ::ts_parser_delete );
3232 }
3333
34- /** Creates a new instance with the given language. */
35- public Parser (Language language ) {
34+ /** Creates a new instance with the given language.
35+ *
36+ * @throws IllegalArgumentException If the language version is not supported.
37+ */
38+ public Parser (Language language ) throws IllegalArgumentException {
3639 this ();
37- ts_parser_set_language (self , language .segment ());
38- this .language = language ;
40+ this .setLanguage (language );
3941 }
4042
4143 /** Get the language that the parser will use for parsing. */
4244 public @ Nullable Language getLanguage () {
4345 return language ;
4446 }
4547
46- /** Set the language that the parser will use for parsing. */
47- public Parser setLanguage (Language language ) {
48- ts_parser_set_language (self , language .segment ());
48+ /**
49+ * Set the language that the parser will use for parsing.
50+ *
51+ * @throws IllegalArgumentException If the language version is not supported.
52+ */
53+ public Parser setLanguage (Language language ) throws IllegalArgumentException {
54+ if (!ts_parser_set_language (self , language .segment ())) {
55+ throw new IllegalArgumentException ("Unsupported Language version (%d)" .formatted (language .getVersion ()));
56+ }
4957 this .language = language ;
5058 return this ;
5159 }
You can’t perform that action at this time.
0 commit comments