### Basic Java Usage Example Source: https://github.com/bonede/tree-sitter-ng/blob/main/README.md Demonstrates initializing a TSParser, setting a language (JSON in this case), and parsing a simple JSON string to access its root node and children. ```java // imports are omitted class Main { public static void main(String[] args) { TSParser parser = new TSParser(); // Use `TSLanguage.load` instead if you would like to load parsers as shared object(.so, .dylib, or .dll). // TSLanguage.load("path/to/languane/shared/object", "tree_sitter_some_lang"); TSLanguage json = new TreeSitterJson(); parser.setLanguage(json); TSTree tree = parser.parseString(null, "[1, null]"); TSNode rootNode = tree.getRootNode(); TSNode arrayNode = rootNode.getNamedChild(0); TSNode numberNode = arrayNode.getNamedChild(0); } } ``` -------------------------------- ### Scala Given Instance Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Provides examples of Scala 3 given instance definitions, including simple assignments and trait implementations. ```scala object A: given a: A = x given intFoo: CanFoo[Int] with def foo(x: Int): Int = 0 given CanFoo[Int] with def foo(x: Int): Int = 0 ``` -------------------------------- ### Case Object with Derivation in Scala Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Example of a case object that extends another type and derives traits. ```scala case object A extends B derives C, D {} ``` -------------------------------- ### Deprecated Class Annotation Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt Demonstrates how to use the @deprecated annotation on a class. Use the replacement 'D' starting from version '1.0'. ```Scala @deprecated("Use D", "1.0") class C {} ``` -------------------------------- ### Scala 3 Class Definition with Derivation Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Example of a final case class definition in Scala 3, including inheritance and derivation. ```scala final case class C() extends A derives B, C.D ``` -------------------------------- ### Scala Package Object Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Defines a Scala 'package object' which allows defining members at the package level. This example includes a type alias and a variable within the package object. ```scala package object d extends A { val hello: String = "there" } ``` -------------------------------- ### Build All Subprojects with Gradle Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md Use this command to build all subprojects within the repository. Ensure Gradle is set up correctly. ```bash ./gradlew build ``` -------------------------------- ### Clean and Rebuild Project with Gradle Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md Perform a clean build by first removing previous build artifacts and then compiling and building the project. ```bash ./gradlew clean build ``` -------------------------------- ### Class Definition with Parameters (Scala 3 Syntax) Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates Scala 3 class syntax, including `using` for context parameters and annotations with arguments. ```scala class Point(val x: Int, val y: Int)(using coord: Coord) ``` ```scala class A @ann (x: Int, y: Int) ``` ```scala class A @ann(1) (x: Int, y: Int) ``` ```scala class A @ann(1)(1) (x: Int, y: Int) ``` -------------------------------- ### Run All Tests with Gradle Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md Execute all tests in the project using the Gradle wrapper. This is useful for a full test suite verification. ```bash ./gradlew test ``` -------------------------------- ### Build and Test Native Modules for New Parser Source: https://github.com/bonede/tree-sitter-ng/blob/main/README.md After generating a new parser subproject, trigger the download of native dependencies, cross-compilation using Zig, and run tests for the new parser. ```bash ./gradlew :tree-sitter-kotlin:buildNative ./gradlew :tree-sitter-kotlin:test ``` -------------------------------- ### Basic Object Definitions in Scala Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates different ways to define objects in Scala, including empty objects, case objects, and objects extending other types or with initializers. ```scala object O1 { } case object O2 { } object O3 extends A { } object O4 extends { val a: A = b } object O5 { ;; ; ; } ``` -------------------------------- ### Build Native Libraries Only Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md This command focuses on building only the native components of the project, excluding Java code compilation. ```bash ./gradlew buildNative ``` -------------------------------- ### Publish Artifacts After Staging Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md After staging, this command finalizes the publishing process. Manual confirmation is needed on the Sonatype platform. ```bash ./gradlew postPublish ``` -------------------------------- ### Scala 3 Given Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates various forms of Scala 3 'given' definitions, including those with generic types, context bounds, and specific implementations. ```scala private given listFoo[A1](using ev: CanFoo[A1]): CanFoo[List[A1]] with def foo(xs: List[A1]): Int = 0 ``` ```scala given foo(using ev: Foo) : Foo = ev ``` ```scala given Context = ctx ``` ```scala given Context[T] = ctx ``` ```scala given Foo[Int] = case n => "123" ``` ```scala given (using a: Int): Int = a ``` ```scala given [A: Foo]: Foo[List[A]] with def x = () ``` ```scala given [A](using Foo[A]): Foo[List[A]] with def x = () ``` ```scala trait B: given c: Context[T] ``` -------------------------------- ### Scala Class Initialization Expression Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates a Scala class with initialization expressions and an assertion. The AST shows the class parameters, type identifiers, and the call expression for the assertion. ```scala class A(val x: Int, val y: Int) { assert(x != 0) } ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (class_parameters (class_parameter (identifier) (type_identifier)) (class_parameter (identifier) (type_identifier))) (template_body (call_expression (identifier) (arguments (infix_expression (identifier) (operator_identifier) (integer_literal))))))) ``` -------------------------------- ### Class Definitions with Type Parameters and Parameters Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates Scala class definitions with generic type parameters and constructor parameters, including lazy and repeated parameters. ```scala class C[ T, U, ](a: => A, b: B, c: C*) { } class A () () {} ``` -------------------------------- ### Add Tree Sitter Dependencies (Gradle) Source: https://github.com/bonede/tree-sitter-ng/blob/main/README.md Add the core tree-sitter library and the JSON parser to your Gradle project. Replace $VERSION with the desired version. ```groovy // Gradle dependencies { // add tree sitter implementation 'io.github.bonede:tree-sitter:$VERSION' // add json parser implementation 'io.github.bonede:tree-sitter-json:$VERSION' } ``` -------------------------------- ### Run Specific Test Class with Gradle Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md To run tests for a specific class, use the `--tests` flag followed by the fully qualified class name. ```bash ./gradlew test --tests "org.treesitter.TSParserTest" ``` -------------------------------- ### Scala 3 Package Syntax Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates Scala 3's alternative syntax for package declarations using colons and indentation, including explicit end markers. ```scala package a.b package c: object A package d: object A end d ``` -------------------------------- ### Scala Package Declaration Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates basic Scala package declarations, including nested packages and scoped package definitions using curly braces. ```scala package a.b package c { object A } ``` -------------------------------- ### Release to Maven Central Staging Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md Prepare and publish specific language parser modules to the Maven Central staging repository. Manual steps are required post-execution. ```bash ./gradlew :tree-sitter-:publish :tree-sitter-:publish ``` -------------------------------- ### Scala Function Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates basic function definitions within a Scala class, including parameters and return types. ```scala class A { def b( c: D, e: F, ) = 1 def l: Int = 1 def m = () def n(using a: A) (using B <:< B, C =:= C) = () def o() : Int = 42 } ``` -------------------------------- ### Run Specific Test Method with Gradle Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md Isolate and run a single test method by specifying its fully qualified name after the `--tests` flag. ```bash ./gradlew test --tests "org.treesitter.TSParserTest.testParseString" ``` -------------------------------- ### AST for Class Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Abstract Syntax Tree representation for Scala class definitions. ```tree-sitter (compilation_unit (class_definition (identifier) (type_parameters (identifier) (identifier)) (class_parameters (class_parameter (identifier) (lazy_parameter_type (type_identifier))) (class_parameter (identifier) (type_identifier)) (class_parameter (identifier) (repeated_parameter_type (type_identifier)))) (template_body)) (class_definition (identifier) (class_parameters) (class_parameters) (template_body))) ``` -------------------------------- ### AST for Object Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Abstract Syntax Tree representation for various Scala object definitions. ```tree-sitter (compilation_unit (comment) (object_definition (identifier) (template_body)) (object_definition (identifier) (template_body)) (object_definition (identifier) (extends_clause (type_identifier)) (template_body)) (object_definition (identifier) (extends_clause (structural_type (val_definition (identifier) (type_identifier) (identifier))))) (object_definition (identifier) (template_body))) ``` -------------------------------- ### Generate New Language Parser Source: https://github.com/bonede/tree-sitter-ng/blob/main/README.md Use the Gradle 'gen' task to create a new subproject for a language parser. Provide the parser name, version, and a zip archive URL of its source code. ```bash ./gradlew gen --parser-name=kotlin --parser-version=0.3.8 --parser-zip=https://github.com/fwcd/tree-sitter-kotlin/archive/refs/tags/0.3.8.zip ``` -------------------------------- ### Scala Value Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows how to define immutable values with initial assignments, including type annotations and multiple definitions. Use for initializing fields. ```scala class A { val b = 1 val c : String = "d" val a, b, c: T3 = triple var a, b, c = triple } ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (val_definition (identifier) (integer_literal)) (val_definition (identifier) (type_identifier) (string)) (val_definition (identifiers (identifier) (identifier) (identifier)) (type_identifier) (identifier)) (var_definition (identifiers (identifier) (identifier) (identifier)) (identifier))))) ``` -------------------------------- ### Add Tree Sitter Dependencies (Maven) Source: https://github.com/bonede/tree-sitter-ng/blob/main/README.md Add the core tree-sitter library and the JSON parser to your Maven project. Replace $VERSION with the desired version. ```xml io.github.bonede tree-sitter $VERSION io.github.bonede tree-sitter-json $VERSION ``` -------------------------------- ### Scala 3 Subclass Definition Syntax Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates the Scala 3 syntax for subclass definitions using commas for multiple parents and `end` for block termination. ```scala class A extends B, C: 1 end A ``` -------------------------------- ### Parse JSON with Tree-sitter-ng API Source: https://github.com/bonede/tree-sitter-ng/blob/main/README.md Demonstrates parsing JSON source code using the Tree-sitter-ng Java API. It shows how to set the language parser, parse with string input, encoding, and a custom reader. It also covers AST traversal and querying. ```java class Main { public static void main(String[] args) { String jsonSource = "[1, null]"; TSParser parser = new TSParser(); TSLanguage json = new TreeSitterJson(); // set language parser parser.setLanguage(json); // parser with string input parser.parseString(null, jsonSource); parser.reset(); // or parser with encoding parser.parseStringEncoding(null, JSON_SRC, TSInputEncoding.TSInputEncodingUTF8); parser.reset(); // or parser with custom reader byte[] buffer = new byte[1024]; TSReader reader = (buf, offset, position) -> { if(offset >= jsonSource.length()){ return 0; } ByteBuffer charBuffer = ByteBuffer.wrap(buf); charBuffer.put(jsonSource.getBytes()); return jsonSource.length(); }; TSTree tree = parser.parse(buffer, null, reader, TSInputEncoding.TSInputEncodingUTF8); // traverse the AST tree with DOM like APIs TSNode rootNode = tree.getRootNode(); TSNode arrayNode = rootNode.getNamedChild(0); // or travers the AST with cursor TSTreeCursor rootCursor = new TSTreeCursor(rootNode); rootCursor.gotoFirstChild(); // or query the AST with S-expression TreeSitterQuery query = new TSQuery(json, "((document) @root)"); TSQueryCursor cursor = new TSQueryCursor(); cursor.exec(query, rootNode); SQueryMatch match = new TSQueryMatch(); while(cursor.nextMatch(match)){ // do something with the match } // debug the parser with a logger TSLogger logger = (type, message) -> { System.out.println(message); }; parser.setLogger(logger); // or output the AST tree as DOT graph File dotFile = File.createTempFile("json", ".dot"); parser.printDotGraphs(dotFile); } } ``` -------------------------------- ### Class Definition with Annotations and Members Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt Defines a class 'A' with a constructor parameter 'x', and members 'y' and 'z'. Includes annotated and deprecated methods. ```Scala class A(x: String) { @transient @volatile var y: Int @transient @volatile val z = x @throws(Error) @deprecated(message = "Don't use this", since = "1.0") def foo() {} } ``` -------------------------------- ### AST for Case Object with Derivation Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Abstract Syntax Tree representation for a case object with derivation. ```tree-sitter (compilation_unit (object_definition (identifier) (extends_clause (type_identifier)) (derives_clause (type_identifier) (type_identifier)) (template_body))) ``` -------------------------------- ### Class Parameters with Annotations Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt Illustrates class parameters and function parameters annotated with custom annotations like '@one' and '@another'. ```Scala class A(@one x: String) { def foo(@another x: Int) {} } ``` -------------------------------- ### Run Tests for Specific Language Parser Source: https://github.com/bonede/tree-sitter-ng/blob/main/CLAUDE.md Execute tests for an individual language parser, like `tree-sitter-json`, by specifying the module path. ```bash ./gradlew :tree-sitter-json:test ``` -------------------------------- ### Scala 3 Variable Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates Scala 3 syntax for defining mutable variables, including multi-line initializers. Use for variables requiring complex initialization. ```scala class A: var b: Int = 1 var c: Int = val d = 2 d ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (var_definition (identifier) (type_identifier) (integer_literal)) (var_definition (identifier) (type_identifier) (indented_block (val_definition (identifier) (integer_literal)) (identifier)))))) ``` -------------------------------- ### Scala 3 Function Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates Scala 3 specific function definitions, including indented blocks for function bodies. ```scala class A: def foo(c: C): Int = val x = 1 val y = 2 x + y ``` -------------------------------- ### Scala Extension Methods Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows how to define extension methods for existing types in Scala 3, including generic extensions. ```scala object A: extension (c: C) def foo: Int = 1 extension [A1](d: D) def foo = "foo" trait B: extension (x: Int) def bar: String ``` -------------------------------- ### AST for Subclass Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Abstract Syntax Tree representation for various subclass definitions in Scala. ```tree-sitter (compilation_unit (class_definition (identifier) (extends_clause (generic_type (stable_type_identifier (identifier) (type_identifier)) (type_arguments (type_identifier) (type_identifier)))) (template_body)) (class_definition (identifier) (class_parameters (class_parameter (identifier) (type_identifier))) (extends_clause (type_identifier) (arguments (infix_expression (identifier) (operator_identifier) (identifier)))) (template_body)) (object_definition (identifier) (template_body (class_definition (identifier) (extends_clause (generic_type (type_identifier) (type_arguments (type_identifier))) (generic_type (type_identifier) (type_arguments (type_identifier))))))) (class_definition (identifier) (class_parameters (class_parameter (identifier) (type_identifier))) (extends_clause (type_identifier) (arguments (identifier)) (type_identifier))) (class_definition (identifier) (extends_clause (type_identifier) (arguments) (type_identifier)))) ``` -------------------------------- ### AST for Scala 3 Class Definition with Derivation Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Abstract Syntax Tree representation for a Scala 3 class definition with derivation. ```tree-sitter (compilation_unit (class_definition (modifiers) (identifier) (class_parameters) (extends_clause (type_identifier)) (derives_clause (type_identifier) (stable_type_identifier (identifier) (type_identifier))))) ``` -------------------------------- ### Class Definition with Parameters Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Defines a Scala class with primary constructor parameters and secondary class parameters. ```scala class Point( val x: Int, val y: Int, )(implicit coord: Coord) ``` ```scala class A @Inject()(x: Int, y: Int) ``` -------------------------------- ### Subclass Definitions with Generic and Infix Types Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows various ways to define subclasses in Scala, including generic type arguments, constructor parameters, and mixed inheritance. ```scala class A extends B.C[D, E] { } class A(b: B) extends C(b || ok) { } object C { class A extends B[T] with C[T] } class D(c: String) extends E(c) with F class MyClass extends Potato() with Tomato ``` -------------------------------- ### Trait Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows different ways to define traits in Scala, including inheritance, multiple inheritance with `with`, and generic type parameters. ```scala trait A extends B ``` ```scala trait A extends B with C derives D ``` ```scala trait T[U] { } ``` ```scala trait T[U] extends V.W[U] { } ``` -------------------------------- ### AST for Scala 3 Subclass Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Abstract Syntax Tree representation for a Scala 3 subclass definition. ```tree-sitter (compilation_unit (class_definition (identifier) (extends_clause (type_identifier)) ``` -------------------------------- ### Tree-sitter Grammar for Class Parameters Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations_extra_delim.txt Abstract syntax tree structure for a class definition with annotated class parameters and annotated function parameters. ```tree-sitter grammar (compilation_unit (class_definition (identifier) (class_parameters (class_parameter (annotation (type_identifier)) (identifier) (type_identifier))) (template_body (function_definition (identifier) (parameters (parameter (annotation (type_identifier)) (identifier) (type_identifier))) (block))))) ``` -------------------------------- ### Inline given instance in Scala 3 Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows how to define an `inline given` instance. This feature is specific to Scala 3. ```scala inline given Test = new Test ``` ```tree-sitter-grammar (compilation_unit (given_definition (modifiers (inline_modifier)) (type_identifier) (indented_block (instance_expression (type_identifier))))) ``` -------------------------------- ### Scala Package Declaration with Semicolon Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows a Scala package declaration followed by a semicolon, which is a valid alternative syntax for terminating package clauses. ```scala package a.b; ``` -------------------------------- ### Export declarations in Scala 3 Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates various ways to use `export` for re-exporting members from other objects or packages, including aliasing and wildcards. ```scala export scanUnit.scan export printUnit.{status as _, *} export printUnit.Test as Hello export printUnit.Test as _ ``` ```tree-sitter-grammar (compilation_unit (export_declaration (identifier) (identifier)) (export_declaration (identifier) (namespace_selectors (as_renamed_identifier (identifier) (wildcard)) (namespace_wildcard))) (export_declaration (identifier) (as_renamed_identifier (identifier) (identifier))) (export_declaration (identifier) (as_renamed_identifier (identifier) (wildcard)))) ``` -------------------------------- ### Tree-sitter Grammar for Class with Members Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations_extra_delim.txt Abstract syntax tree structure for a class definition, detailing variable and value declarations with annotations, and function definitions with annotations. ```tree-sitter grammar (compilation_unit (class_definition (identifier) (class_parameters (class_parameter (identifier) (type_identifier))) (template_body (var_declaration (annotation (type_identifier)) (annotation (type_identifier)) (identifier) (type_identifier)) (val_definition (annotation (type_identifier)) (annotation (type_identifier)) (identifier) (identifier)) (function_definition (annotation (type_identifier) (arguments (identifier))) (annotation (type_identifier) (arguments (assignment_expression (identifier) (string)) (assignment_expression (identifier) (string)))) (identifier) (parameters) (block)))) ``` -------------------------------- ### Scala 3 Value Declarations Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates Scala 3 syntax for class value declarations, including comments that do not affect indentation. Suitable for declaring immutable members. ```scala class A: // Comments that should not // influence indentation val b, c : Int val d : String ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (comment) (comment) (val_declaration (identifier) (identifier) (type_identifier)) (val_declaration (identifier) (type_identifier))))) ``` -------------------------------- ### Scala Function with Optional Parameters Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates a Scala function definition with optional parameters for indentation and repetition. The AST captures the function identifier, parameters with their types and default values. ```scala def mkLines(header: String, indented: Boolean = false, repeated: Long = 0L): String = {} ``` ```tree-sitter-grammar (compilation_unit (function_definition (identifier) (parameters (parameter (identifier) (type_identifier)) (parameter (identifier) (type_identifier) (boolean_literal)) (parameter (identifier) (type_identifier) (integer_literal))) (type_identifier) (block))) ``` -------------------------------- ### Inline val in Scala 3 Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates the use of `inline val` for compile-time constants. Requires Scala 3. ```scala inline def test() = inline val x = true ``` ```tree-sitter-grammar (compilation_unit (function_definition (modifiers (inline_modifier)) (identifier) (parameters) (indented_block (val_definition (modifiers (inline_modifier)) (identifier) (boolean_literal))))) ``` -------------------------------- ### Tree-sitter Grammar for Annotated Parameters Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt This grammar rule parses class and function definitions with annotated parameters. ```tree-sitter grammar (compilation_unit (class_definition (identifier) (class_parameters (class_parameter (annotation (type_identifier)) (identifier) (type_identifier))) (template_body (function_definition (identifier) (parameters (parameter (annotation (type_identifier)) (identifier) (type_identifier))) (block))))) ``` -------------------------------- ### Tree-sitter Grammar for Class Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations_extra_delim.txt Represents the abstract syntax tree structure for a class definition, including annotations, identifiers, parameters, and template bodies. ```tree-sitter grammar (compilation_unit (class_definition (annotation (type_identifier) (arguments (string) (string)))) (identifier) (template_body)) ``` -------------------------------- ### Class Definition with Modifiers Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates Scala class definitions with various modifiers like `implicit`, `final`, `sealed`, `private`, and `override`. ```scala implicit final sealed class Point { private override def getX() = 1 } ``` ```scala private[a] class D[T] private (x: T) { private[a] def b: Byte } ``` -------------------------------- ### Scala Operator Identifiers and Usage Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates the definition and usage of Scala's operator identifiers, including custom type aliases and overloaded operators like '::', '+:', ':+', and '##'. Note the comment explaining the avoidance of matching slashes. ```scala type ::[+Ab] = scala.collection.immutable.::[Ab] val :: = scala.collection.immutable.:: val +: = scala.collection.+: val :+ = scala.collection.:+ def → = ??? val test = id.## val x = y ///////// // avoid matching slashes as operator ///////// ``` -------------------------------- ### Scala 3 Class Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt A simple Scala 3 class definition with a method that returns unit. ```scala class A: def a() = () ``` -------------------------------- ### Open class definition in Scala 3 Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Defines an `open class` with a constructor parameter. `open` classes can be extended by classes from other packages. ```scala open class Test(a: Int): def test = 25 end Test ``` ```tree-sitter-grammar (compilation_unit (class_definition (modifiers (open_modifier)) (identifier) (class_parameters (class_parameter (identifier) (type_identifier))) (template_body (function_definition (identifier) (integer_literal))))) ``` -------------------------------- ### Tree-sitter Grammar for Generic Trait Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations_extra_delim.txt Abstract syntax tree structure for a trait definition with type parameters, including specialized types and function declarations. ```tree-sitter grammar (compilation_unit (trait_definition (identifier) (type_parameters (annotation (type_identifier) (arguments (identifier) (identifier) (identifier))) (identifier)) (template_body (function_declaration (identifier) (type_identifier))))) ``` -------------------------------- ### Infix private method in Scala 3 Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Illustrates an `inline infix private` method definition. Note the combination of modifiers. ```scala object Test: inline infix private def hello = 25 ``` ```tree-sitter-grammar (compilation_unit (object_definition (identifier) (template_body (function_definition (modifiers (inline_modifier) (infix_modifier) (access_modifier)) (identifier) (integer_literal))))) ``` -------------------------------- ### Tree-sitter Grammar for Class Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt This tree-sitter grammar rule parses a class definition including parameters, variable declarations, value definitions, and function definitions with annotations. ```tree-sitter grammar (compilation_unit (class_definition (identifier) (class_parameters (class_parameter (identifier) (type_identifier))) (template_body (var_declaration (annotation (type_identifier)) (annotation (type_identifier)) (identifier) (type_identifier)) (val_definition (annotation (type_identifier)) (annotation (type_identifier)) (identifier) (identifier)) (function_definition (annotation (type_identifier) (arguments (identifier))) (annotation (type_identifier) (arguments (assignment_expression (identifier) (string)) (assignment_expression (identifier) (string)))) (identifier) (parameters) (block))))) ``` -------------------------------- ### Scala 3 Enum Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows the structure of a Scala 3 enum with various cases, including simple cases, parameterized cases, and inherited cases. The AST details annotations, type parameters, and extends clauses. ```scala @A enum Hello[Y] extends java.Enumeration derives Codec, Eq { @A("") @B case World, You @A case Test[A](bla: Int, yo: String) extends Hello[A] case T extends Hello[String](25) } ``` ```tree-sitter-grammar (compilation_unit (enum_definition (annotation (type_identifier)) (identifier) (type_parameters (identifier)) (extends_clause (stable_type_identifier (identifier) (type_identifier))) (derives_clause (type_identifier) (type_identifier)) (enum_body (enum_case_definitions (annotation (type_identifier) (arguments (string))) (annotation (type_identifier)) (simple_enum_case (identifier)) (simple_enum_case (identifier))) (enum_case_definitions (annotation (type_identifier)) (full_enum_case (identifier) (type_parameters (identifier)) (class_parameters (class_parameter (identifier) (type_identifier)) (class_parameter (identifier) (type_identifier))) (extends_clause (generic_type (type_identifier) (type_arguments (type_identifier)))))) (enum_case_definitions (simple_enum_case (identifier) (extends_clause (generic_type (type_identifier) (type_arguments (type_identifier))) (arguments (integer_literal)))))))) ``` -------------------------------- ### Scala 3 Top-Level Function Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt A Scala 3 top-level function definition that returns an integer. ```scala def a() = 1 ``` -------------------------------- ### Scala Self Types Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates the use of self types in Scala traits and classes. The AST shows the self type declaration and its usage within the class or trait body. ```scala trait A { self => def f: Int } ``` ```scala trait A { self => def f: Int } ``` ```scala class B { self: Something[A] => case class Hello(a: Int) } ``` ```tree-sitter-grammar (compilation_unit (trait_definition (identifier) (template_body (self_type (identifier)) (function_declaration (identifier) (type_identifier)))) (trait_definition (identifier) (template_body (self_type (identifier)) (function_declaration (identifier) (type_identifier)))) (class_definition (identifier) (template_body (self_type (identifier) (generic_type (type_identifier) (type_arguments (type_identifier)))) (class_definition (identifier) (class_parameters (class_parameter (identifier) (type_identifier))))))) ``` -------------------------------- ### Tree-sitter Grammar for Generic Trait Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt This grammar rule parses a trait definition with type parameters and specialized annotations. ```tree-sitter grammar (compilation_unit (trait_definition (identifier) (type_parameters (annotation (type_identifier) (arguments (identifier) (identifier) (identifier))) (identifier)) (template_body (function_declaration (identifier) (type_identifier))))) ``` -------------------------------- ### Scala Variable Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Defines mutable variables with initial values and type annotations. Suitable for fields that require reassignment. ```scala class A { var b : Int = 1 } ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (var_definition (identifier) (type_identifier) (integer_literal))))) ``` -------------------------------- ### Scala Type Definitions Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Defines type aliases and abstract types within a class, including generic type parameters. Use for creating type synonyms or abstracting types. ```scala class A { type B = C type D[E] = F type Abs type Beta[B] } ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (type_definition (type_identifier) (type_identifier)) (type_definition (type_identifier) (type_parameters (identifier)) (type_identifier)) (type_definition (type_identifier)) (type_definition (type_identifier) (type_parameters (identifier)))))) ``` -------------------------------- ### Scala Identifiers with Special Characters Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Demonstrates Scala identifiers that include special characters like '!', '->', '__', '?', '^', and Unicode characters. These are valid in Scala for defining variables and functions. ```scala def m = ??? def unary_! = true def a_-> = ??? def __symtem = ??? def empty_? = ??? def ひらがな = ??? def a_^ = ??? ``` -------------------------------- ### Scala 3 Inline Method Definition Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows a Scala 3 function definition using the 'inline' modifier for both the method and its parameters. The AST captures the inline modifiers and parameter declarations. ```scala inline def mkLines(inline header: String, indented: Boolean = false): String = {} ``` ```tree-sitter-grammar (compilation_unit (function_definition (modifiers (inline_modifier)) (identifier) (parameters (parameter (inline_modifier) (identifier) ``` -------------------------------- ### Tree-sitter Grammar for Deprecated Class Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt This is a tree-sitter grammar rule representing a class definition with an annotation, identifier, and template body. ```tree-sitter grammar (compilation_unit (class_definition (annotation (type_identifier) (arguments (string) (string))) (identifier) (template_body))) ``` -------------------------------- ### Scala Function Declarations Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Declares a method signature within a class, specifying parameter types and return type. Use for defining method contracts without implementation. ```scala class A { def b(c: D) : E ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (def_declaration (identifier) (parameters (parameter (identifier) (type_identifier))) (type_identifier))))) ``` -------------------------------- ### Scala Value Declarations Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Defines a class with immutable value members and their types. Used for declaring fields that will not be reassigned. ```scala class A { val b, c : Int val d : String } ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (val_declaration (identifier) (identifier) (type_identifier)) (val_declaration (identifier) (type_identifier))))) ``` -------------------------------- ### Scala Class Definition with '$' in Identifiers Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows a Scala class definition where identifiers contain the '$' symbol. This is a valid, though uncommon, practice for naming classes, variables, and types. ```scala class $A$B$ { val b$, c$ : Int val d$ : String } ``` -------------------------------- ### Generic Trait with Specialized Type Parameter Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/annotations.txt Defines a generic trait 'Function0' with a type parameter 'T' that is specialized for Unit, Int, and Double. ```Scala trait Function0[@specialized(Unit, Int, Double) T] { def apply: T } ``` -------------------------------- ### Scala Variable Declarations Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Declares mutable variable members within a class, specifying their types. Use when fields need to be reassigned. ```scala class A { var b, c : Int var d : String } ``` ```tree-sitter-grammar (compilation_unit (class_definition (identifier) (template_body (var_declaration (identifier) (identifier) (type_identifier)) (var_declaration (identifier) (type_identifier))))) ``` -------------------------------- ### Transparent trait definition in Scala 3 Source: https://github.com/bonede/tree-sitter-ng/blob/main/tree-sitter-tests/src/test/resources/test/corpus/definitions.txt Shows a `transparent trait` with a self-type annotation. Transparent traits are erased at compile time. ```scala transparent trait Kind: this: A => def test = 1 ``` ```tree-sitter-grammar (compilation_unit (trait_definition (modifiers (transparent_modifier)) (identifier) (template_body (self_type (identifier) (type_identifier)) (function_definition (identifier) (integer_literal))))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.