├── webapp ├── index.js ├── highlights.scm ├── FiraCode-Regular.ttf ├── postcss.config.js ├── tailwind.config.js ├── index.css ├── vite.config.js ├── src │ └── main │ │ └── scala │ │ ├── HighlightJS.scala │ │ ├── CodeMirror.scala │ │ └── Webapp.scala ├── tree-sitter.js ├── package.json └── index.html ├── project ├── build.properties ├── plugins.sbt └── ArtifactNaming.scala ├── .gitattributes ├── mod ├── cairo-bindings │ ├── amalgam.h │ └── src │ │ └── main │ │ └── resources │ │ └── scala-native │ │ └── generated │ │ └── cairo.c ├── tree-sitter-interface │ └── src │ │ ├── test │ │ ├── scalajs │ │ │ └── Bootstrap.scala │ │ ├── scala │ │ │ └── HighlightTokenizerTest.scala │ │ └── scalanative │ │ │ └── Bootstrap.scala │ │ └── main │ │ ├── scala │ │ ├── TreesitterInterface.scala │ │ └── HighlightTokenizer.scala │ │ ├── scalajs │ │ └── TreeSitter.scala │ │ ├── scalanative │ │ └── TreeSitter.scala │ │ └── resources │ │ └── scala-native │ │ └── generated │ │ └── treesitter.c ├── lib │ └── src │ │ └── main │ │ └── scala │ │ ├── CairoMacros.scala │ │ ├── Lib.scala │ │ └── ImageGenerator.scala ├── themes │ └── src │ │ └── main │ │ └── scala │ │ ├── Color.scala │ │ └── Theme.scala ├── bin │ └── src │ │ └── main │ │ └── scala │ │ └── Main.scala ├── treesitter-bindings │ └── src │ │ └── main │ │ ├── resources │ │ └── scala-native │ │ │ └── generated │ │ │ └── tree_sitter.c │ │ └── scala │ │ └── generated │ │ └── tree_sitter.scala └── cmark-bindings │ └── src │ └── main │ └── scala │ └── generated │ └── cmark.scala ├── .gitmodules ├── .scalafmt.conf ├── .gitignore ├── README.md ├── .github └── workflows │ ├── release-webapp.yml │ └── release-binary.yml └── LICENSE /webapp/index.js: -------------------------------------------------------------------------------- 1 | import 'scalajs:main.js' 2 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 1.10.6 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.wasm filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /webapp/highlights.scm: -------------------------------------------------------------------------------- 1 | ../tree-sitter-scala/queries/highlights.scm -------------------------------------------------------------------------------- /mod/cairo-bindings/amalgam.h: -------------------------------------------------------------------------------- 1 | #include "cairo.h" 2 | #include "cairo-ft.h" 3 | -------------------------------------------------------------------------------- /webapp/FiraCode-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keynmol/scala-treesitter-highlighting/HEAD/webapp/FiraCode-Regular.ttf -------------------------------------------------------------------------------- /webapp/postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "tree-sitter-scala"] 2 | path = tree-sitter-scala 3 | url = https://github.com/tree-sitter/tree-sitter-scala/ 4 | -------------------------------------------------------------------------------- /webapp/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export const content = [ 3 | './*.{html,js}', 4 | './components/**/*.{html,js}', 5 | './target/**/*.{html,js}', 6 | ]; 7 | -------------------------------------------------------------------------------- /.scalafmt.conf: -------------------------------------------------------------------------------- 1 | version = "3.8.1" 2 | runner.dialect = scala3 3 | rewrite.scala3.insertEndMarkerMinLines = 10 4 | rewrite.scala3.removeOptionalBraces = true 5 | rewrite.scala3.convertToNewSyntax = true 6 | 7 | -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/test/scalajs/Bootstrap.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight 2 | 3 | 4 | object Bootstrap: 5 | def forScala(f: TreeSitterInterface => Unit) = 6 | f(TreeSitter(Parser)) 7 | 8 | lazy val QUERIES = "" // TODO 9 | -------------------------------------------------------------------------------- /webapp/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @font-face { 6 | font-family: myFirstFont; 7 | src: url(/FiraCode-Regular.ttf); 8 | } 9 | 10 | pre.ts-hl { 11 | padding: 15px; 12 | } 13 | -------------------------------------------------------------------------------- /webapp/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import scalaJSPlugin from "@scala-js/vite-plugin-scalajs"; 3 | export default defineConfig({ 4 | build: { 5 | target: 'esnext' //browsers can handle the latest ES features 6 | }, 7 | plugins: [scalaJSPlugin({ 8 | cwd: '../', 9 | projectID: 'webapp' 10 | })], 11 | }) 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | project/target 2 | project/project 3 | .metals 4 | .bloop 5 | .vscode 6 | *.class 7 | *.sjsr 8 | 9 | project/.bloop 10 | 11 | .sbt 12 | 13 | modules/core/target 14 | 15 | root/target 16 | target 17 | 18 | .bsp 19 | 20 | *.log 21 | 22 | project/metals.sbt 23 | 24 | 25 | node_modules 26 | dist 27 | dist-ssr 28 | *.local 29 | out 30 | *.wasm 31 | -------------------------------------------------------------------------------- /webapp/src/main/scala/HighlightJS.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight.webapp 2 | 3 | import org.scalajs.dom 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSImport 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | @JSGlobal 10 | object hljs extends js.Object: 11 | def highlightElement(element: dom.HTMLElement): Unit = js.native 12 | end hljs 13 | -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/test/scala/HighlightTokenizerTest.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight 2 | 3 | class HighlightTokenizerTest extends munit.FunSuite: 4 | test("basics"): 5 | Bootstrap.forScala: ts => 6 | val highlight = 7 | HighlightTokenizer(CODE, Bootstrap.QUERIES, ts).switches.toVector 8 | 9 | end HighlightTokenizerTest 10 | 11 | val CODE = """ 12 | val _ = s"test ${code + "hello"} bla" 13 | """.trim 14 | -------------------------------------------------------------------------------- /mod/lib/src/main/scala/CairoMacros.scala: -------------------------------------------------------------------------------- 1 | package scala_highlight.lib 2 | 3 | import scala.quoted.* 4 | import scalanative.unsafe.fromCString 5 | import cairo.aliases.FT_Error 6 | import cairo.functions.FT_Error_String 7 | 8 | inline def check(inline expr: => FT_Error): FT_Error = ${ checkImpl('expr) } 9 | 10 | private def checkImpl(expr: Expr[FT_Error])(using Quotes): Expr[FT_Error] = 11 | import quotes.* 12 | val e = Expr(s"${expr.show.take(500)} failed: ") 13 | 14 | '{ 15 | val code = $expr 16 | assert( 17 | code.value == 0, 18 | $e + "[" + fromCString(FT_Error_String(code)) + "]" 19 | ) 20 | code 21 | } 22 | end checkImpl 23 | -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/test/scalanative/Bootstrap.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight 2 | 3 | import scalanative.unsafe.* 4 | import tree_sitter.structs.TSLanguage 5 | 6 | object Bootstrap: 7 | def forScala(f: TreeSitterInterface => Unit) = 8 | Zone: 9 | val parser = tree_sitter.all.ts_parser_new() 10 | val lang = tree_sitter_scala() 11 | 12 | val ts = TreeSitter(parser, lang) 13 | f(ts) 14 | 15 | lazy val QUERIES = io.Source 16 | .fromInputStream(getClass().getResourceAsStream("/highlights.scm")) 17 | .getLines() 18 | .mkString(System.lineSeparator()) 19 | end Bootstrap 20 | 21 | def tree_sitter_scala(): Ptr[TSLanguage] = extern 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # In-browser syntax highlighting for Scala using Tree Sitter 2 | 3 | [**Live version**](https://keynmol.github.io/scala-treesitter-highlighting/) 4 | 5 | ade possible by [web-tree-sitter](https://www.npmjs.com/package/web-tree-sitter?activeTab=readme) bindings, and the ability to compile Tree Sitter Scala parser to WASM. 6 | 7 | ![CleanShot 2025-04-03 at 14 33 07@2x](https://github.com/user-attachments/assets/e82f19cf-c714-4116-9ddd-f6b0e1f195df) 8 | 9 | 10 | ## Contributing 11 | 12 | 1. Make sure you have Scala CLI installed 13 | 2. Run `npm install` 14 | 3. Run `npm watch` 15 | 4. Happy hacking! Your project will reload automatically as you make changes to [index.scala](./index.scala) or any other files 16 | -------------------------------------------------------------------------------- /webapp/tree-sitter.js: -------------------------------------------------------------------------------- 1 | import TreeSitter from 'web-tree-sitter'; 2 | import init from 'web-tree-sitter/tree-sitter.wasm?init&url'; 3 | import initScala from '/tree-sitter-scala.wasm?init&url'; 4 | 5 | const Parser = TreeSitter; 6 | 7 | let parser = await (async () => { 8 | await Parser.init({ 9 | locateFile(scriptName, scriptDirectory) { 10 | return init 11 | // if (import.meta.env.MODE == 'development') 12 | // return 'node_modules/web-tree-sitter/' + scriptName; 13 | // else return 'assets!/' + scriptName; 14 | }, 15 | }); 16 | const parser = new Parser(); 17 | const Lang = await Parser.Language.load(initScala); 18 | parser.setLanguage(Lang); 19 | return parser; 20 | })(); 21 | 22 | export default parser; 23 | 24 | -------------------------------------------------------------------------------- /webapp/src/main/scala/CodeMirror.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight.webapp 2 | 3 | import org.scalajs.dom 4 | import scala.scalajs.js 5 | import scala.scalajs.js.annotation.JSImport 6 | import scala.scalajs.js.annotation.JSGlobal 7 | 8 | @js.native 9 | trait CodeMirrorValue extends js.Object: 10 | def getValue(): String 11 | 12 | @js.native 13 | trait CodeMirrorInstance extends js.Object: 14 | def on( 15 | eventName: String, 16 | listener: js.Function1[CodeMirrorValue, Unit] 17 | ): this.type = js.native 18 | end CodeMirrorInstance 19 | 20 | @js.native 21 | @JSGlobal 22 | object CodeMirror extends js.Object: 23 | def fromTextArea( 24 | element: dom.HTMLElement, 25 | options: js.Any 26 | ): CodeMirrorInstance = 27 | js.native 28 | end CodeMirror 29 | -------------------------------------------------------------------------------- /webapp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scala-treesitter-highlighting", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "preview": "vite preview", 10 | "watch": "concurrently vite npm:watchScalajs", 11 | "watchScalajs": "sbt ~webapp/fastLinkJS", 12 | "buildForGithubPages": "vite build --base=/scala-treesitter-highlighting" 13 | }, 14 | "devDependencies": { 15 | "@scala-js/vite-plugin-scalajs": "^1.0.0", 16 | "autoprefixer": "^10.4.19", 17 | "concurrently": "^8.2.2", 18 | "postcss": "^8.4.38", 19 | "tailwindcss": "^3.4.3", 20 | "typescript": "^5.4.5", 21 | "vite": "^5.2.0" 22 | }, 23 | "dependencies": { 24 | "web-tree-sitter": "^0.22.6" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/release-webapp.yml: -------------------------------------------------------------------------------- 1 | name: Webapp 2 | on: 3 | push: 4 | branches: ["main"] 5 | tags: ["v*"] 6 | pull_request: 7 | branches: ["*"] 8 | 9 | jobs: 10 | build: 11 | strategy: 12 | fail-fast: false 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | with: 17 | submodules: true 18 | - uses: coursier/cache-action@v6.3 19 | - uses: sbt/setup-sbt@v1 20 | - run: sbt --client buildScalaWASM 21 | - run: cd webapp && npm install && npm run buildForGithubPages 22 | - name: Publish gh-pages 23 | if: (github.ref == 'refs/heads/main') 24 | uses: peaceiris/actions-gh-pages@v3 25 | with: 26 | github_token: ${{ secrets.GITHUB_TOKEN }} 27 | publish_dir: ./webapp/dist 28 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") 2 | 3 | addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.10.0") 4 | 5 | addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.3.1") 6 | 7 | addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") 8 | 9 | addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0") 10 | 11 | addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0") 12 | 13 | // Scala.js and Scala Native 14 | addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.17.0") 15 | 16 | addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.6") 17 | 18 | addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg-native" % "0.0.21") 19 | 20 | addSbtPlugin("com.indoorvivants" % "bindgen-sbt-plugin" % "0.1.4") 21 | 22 | libraryDependencies += "com.indoorvivants.detective" %% "platform" % "0.0.2" 23 | -------------------------------------------------------------------------------- /mod/cairo-bindings/src/main/resources/scala-native/generated/cairo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "cairo.h" 3 | #include "cairo-ft.h" 4 | 5 | FcBool __sn_wrap_cairo_FcPatternAdd(FcPattern * p, const char * object, FcValue *value, FcBool append) { 6 | return FcPatternAdd(p, object, *value, append); 7 | }; 8 | 9 | 10 | FcBool __sn_wrap_cairo_FcPatternAddWeak(FcPattern * p, const char * object, FcValue *value, FcBool append) { 11 | return FcPatternAddWeak(p, object, *value, append); 12 | }; 13 | 14 | 15 | void __sn_wrap_cairo_FcValueDestroy(FcValue *v) { 16 | FcValueDestroy(*v); 17 | }; 18 | 19 | 20 | FcBool __sn_wrap_cairo_FcValueEqual(FcValue *va, FcValue *vb) { 21 | return FcValueEqual(*va, *vb); 22 | }; 23 | 24 | 25 | void __sn_wrap_cairo_FcValuePrint(const FcValue *v) { 26 | FcValuePrint(*v); 27 | }; 28 | 29 | 30 | void __sn_wrap_cairo_FcValueSave(FcValue *v, FcValue *____return) { 31 | FcValue ____ret = FcValueSave(*v); 32 | memcpy(____return, &____ret, sizeof(FcValue)); 33 | } -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/main/scala/TreesitterInterface.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight 2 | 3 | import scala.annotation.* 4 | 5 | trait TreeSitterInterface: 6 | type Tree 7 | extension (t: Tree) def rootNode: Node 8 | 9 | def parse(source: String): Tree 10 | 11 | def getLanguage: Language 12 | 13 | type Point 14 | extension (p: Point) 15 | def row: Int 16 | def column: Int 17 | 18 | type Language 19 | extension (t: Language) def query(source: String): Query 20 | 21 | type Node 22 | extension (t: Node) 23 | def children: Iterable[Node] 24 | def startPoint: Point 25 | def endPoint: Point 26 | def text(source: String): String 27 | 28 | type Capture 29 | extension (t: Capture) 30 | @targetName("capture_name") 31 | def name(q: Query): String 32 | def node: Node 33 | 34 | type Match 35 | extension (t: Match) 36 | def captures: Iterable[Capture] 37 | 38 | type Query 39 | extension (q: Query) def matches(node: Node): Iterable[Match] 40 | end TreeSitterInterface 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Anton Sviridov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /project/ArtifactNaming.scala: -------------------------------------------------------------------------------- 1 | import com.indoorvivants.detective.Platform 2 | import Platform.* 3 | 4 | object ArtifactNames { 5 | def jarString(os: Platform.OS): String = { 6 | import Platform.OS.* 7 | os match { 8 | case Windows => "windows" 9 | case MacOS => "osx" 10 | case Linux => "linux" 11 | case Unknown => "unknown" 12 | } 13 | } 14 | 15 | def jarString(bits: Platform.Bits, arch: Platform.Arch): String = { 16 | (bits, arch) match { 17 | case (Bits.x64, Arch.Intel) => "x86_64" 18 | case (Bits.x64, Arch.Arm) => "aarch64" 19 | case (Bits.x32, Arch.Intel) => "x86_32" 20 | case (Bits.x32, Arch.Arm) => "aarch32" 21 | } 22 | } 23 | 24 | def jarString(target: Platform.Target): String = { 25 | jarString(target.bits, target.arch) + "-" + jarString(target.os) 26 | } 27 | 28 | def coursierString(os: Platform.OS): String = { 29 | import Platform.OS.* 30 | os match { 31 | case Windows => "pc-win32" 32 | case MacOS => "apple-darwin" 33 | case Linux => "pc-linux" 34 | case Unknown => "unknown" 35 | } 36 | } 37 | 38 | def coursierString(target: Platform.Target): String = { 39 | jarString(target.bits, target.arch) + "-" + coursierString(target.os) 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | Scala Highlighter using Tree Sitter 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /mod/themes/src/main/scala/Color.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight.themes 2 | 3 | import org.typelevel.literally.* 4 | 5 | extension (inline ctx: StringContext) 6 | inline def rgb(inline args: Any*): Color = 7 | ${ ColorLiteral('ctx, 'args) } 8 | 9 | case class Color(r: Int, g: Int, b: Int) 10 | object Color: 11 | def fromString( 12 | str: String 13 | ): Either[String, Color] = 14 | if str.startsWith("#") then 15 | val code = str.stripPrefix("#") 16 | if code.length != 6 then 17 | Left( 18 | "hex color needs to be exactly 6 hex characters long and start with # (total 7 characters)" 19 | ) 20 | else 21 | try 22 | Right(code.grouped(2).map(Integer.parseInt(_, 16)).toArray).map: it => 23 | Color(it(0), it(1), it(2)) 24 | catch 25 | case exc: NumberFormatException => 26 | Left("Failed to parse part of the color: " + exc.getMessage()) 27 | end if 28 | else 29 | str.split(",").map(_.trim).toList match 30 | case r :: g :: b :: Nil => 31 | try Right(Color(r.toInt, g.toInt, b.toInt)) 32 | catch 33 | case exc: NumberFormatException => 34 | Left("Failed to parse part of the color: " + exc.getMessage()) 35 | case _ => 36 | Left( 37 | "color should either be a comma separated triplet of decimal RGB values (example: `127,240,11`) or a hex code (example: `#00ff99`)" 38 | ) 39 | end Color 40 | 41 | object ColorLiteral extends Literally[Color]: 42 | def validate(s: String)(using Quotes) = 43 | Color.fromString(s) match 44 | case Left(err) => Left(err) 45 | case Right(_) => Right('{ Color.fromString(${ Expr(s) }).right.get }) 46 | -------------------------------------------------------------------------------- /mod/bin/src/main/scala/Main.scala: -------------------------------------------------------------------------------- 1 | package scala_highlight.bin 2 | 3 | import mainargs.{main, arg, ParserForMethods, Flag} 4 | import java.nio.file.Path 5 | import java.nio.file.Paths 6 | import ts_highlight.themes.Theme 7 | import scala_highlight.lib.* 8 | 9 | object Main: 10 | @main 11 | def markdown( 12 | @arg(doc = "Input markdown file") 13 | in: String, 14 | @arg(doc = "Output markdown file (when not provided, print to stdout)") 15 | out: Option[String] = None, 16 | @arg(doc = "Theme") 17 | theme: String = "kanagawa" 18 | ) = 19 | val contents = 20 | if in == "-" then 21 | scala.io.Source 22 | .fromInputStream(System.in) 23 | .getLines() 24 | .mkString(System.lineSeparator()) 25 | else 26 | scala.io.Source 27 | .fromFile(Paths.get(in).toFile) 28 | .getLines() 29 | .mkString(System.lineSeparator()) 30 | 31 | highlight_markdown_file( 32 | contents, 33 | out.map(Paths.get(_)), 34 | Theme.fromString(theme) 35 | ).foreach(println) 36 | end markdown 37 | 38 | @main 39 | def image( 40 | @arg(doc = "Scala snippet") 41 | in: String, 42 | @arg(doc = "Output PNG file location") 43 | out: String, 44 | @arg(doc = "Theme") 45 | theme: String = "kanagawa", 46 | @arg() 47 | fontSize: Int = 50 48 | ) = 49 | val contents = 50 | if in == "-" then 51 | scala.io.Source 52 | .fromInputStream(System.in) 53 | .getLines() 54 | .mkString(System.lineSeparator()) 55 | else 56 | scala.io.Source 57 | .fromFile(Paths.get(in).toFile()) 58 | .getLines() 59 | .mkString(System.lineSeparator()) 60 | val tokens = highlight_scala_snippet(contents).toList 61 | val th = 62 | Theme.fromString(theme).getOrElse(sys.error(s"Unknown theme `$theme`")) 63 | 64 | generate_image( 65 | contents = contents, 66 | tokens = tokens, 67 | theme = th, 68 | out = out, 69 | FONT_SIZE = fontSize 70 | ) 71 | end image 72 | 73 | def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) 74 | end Main 75 | -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/main/scalajs/TreeSitter.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight 2 | 3 | import scalajs.js 4 | import js.annotation.* 5 | import js.Array as Arr 6 | 7 | class TreeSitter(p: Parser.type) extends TreeSitterInterface: 8 | override opaque type Tree = p.Tree 9 | override opaque type Point = p.Point 10 | override opaque type Language = p.Language 11 | override opaque type Node = p.Node 12 | override opaque type Match = p.Match 13 | override opaque type Capture = p.Capture 14 | override opaque type Query = p.Query 15 | 16 | override inline def getLanguage = p.getLanguage() 17 | override inline def parse(source: String) = p.parse(source) 18 | 19 | extension (t: Tree) override inline def rootNode = t.rootNode 20 | 21 | extension (q: Query) 22 | override inline def matches(node: Node): Iterable[Match] = 23 | q.matches(node).toArray 24 | 25 | extension (m: Match) 26 | override inline def captures = 27 | m.captures 28 | 29 | extension (t: Capture) 30 | @annotation.targetName("capture_name") 31 | override inline def name(q: Query): String = t.name 32 | override inline def node = t.node 33 | 34 | 35 | extension (t: Node) 36 | override inline def children: Iterable[Node] = t.children.toArray 37 | override inline def startPoint = t.startPosition 38 | override inline def endPoint = t.endPosition 39 | override inline def text(source: String) = t.text 40 | 41 | extension (p: Point) 42 | override inline def column: Int = p.column 43 | override inline def row: Int = p.row 44 | 45 | extension (q: Language) 46 | override inline def query(source: String): Query = q.query(source) 47 | 48 | end TreeSitter 49 | 50 | @js.native 51 | @JSImport("/tree-sitter.js", JSImport.Default) 52 | private object Parser extends js.Any: 53 | def parse(path: String): Tree = js.native 54 | 55 | def getLanguage(): Language = js.native 56 | 57 | @js.native 58 | trait Language extends js.Any: 59 | def query(source: String): Query = js.native 60 | 61 | @js.native 62 | trait Query extends js.Any: 63 | def matches(node: Node): Arr[Match] = js.native 64 | 65 | @js.native 66 | trait Tree extends js.Any: 67 | val rootNode: Node = js.native 68 | 69 | @js.native 70 | trait Node extends js.Any: 71 | val id: Int = js.native 72 | val children: Arr[Node] = js.native 73 | val text: String = js.native 74 | val startPosition: Point = js.native 75 | val endPosition: Point = js.native 76 | 77 | @js.native 78 | trait Match extends js.Any: 79 | val name: String = js.native 80 | val captures: Arr[Capture] = js.native 81 | 82 | @js.native 83 | trait Capture extends js.Any: 84 | val name: String = js.native 85 | val node: Node = js.native 86 | val text: js.UndefOr[String] = js.native 87 | 88 | @js.native 89 | trait TreeCursor extends js.Any: 90 | val nodeId: Int = js.native 91 | val nodeText: String = js.native 92 | 93 | @js.native 94 | trait Point extends js.Any: 95 | val row: Int = js.native 96 | val column: Int = js.native 97 | end Parser 98 | -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/main/scala/HighlightTokenizer.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight 2 | 3 | case class HighlightToken(start: Int, finish: Int, kind: Option[String]) 4 | class HighlightTokenizer[TS <: TreeSitterInterface & Singleton]( 5 | source: String, 6 | highlightQueries: String, 7 | treesitter: TS 8 | ): 9 | private lazy val tree = treesitter.parse(source) 10 | private lazy val index = Index(source, treesitter) 11 | private lazy val lang = treesitter.getLanguage 12 | private lazy val query = lang.query(highlightQueries) 13 | private lazy val matches = query.matches(tree.rootNode) 14 | 15 | lazy val switches: List[(Int, Int, String)] = matches.toList 16 | .flatMap: m => 17 | m.captures.map: capture => 18 | ( 19 | index.resolve(capture.node.startPoint), 20 | index.resolve(capture.node.endPoint), 21 | capture.name(query) 22 | ) 23 | 24 | lazy val tokens: Array[HighlightToken] = 25 | val sortedSwitches = 26 | switches.zipWithIndex.sortBy(sw => sw._1._1 -> sw._2).map(_._1) 27 | 28 | val breakpoints = Vector.newBuilder[Int] 29 | 30 | sortedSwitches.headOption.foreach: (start, _, _) => 31 | if start != 0 then breakpoints += 0 32 | 33 | sortedSwitches.foreach: (start, _end, group) => 34 | breakpoints += start 35 | breakpoints += _end 36 | 37 | sortedSwitches.lastOption.foreach: (__, end, _) => 38 | if end != source.length - 1 then breakpoints += source.length - 1 39 | 40 | val points = breakpoints.result().distinct.sorted 41 | 42 | if points.length < 2 then Array.empty 43 | else 44 | /** WARNING: this is very slow. 45 | * 46 | * It performs a linear search for each interval. It's probably just fast 47 | * enough for most snippets, but it won't be winning any benchmark 48 | * prizes. We need something like an interval tree (a self balancing one, 49 | * and not sensitive to overlaps). 50 | */ 51 | points 52 | .sliding(2) 53 | .toVector 54 | .map: 55 | case Vector(start, end) => 56 | val g = sortedSwitches 57 | .filter((groupStart, groupEnd, group) => 58 | groupStart <= start && groupEnd >= end 59 | ) 60 | .sortBy((groupStart, groupEnd, _) => 61 | (start - groupStart, groupEnd - end) 62 | ) 63 | .headOption 64 | HighlightToken(start, end, g.map(_._3)) 65 | .toArray 66 | end if 67 | end tokens 68 | 69 | end HighlightTokenizer 70 | 71 | private class Index[T <: TreeSitterInterface & Singleton]( 72 | text: String, 73 | val ts: T 74 | ): 75 | val mapping: Map[Int, (Int, String)] = 76 | var curOffset = 0 77 | val spl = text.split("\n") 78 | val result = List.newBuilder[(Int, (Int, String))] 79 | for i <- 0 until spl.length 80 | do 81 | result.addOne(i -> (curOffset, spl(i))) 82 | curOffset += spl(i).length() + 1 83 | 84 | result.result().toMap 85 | end mapping 86 | 87 | def resolve(point: ts.Point): Int = 88 | mapping(point.row) match 89 | case (curOffset, _) => 90 | curOffset + point.column 91 | 92 | end Index 93 | -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/main/scalanative/TreeSitter.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight 2 | 3 | import scalanative.unsafe.* 4 | import tree_sitter.all.* 5 | import scala.scalanative.unsigned.* 6 | 7 | extension [A: Tag](p: Ptr[A]) private inline def DEREF: A = !p 8 | 9 | class TreeSitter(parser: Ptr[TSParser], language: Ptr[TSLanguage])(using 10 | z: Zone 11 | ) extends TreeSitterInterface: 12 | override opaque type Tree = Ptr[TSTree] 13 | override opaque type Point = Ptr[TSPoint] 14 | override opaque type Language = Ptr[TSLanguage] 15 | override opaque type Node = Ptr[TSNode] 16 | override opaque type Capture = Ptr[TSQueryCapture] 17 | override opaque type Match = Ptr[TSQueryMatch] 18 | override opaque type Query = Ptr[TSQuery] 19 | 20 | override inline def getLanguage = language 21 | 22 | @volatile private var langSet = false 23 | 24 | override def parse(source: String) = 25 | val str = toCString(source) 26 | if !langSet then 27 | ts_parser_set_language(parser, language) 28 | langSet = true 29 | ts_parser_parse_string( 30 | parser, 31 | null, 32 | str, 33 | scalanative.libc.string.strlen(str).toUInt 34 | ) 35 | end parse 36 | 37 | extension (t: Tree) 38 | override def rootNode = 39 | val newValue = alloc[TSNode]() 40 | ts_tree_root_node(t)(newValue) 41 | newValue 42 | 43 | extension (q: Query) 44 | override def matches(node: Node): Iterable[Match] = 45 | val builder = List.newBuilder[Match] 46 | val cursor = ts_query_cursor_new() 47 | ts_query_cursor_exec(cursor, q, node.DEREF); 48 | 49 | val mtch = stackalloc[TSQueryMatch]() 50 | var hasNext = true 51 | while { hasNext = ts_query_cursor_next_match(cursor, mtch); hasNext } do 52 | val deref = !mtch 53 | 54 | val capturesCopy = alloc[TSQueryCapture](deref.capture_count) 55 | 56 | for i <- 0 until deref.capture_count.toInt do 57 | val c = deref.captures(i) 58 | capturesCopy(i) = !tree_sitter.structs.TSQueryCapture 59 | .apply(c.node, c.index) 60 | 61 | builder += tree_sitter.structs.TSQueryMatch.apply( 62 | deref.id, 63 | deref.pattern_index, 64 | deref.capture_count, 65 | capturesCopy 66 | )(using z) 67 | end while 68 | builder.result() 69 | end extension 70 | 71 | extension (t: Match) 72 | override def captures = 73 | val builder = Array.newBuilder[Capture] 74 | 75 | for i <- 0 until t.DEREF.capture_count.toInt do 76 | val c = t.DEREF.captures(i) 77 | builder += tree_sitter.structs.TSQueryCapture 78 | .apply(c.node, c.index) 79 | 80 | builder.result() 81 | 82 | extension (t: Capture) 83 | @annotation.targetName("capture_name") 84 | override def name(q: Query) = 85 | val length = stackalloc[UInt]() 86 | val str = ts_query_capture_name_for_id(q, t.DEREF.index, length) 87 | val strZero = stackalloc[CChar](length.DEREF.toInt + 1) 88 | scalanative.libc.string.memcpy(strZero, str, !length) 89 | strZero(!length) = 0.toByte 90 | assert(str != null, "ts_query_capture_name_for_id returned null") 91 | fromCString(strZero) 92 | 93 | override def node: Node = 94 | val n = alloc[TSNode]() 95 | !n = t.DEREF.node 96 | n 97 | end extension 98 | 99 | extension (t: Node) 100 | override def children: Iterable[Node] = 101 | val children = Array.newBuilder[Node] 102 | val cnt = tree_sitter.functions.ts_node_child_count(t) 103 | for childId <- 0 until cnt.toInt do 104 | val node = alloc[TSNode]() 105 | tree_sitter.functions.ts_node_child(t, childId.toUInt)(node) 106 | children += node 107 | 108 | children.result() 109 | 110 | override def startPoint = 111 | val sp = alloc[TSPoint]() 112 | ts_node_start_point(t)(sp) 113 | sp 114 | 115 | override def endPoint = 116 | val sp = alloc[TSPoint]() 117 | ts_node_end_point(t)(sp) 118 | sp 119 | 120 | override def text(s: String) = 121 | val start = ts_node_start_byte(t).toInt 122 | val finish = ts_node_end_byte(t).toInt 123 | 124 | new String(s.getBytes().slice(start, finish)) 125 | end extension 126 | 127 | extension (p: Point) 128 | override inline def column: Int = p.DEREF.column.toInt 129 | override inline def row: Int = p.DEREF.row.toInt 130 | 131 | extension (q: Language) 132 | override def query(source: String): Query = 133 | Zone: 134 | val erroffset = stackalloc[UInt]() 135 | val err = stackalloc[TSQueryError]() 136 | val querySource = toCString(source) 137 | 138 | val query = 139 | ts_query_new( 140 | language, 141 | querySource, 142 | scalanative.libc.string.strlen(querySource).toUInt, 143 | erroffset, 144 | err 145 | ) 146 | assert((!erroffset).toInt == 0) 147 | 148 | query 149 | 150 | end TreeSitter 151 | -------------------------------------------------------------------------------- /.github/workflows/release-binary.yml: -------------------------------------------------------------------------------- 1 | name: Binary 2 | on: 3 | push: 4 | branches: ["main"] 5 | tags: ["v*"] 6 | pull_request: 7 | branches: ["*"] 8 | 9 | 10 | jobs: 11 | macos_build: 12 | name: MacOS (${{ matrix.OS }}) 13 | strategy: 14 | fail-fast: true 15 | matrix: 16 | OS: ["macos-14", "macos-13"] 17 | runs-on: ${{ matrix.OS }} 18 | steps: 19 | - uses: actions/checkout@v4 20 | with: 21 | fetch-depth: 0 22 | submodules: true 23 | 24 | - uses: actions/setup-java@v4 25 | with: 26 | distribution: 'temurin' 27 | java-version: '21' 28 | 29 | - uses: sbt/setup-sbt@v1 30 | 31 | # - name: Cache vcpkg 32 | # uses: actions/cache@v3 33 | # with: 34 | # path: | 35 | # ~/Library/Caches/sbt-vcpkg/vcpkg-install 36 | # ~/.cache/sbt-vcpkg/vcpkg-install 37 | # ~/.cache/sbt-vcpkg/vcpkg 38 | # key: ${{ matrix.OS }}-sbt-vcpkg 39 | 40 | - uses: rui314/setup-mold@v1 41 | 42 | - run: brew install llvm@17 ninja autoconf 43 | 44 | - name: Build the binary 45 | run: sbt buildPlatformBinary 46 | 47 | - name: Upload artifacts 48 | uses: actions/upload-artifact@v4 49 | with: 50 | path: out/release/* 51 | name: ${{ matrix.os }}-binaries 52 | if-no-files-found: error 53 | 54 | - run: ~/Library/Caches/sbt-vcpkg/vcpkg/buildtrees/**/*-err.log 55 | if: failure() 56 | 57 | 58 | linux_build: 59 | name: Linux 60 | runs-on: ubuntu-20.04 61 | steps: 62 | - uses: actions/checkout@v4 63 | with: 64 | fetch-depth: 0 65 | submodules: true 66 | 67 | - uses: actions/setup-java@v4 68 | with: 69 | distribution: 'temurin' 70 | java-version: '21' 71 | cache: sbt 72 | 73 | - name: Cache vcpkg 74 | uses: actions/cache@v3 75 | with: 76 | path: | 77 | ~/Library/Caches/sbt-vcpkg/vcpkg-install 78 | ~/.cache/sbt-vcpkg/vcpkg-install 79 | ~/.cache/sbt-vcpkg/vcpkg 80 | key: ${{ runner.os }}-sbt-vcpkg 81 | 82 | - uses: sbt/setup-sbt@v1 83 | 84 | - name: Build the binary 85 | run: sbt buildPlatformBinary 86 | 87 | - name: Upload artifacts 88 | uses: actions/upload-artifact@v4 89 | with: 90 | path: out/release/* 91 | name: linux-binaries 92 | if-no-files-found: error 93 | 94 | # windows_build: 95 | # name: Windows 96 | # strategy: 97 | # fail-fast: false 98 | # runs-on: windows-2019 99 | # env: 100 | # LLVM_BIN: 'C:\Program Files\LLVM\bin' 101 | # LLVM_VERSION: "17.0.6" 102 | # steps: 103 | # # This step is important to make sure scalafmt 104 | # # checks don't fail 105 | # - name: Setup git config 106 | # run: git config --global core.autocrlf false 107 | 108 | # - uses: actions/checkout@v4 109 | # with: 110 | # fetch-depth: 0 111 | # submodules: true 112 | 113 | # - uses: actions/setup-java@v4 114 | # with: 115 | # distribution: 'temurin' 116 | # java-version: '21' 117 | # cache: sbt 118 | 119 | # - uses: sbt/setup-sbt@v1 120 | 121 | # # See https://github.com/scala-native/scala-native/blob/master/.github/actions/windows-setup-env/action.yml#L14 SN_RELE 122 | # # for details 123 | # - name: Configure Pagefile 124 | # uses: al-cheb/configure-pagefile-action@v1.2 125 | # with: 126 | # minimum-size: 4GB 127 | # maximum-size: 16GB 128 | 129 | # - run: clang -v 130 | # shell: cmd 131 | 132 | # - name: Install clang and SBT 133 | # shell: pwsh 134 | # run: | 135 | # choco install llvm --version="$Env:LLVM_VERSION" --allow-downgrade 136 | # choco install sbt --version=1.10.0 137 | # clang --version 138 | 139 | # - name: Build binary (windows) 140 | # run: sbt buildPlatformBinary 141 | # shell: cmd 142 | 143 | # - name: Upload artifacts 144 | # uses: actions/upload-artifact@v4 145 | # with: 146 | # path: out/release/* 147 | # name: windows-binaries 148 | # if-no-files-found: error 149 | 150 | mergify-build-checkpoint: 151 | runs-on: ubuntu-latest 152 | # needs: [linux_build, windows_build, macos_build] 153 | needs: [linux_build, macos_build] 154 | steps: 155 | - name: I only exist to please Mergify :( 156 | run: echo "It's a sad existence but necessary" 157 | 158 | release: 159 | if: startsWith(github.ref, 'refs/tags/v') 160 | # needs: [linux_build, windows_build, macos_build] 161 | needs: [linux_build, macos_build] 162 | name: Upload binaries to release 163 | runs-on: ubuntu-20.04 164 | steps: 165 | - uses: actions/checkout@v4 166 | with: 167 | fetch-depth: 0 168 | submodules: true 169 | 170 | - name: Download binaries 171 | uses: actions/download-artifact@v4 172 | id: download 173 | with: 174 | path: binaries 175 | 176 | - name: List downloaded binaries 177 | run: ls -R binaries 178 | 179 | - name: Upload release binaries 180 | uses: softprops/action-gh-release@v1 181 | if: startsWith(github.ref, 'refs/tags/') 182 | with: 183 | files: "${{steps.download.outputs.download-path}}/**/*" 184 | -------------------------------------------------------------------------------- /mod/lib/src/main/scala/Lib.scala: -------------------------------------------------------------------------------- 1 | package scala_highlight.lib 2 | 3 | import scalanative.unsafe.* 4 | import ts_highlight.* 5 | import tree_sitter.structs.TSLanguage 6 | import scala.util.Using 7 | import java.io.FileWriter 8 | import java.io.File 9 | import java.nio.file.Path 10 | import ts_highlight.themes.CaptureGroup 11 | import ts_highlight.themes.{Theme, CaptureGroup}, Theme.* 12 | import java.io.ByteArrayOutputStream 13 | import scala_highlight.lib.Resources.QUERIES 14 | 15 | def tree_sitter_scala(): Ptr[TSLanguage] = extern 16 | 17 | def highlight_markdown_file( 18 | code: String, 19 | out: Option[Path], 20 | theme: Option[Theme] = None 21 | ) = 22 | import cmark.all.*, scalanative.libc 23 | Zone: 24 | val str = toCString(code) 25 | 26 | val node = cmark_parse_document(str, libc.string.strlen(str), 0) 27 | 28 | val lines = code.linesIterator.toList 29 | 30 | val parser = tree_sitter.all.ts_parser_new() 31 | val lang = tree_sitter_scala() 32 | 33 | val ts = TreeSitter(parser, lang) 34 | 35 | val mentionedGroups = collection.mutable.Set.empty[CaptureGroup] 36 | 37 | def iterateNodes(node: Ptr[cmark_node]) = 38 | val cuts = List.newBuilder[(Int, Int, Array[String])] 39 | def go(nd: Ptr[cmark_node]): Unit = 40 | val iter = cmark_iter_new(nd) 41 | var ev_type: cmark_event_type = cmark_event_type.CMARK_EVENT_NONE 42 | 43 | while { 44 | ev_type = cmark_iter_next(iter); ev_type 45 | } != cmark_event_type.CMARK_EVENT_DONE 46 | do 47 | val cur = cmark_iter_get_node(iter) 48 | val tpe = 49 | cmark_node_get_type(cur) == cmark_node_type.CMARK_NODE_CODE_BLOCK 50 | 51 | if tpe then 52 | val fence = 53 | fromCString(cmark_node_get_fence_info(cur)).split(" ").toList 54 | val code = 55 | fromCString(cmark_node_get_literal(cur)) 56 | 57 | val shouldReplace = 58 | fence match 59 | case List("scala") => true 60 | case List("scala", "mdoc") => true 61 | case List("scala", "mdoc:compile-only") => true 62 | case List("scala", "mdoc:reset") => true 63 | case List("scala", "mdoc:passthrough") => false 64 | case List("scala", "mdoc:nest:passthrough") => false 65 | case _ => false 66 | 67 | if shouldReplace then 68 | val lineStart = cmark_node_get_start_line(cur) - 1 69 | val columnStart = cmark_node_get_start_column(cur) - 1 70 | val lineEnd = cmark_node_get_end_line(cur) - 1 71 | val highlight = HighlightTokenizer(code, Resources.QUERIES, ts) 72 | 73 | val indent = " " * (columnStart + 1) 74 | 75 | val builder = new StringBuilder 76 | builder.addAll("\n\n" + indent + "
")
 77 | 
 78 |               highlight.tokens.foreach: tok =>
 79 |                 tok.kind.foreach: k =>
 80 |                   CaptureGroup.fromString(k).foreach(mentionedGroups += _)
 81 | 
 82 |                 builder.addAll(
 83 |                   s"${code
 84 |                       .slice(tok.start, tok.finish)}"
 85 |                 )
 86 | 
 87 |               builder.addAll(s"
\n\n") 88 | 89 | cuts.addOne( 90 | lineStart, 91 | lineEnd, 92 | builder.result().linesIterator.toArray 93 | ) 94 | end if 95 | end if 96 | 97 | end while 98 | 99 | end go 100 | 101 | go(node) 102 | cuts.result() 103 | end iterateNodes 104 | 105 | val cuts = iterateNodes(node).sortBy(_._1).toArray 106 | var currentCutIdx = 0 107 | inline def currentCut = cuts(currentCutIdx) 108 | val content = List.newBuilder[String] 109 | lines.zipWithIndex.foreach: (line, idx) => 110 | if currentCutIdx <= cuts.length - 1 then 111 | if idx < currentCut._1 then content += line 112 | else if idx == currentCut._1 then content.addAll(currentCut._3) 113 | else if idx == currentCut._2 then currentCutIdx += 1 114 | else content += line 115 | 116 | val result = 117 | content.result().mkString(System.lineSeparator()) + theme 118 | .map(t => "\n\n" + Theme.buildCSS(t, mentionedGroups.toSet)) 119 | .map(s => 120 | s"\n\n\n\n" 121 | ) 122 | .getOrElse("") 123 | 124 | out match 125 | case None => Some(result) 126 | case Some(path) => 127 | Using.resource(FileWriter(path.toFile())): f => 128 | f.write(result) 129 | None 130 | end highlight_markdown_file 131 | 132 | def highlight_scala_snippet(snippet: String) = 133 | Zone: 134 | val parser = tree_sitter.all.ts_parser_new() 135 | val lang = tree_sitter_scala() 136 | val ts = TreeSitter(parser, lang) 137 | val highlight = HighlightTokenizer(snippet, QUERIES, ts) 138 | 139 | highlight.tokens 140 | 141 | object Resources: 142 | lazy val QUERIES = io.Source 143 | .fromInputStream(getClass().getResourceAsStream("/highlights.scm")) 144 | .getLines() 145 | .mkString(System.lineSeparator()) 146 | 147 | lazy val FONT: Array[Byte] = 148 | val is = getClass().getResourceAsStream("/cairo.ttf") 149 | val boas = new ByteArrayOutputStream 150 | try 151 | val buffer = Array.ofDim[Byte](1024) 152 | var bytesRead: Int = 0 153 | 154 | while { bytesRead = is.read(buffer); bytesRead != -1 } do 155 | boas.write(buffer, 0, bytesRead); 156 | 157 | boas.toByteArray() 158 | finally is.close() 159 | end try 160 | end FONT 161 | end Resources 162 | -------------------------------------------------------------------------------- /mod/lib/src/main/scala/ImageGenerator.scala: -------------------------------------------------------------------------------- 1 | package scala_highlight.lib 2 | 3 | import ts_highlight.HighlightToken 4 | 5 | import cairo.all.* 6 | import scalanative.unsafe.*, scalanative.unsigned.* 7 | import ts_highlight.themes.* 8 | import ts_highlight.themes.Theme.Container 9 | 10 | extension (c: Ptr[cairo_t]) 11 | def setColor(col: Color) = 12 | cairo_set_source_rgb( 13 | c, 14 | col.r.toDouble / 255d, 15 | col.g.toDouble / 255d, 16 | col.b.toDouble / 255d 17 | ) 18 | def setColor(col: Color, alpha: Double) = 19 | cairo_set_source_rgba( 20 | c, 21 | col.r.toDouble / 255d, 22 | col.g.toDouble / 255d, 23 | col.b.toDouble / 255d, 24 | alpha 25 | ) 26 | end extension 27 | 28 | def generate_image( 29 | contents: String, 30 | tokens: List[HighlightToken], 31 | theme: Theme, 32 | out: String, 33 | FONT_SIZE: Int = 50, 34 | PADDING: Int = 50 35 | ) = 36 | val freetypeLibrary = stackalloc[FT_Library]() 37 | assert(FT_Init_FreeType(freetypeLibrary).value == 0) 38 | 39 | val freetypeFace = stackalloc[FT_Face]() 40 | check( 41 | FT_New_Memory_Face( 42 | !freetypeLibrary, 43 | Resources.FONT.at(0).asInstanceOf[Ptr[FT_Byte]], 44 | FT_Long(Resources.FONT.length.toSize), 45 | FT_Long(0L.toSize), 46 | freetypeFace 47 | ) 48 | ) 49 | 50 | check( 51 | FT_Set_Pixel_Sizes( 52 | !freetypeFace, 53 | FT_UInt(FONT_SIZE.toUInt), 54 | FT_UInt(FONT_SIZE.toUInt) 55 | ) 56 | ) 57 | 58 | val surface = 59 | cairo_image_surface_create(_cairo_format.CAIRO_FORMAT_ARGB32, 4096, 4096) 60 | 61 | val cairo = cairo_create(surface) 62 | val cairoFreetypeFace = 63 | cairo_ft_font_face_create_for_ft_face(!freetypeFace, 0) 64 | 65 | cairo_set_font_face(cairo, cairoFreetypeFace) 66 | cairo_set_font_size(cairo, FONT_SIZE) 67 | 68 | val summary = size_text(cairo, contents, tokens, 20f, theme) 69 | 70 | Zone: 71 | summary.tokens.foreach: token => 72 | cairo.setColor(token.color) 73 | cairo_move_to(cairo, PADDING + token.x, PADDING + token.y) 74 | cairo_show_text(cairo, toCString(token.str)) 75 | 76 | val width = PADDING + summary.width + PADDING 77 | val height = PADDING + summary.height + PADDING 78 | 79 | val newSurface = 80 | cairo_image_surface_create( 81 | _cairo_format.CAIRO_FORMAT_ARGB32, 82 | width.toInt, 83 | height.toInt 84 | ) 85 | 86 | val newCairo = cairo_create(newSurface) 87 | 88 | newCairo.setColor(rgb"#000000", 0.0) 89 | cairo_rectangle(newCairo, 0, 0, width, height) 90 | cairo_fill(newCairo) 91 | 92 | val bgColor = theme 93 | .lift(Container) 94 | .flatMap(_.background) 95 | rounded_rectangle(0, 0, width, height, 25.0, bgColor, newCairo) 96 | 97 | cairo_set_source_surface(newCairo, surface, 0, 0) 98 | 99 | cairo_paint(newCairo) 100 | 101 | Zone: 102 | cairo_surface_write_to_png(newSurface, toCString(out)) 103 | 104 | end generate_image 105 | 106 | case class Summary( 107 | width: Double, 108 | height: Double, 109 | tokens: List[PositionedToken] 110 | ) 111 | case class PositionedToken(str: String, x: Double, y: Double, color: Color): 112 | override def toString(): String = s"[`$str` at x=$x, y=$y]" 113 | 114 | def rounded_rectangle( 115 | x: Double, 116 | y: Double, 117 | width: Double, 118 | height: Double, 119 | corner_radius: Double, 120 | color: Option[Color], 121 | cr: Ptr[cairo_t] 122 | ) = 123 | 124 | val aspect = 1.0 125 | val radius = corner_radius / aspect 126 | val degrees = Math.PI / 180.0 127 | 128 | cairo_new_sub_path(cr); 129 | cairo_arc( 130 | cr, 131 | x + width - radius, 132 | y + radius, 133 | radius, 134 | -90 * degrees, 135 | 0 * degrees 136 | ); 137 | cairo_arc( 138 | cr, 139 | x + width - radius, 140 | y + height - radius, 141 | radius, 142 | 0 * degrees, 143 | 90 * degrees 144 | ); 145 | cairo_arc( 146 | cr, 147 | x + radius, 148 | y + height - radius, 149 | radius, 150 | 90 * degrees, 151 | 180 * degrees 152 | ); 153 | cairo_arc(cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees); 154 | cairo_close_path(cr); 155 | 156 | // cairo_set_source_rgb(cr, 0.5, 0.5, 1); 157 | color.foreach: color => 158 | cr.setColor(color) 159 | cairo_fill(cr) 160 | // cairo_set_source_rgba(cr, 0.5, 0, 0, 0.5); 161 | // cairo_set_line_width(cr, 10.0); 162 | // cairo_stroke(cr) 163 | end rounded_rectangle 164 | 165 | def size_text( 166 | cairo: Ptr[cairo_t], 167 | str: String, 168 | tokens: List[HighlightToken], 169 | lineSpacing: Float, 170 | theme: Theme 171 | ): Summary = 172 | val extents = stackalloc[cairo_text_extents_t]() 173 | val baseExtents = stackalloc[cairo_text_extents_t]() 174 | 175 | var width = 0.0 176 | var height = 0.0 177 | 178 | val positionedTokens = List.newBuilder[PositionedToken] 179 | 180 | val baseLine = c"P" 181 | 182 | val fallbackColor = theme(Container).text.getOrElse(rgb"#ffffff") 183 | var lineWidth = 0.0 184 | 185 | cairo_text_extents( 186 | cairo, 187 | baseLine, 188 | baseExtents 189 | ) 190 | 191 | inline def handleToken(text: String, color: Color)(using Zone) = 192 | cairo_text_extents(cairo, toCString(text.replace(' ', '@')), extents) 193 | 194 | if text.trim.nonEmpty then 195 | positionedTokens += PositionedToken( 196 | text, 197 | x = lineWidth, 198 | y = height, 199 | color = color 200 | ) 201 | lineWidth += ((!extents).width).max((!baseExtents).width * text.length) 202 | else lineWidth += text.count(_.isWhitespace) * (!baseExtents).width 203 | end handleToken 204 | 205 | extension (d: String) 206 | def splitWithDelimiters(s: Char) = 207 | val sb = new StringBuilder 208 | val segments = List.newBuilder[String] 209 | val ds = s.toString 210 | d.foreach: c => 211 | if c == s then 212 | if sb.length != 0 then 213 | segments += sb.result 214 | sb.clear() 215 | end if 216 | segments += ds 217 | else sb.addOne(c) 218 | 219 | if sb.length > 0 then segments += sb.result 220 | 221 | segments.result 222 | 223 | Zone: 224 | tokens.foreach: token => 225 | val cg = token.kind.flatMap(CaptureGroup.fromString) 226 | val color = 227 | cg.flatMap(theme.lift.apply).flatMap(_.text).getOrElse(fallbackColor) 228 | val text = str.slice(token.start, token.finish) 229 | 230 | text 231 | .splitWithDelimiters('\n') 232 | .foreach: 233 | case "\n" => 234 | width = width.max(lineWidth) 235 | height += (!baseExtents).height + lineSpacing 236 | lineWidth = 0 237 | case other => 238 | handleToken(other, color) 239 | 240 | Summary(width, height, positionedTokens.result()) 241 | end size_text 242 | -------------------------------------------------------------------------------- /mod/treesitter-bindings/src/main/resources/scala-native/generated/tree_sitter.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "tree_sitter/api.h" 3 | 4 | void __sn_wrap_tree_sitter_ts_node_child(TSNode *_0, uint32_t _1, TSNode *____return) { 5 | TSNode ____ret = ts_node_child(*_0, _1); 6 | memcpy(____return, &____ret, sizeof(TSNode)); 7 | } 8 | 9 | 10 | void __sn_wrap_tree_sitter_ts_node_child_by_field_id(TSNode *_0, TSFieldId _1, TSNode *____return) { 11 | TSNode ____ret = ts_node_child_by_field_id(*_0, _1); 12 | memcpy(____return, &____ret, sizeof(TSNode)); 13 | } 14 | 15 | 16 | void __sn_wrap_tree_sitter_ts_node_child_by_field_name(TSNode *self, const char * field_name, uint32_t field_name_length, TSNode *____return) { 17 | TSNode ____ret = ts_node_child_by_field_name(*self, field_name, field_name_length); 18 | memcpy(____return, &____ret, sizeof(TSNode)); 19 | } 20 | 21 | 22 | uint32_t __sn_wrap_tree_sitter_ts_node_child_count(TSNode *_0) { 23 | return ts_node_child_count(*_0); 24 | }; 25 | 26 | 27 | void __sn_wrap_tree_sitter_ts_node_descendant_for_byte_range(TSNode *_0, uint32_t _1, uint32_t _2, TSNode *____return) { 28 | TSNode ____ret = ts_node_descendant_for_byte_range(*_0, _1, _2); 29 | memcpy(____return, &____ret, sizeof(TSNode)); 30 | } 31 | 32 | 33 | void __sn_wrap_tree_sitter_ts_node_descendant_for_point_range(TSNode *_0, TSPoint *_1, TSPoint *_2, TSNode *____return) { 34 | TSNode ____ret = ts_node_descendant_for_point_range(*_0, *_1, *_2); 35 | memcpy(____return, &____ret, sizeof(TSNode)); 36 | } 37 | 38 | 39 | uint32_t __sn_wrap_tree_sitter_ts_node_end_byte(TSNode *_0) { 40 | return ts_node_end_byte(*_0); 41 | }; 42 | 43 | 44 | void __sn_wrap_tree_sitter_ts_node_end_point(TSNode *_0, TSPoint *____return) { 45 | TSPoint ____ret = ts_node_end_point(*_0); 46 | memcpy(____return, &____ret, sizeof(TSPoint)); 47 | } 48 | 49 | 50 | _Bool __sn_wrap_tree_sitter_ts_node_eq(TSNode *_0, TSNode *_1) { 51 | return ts_node_eq(*_0, *_1); 52 | }; 53 | 54 | 55 | const char * __sn_wrap_tree_sitter_ts_node_field_name_for_child(TSNode *_0, uint32_t _1) { 56 | return ts_node_field_name_for_child(*_0, _1); 57 | }; 58 | 59 | 60 | void __sn_wrap_tree_sitter_ts_node_first_child_for_byte(TSNode *_0, uint32_t _1, TSNode *____return) { 61 | TSNode ____ret = ts_node_first_child_for_byte(*_0, _1); 62 | memcpy(____return, &____ret, sizeof(TSNode)); 63 | } 64 | 65 | 66 | void __sn_wrap_tree_sitter_ts_node_first_named_child_for_byte(TSNode *_0, uint32_t _1, TSNode *____return) { 67 | TSNode ____ret = ts_node_first_named_child_for_byte(*_0, _1); 68 | memcpy(____return, &____ret, sizeof(TSNode)); 69 | } 70 | 71 | 72 | _Bool __sn_wrap_tree_sitter_ts_node_has_changes(TSNode *_0) { 73 | return ts_node_has_changes(*_0); 74 | }; 75 | 76 | 77 | _Bool __sn_wrap_tree_sitter_ts_node_has_error(TSNode *_0) { 78 | return ts_node_has_error(*_0); 79 | }; 80 | 81 | 82 | _Bool __sn_wrap_tree_sitter_ts_node_is_extra(TSNode *_0) { 83 | return ts_node_is_extra(*_0); 84 | }; 85 | 86 | 87 | _Bool __sn_wrap_tree_sitter_ts_node_is_missing(TSNode *_0) { 88 | return ts_node_is_missing(*_0); 89 | }; 90 | 91 | 92 | _Bool __sn_wrap_tree_sitter_ts_node_is_named(TSNode *_0) { 93 | return ts_node_is_named(*_0); 94 | }; 95 | 96 | 97 | _Bool __sn_wrap_tree_sitter_ts_node_is_null(TSNode *_0) { 98 | return ts_node_is_null(*_0); 99 | }; 100 | 101 | 102 | void __sn_wrap_tree_sitter_ts_node_named_child(TSNode *_0, uint32_t _1, TSNode *____return) { 103 | TSNode ____ret = ts_node_named_child(*_0, _1); 104 | memcpy(____return, &____ret, sizeof(TSNode)); 105 | } 106 | 107 | 108 | uint32_t __sn_wrap_tree_sitter_ts_node_named_child_count(TSNode *_0) { 109 | return ts_node_named_child_count(*_0); 110 | }; 111 | 112 | 113 | void __sn_wrap_tree_sitter_ts_node_named_descendant_for_byte_range(TSNode *_0, uint32_t _1, uint32_t _2, TSNode *____return) { 114 | TSNode ____ret = ts_node_named_descendant_for_byte_range(*_0, _1, _2); 115 | memcpy(____return, &____ret, sizeof(TSNode)); 116 | } 117 | 118 | 119 | void __sn_wrap_tree_sitter_ts_node_named_descendant_for_point_range(TSNode *_0, TSPoint *_1, TSPoint *_2, TSNode *____return) { 120 | TSNode ____ret = ts_node_named_descendant_for_point_range(*_0, *_1, *_2); 121 | memcpy(____return, &____ret, sizeof(TSNode)); 122 | } 123 | 124 | 125 | void __sn_wrap_tree_sitter_ts_node_next_named_sibling(TSNode *_0, TSNode *____return) { 126 | TSNode ____ret = ts_node_next_named_sibling(*_0); 127 | memcpy(____return, &____ret, sizeof(TSNode)); 128 | } 129 | 130 | 131 | void __sn_wrap_tree_sitter_ts_node_next_sibling(TSNode *_0, TSNode *____return) { 132 | TSNode ____ret = ts_node_next_sibling(*_0); 133 | memcpy(____return, &____ret, sizeof(TSNode)); 134 | } 135 | 136 | 137 | void __sn_wrap_tree_sitter_ts_node_parent(TSNode *_0, TSNode *____return) { 138 | TSNode ____ret = ts_node_parent(*_0); 139 | memcpy(____return, &____ret, sizeof(TSNode)); 140 | } 141 | 142 | 143 | void __sn_wrap_tree_sitter_ts_node_prev_named_sibling(TSNode *_0, TSNode *____return) { 144 | TSNode ____ret = ts_node_prev_named_sibling(*_0); 145 | memcpy(____return, &____ret, sizeof(TSNode)); 146 | } 147 | 148 | 149 | void __sn_wrap_tree_sitter_ts_node_prev_sibling(TSNode *_0, TSNode *____return) { 150 | TSNode ____ret = ts_node_prev_sibling(*_0); 151 | memcpy(____return, &____ret, sizeof(TSNode)); 152 | } 153 | 154 | 155 | uint32_t __sn_wrap_tree_sitter_ts_node_start_byte(TSNode *_0) { 156 | return ts_node_start_byte(*_0); 157 | }; 158 | 159 | 160 | void __sn_wrap_tree_sitter_ts_node_start_point(TSNode *_0, TSPoint *____return) { 161 | TSPoint ____ret = ts_node_start_point(*_0); 162 | memcpy(____return, &____ret, sizeof(TSPoint)); 163 | } 164 | 165 | 166 | char * __sn_wrap_tree_sitter_ts_node_string(TSNode *_0) { 167 | return ts_node_string(*_0); 168 | }; 169 | 170 | 171 | TSSymbol __sn_wrap_tree_sitter_ts_node_symbol(TSNode *_0) { 172 | return ts_node_symbol(*_0); 173 | }; 174 | 175 | 176 | const char * __sn_wrap_tree_sitter_ts_node_type(TSNode *_0) { 177 | return ts_node_type(*_0); 178 | }; 179 | 180 | 181 | void __sn_wrap_tree_sitter_ts_parser_logger(const TSParser * self, TSLogger *____return) { 182 | TSLogger ____ret = ts_parser_logger(self); 183 | memcpy(____return, &____ret, sizeof(TSLogger)); 184 | } 185 | 186 | 187 | TSTree * __sn_wrap_tree_sitter_ts_parser_parse(TSParser * self, const TSTree * old_tree, TSInput *input) { 188 | return ts_parser_parse(self, old_tree, *input); 189 | }; 190 | 191 | 192 | void __sn_wrap_tree_sitter_ts_parser_set_logger(TSParser * self, TSLogger *logger) { 193 | ts_parser_set_logger(self, *logger); 194 | }; 195 | 196 | 197 | void __sn_wrap_tree_sitter_ts_query_cursor_exec(TSQueryCursor * _0, const TSQuery * _1, TSNode *_2) { 198 | ts_query_cursor_exec(_0, _1, *_2); 199 | }; 200 | 201 | 202 | void __sn_wrap_tree_sitter_ts_query_cursor_set_point_range(TSQueryCursor * _0, TSPoint *_1, TSPoint *_2) { 203 | ts_query_cursor_set_point_range(_0, *_1, *_2); 204 | }; 205 | 206 | 207 | void __sn_wrap_tree_sitter_ts_tree_cursor_copy(const TSTreeCursor * _0, TSTreeCursor *____return) { 208 | TSTreeCursor ____ret = ts_tree_cursor_copy(_0); 209 | memcpy(____return, &____ret, sizeof(TSTreeCursor)); 210 | } 211 | 212 | 213 | void __sn_wrap_tree_sitter_ts_tree_cursor_current_node(const TSTreeCursor * _0, TSNode *____return) { 214 | TSNode ____ret = ts_tree_cursor_current_node(_0); 215 | memcpy(____return, &____ret, sizeof(TSNode)); 216 | } 217 | 218 | 219 | int64_t __sn_wrap_tree_sitter_ts_tree_cursor_goto_first_child_for_point(TSTreeCursor * _0, TSPoint *_1) { 220 | return ts_tree_cursor_goto_first_child_for_point(_0, *_1); 221 | }; 222 | 223 | 224 | void __sn_wrap_tree_sitter_ts_tree_cursor_new(TSNode *_0, TSTreeCursor *____return) { 225 | TSTreeCursor ____ret = ts_tree_cursor_new(*_0); 226 | memcpy(____return, &____ret, sizeof(TSTreeCursor)); 227 | } 228 | 229 | 230 | void __sn_wrap_tree_sitter_ts_tree_cursor_reset(TSTreeCursor * _0, TSNode *_1) { 231 | ts_tree_cursor_reset(_0, *_1); 232 | }; 233 | 234 | 235 | void __sn_wrap_tree_sitter_ts_tree_root_node(const TSTree * self, TSNode *____return) { 236 | TSNode ____ret = ts_tree_root_node(self); 237 | memcpy(____return, &____ret, sizeof(TSNode)); 238 | } -------------------------------------------------------------------------------- /mod/themes/src/main/scala/Theme.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight.themes 2 | 3 | import ts_highlight.* 4 | 5 | import Theme.Container 6 | 7 | trait Theme extends PartialFunction[CaptureGroup | Container, Style] 8 | 9 | enum Decorator: 10 | case Underline, Bold 11 | 12 | def toCSS: String = this match 13 | case Underline => "text-decoration: underline" 14 | case Bold => "font-weight: bold" 15 | 16 | case class Style( 17 | background: Option[Color] = None, 18 | text: Option[Color] = None, 19 | decoration: Set[Decorator] = Set.empty 20 | ): 21 | def underline = copy(decoration = decoration + Decorator.Underline) 22 | 23 | def toCSS: String = 24 | inline def color(c: Color) = s"rgb(${c.r}, ${c.g}, ${c.b})" 25 | (background.map(c => s"background: ${color(c)}").toSeq ++ 26 | text.map(c => s"color: ${color(c)}").toSeq ++ 27 | decoration.toSeq.map(_.toCSS)).mkString("; ") 28 | end Style 29 | 30 | extension (c: Color) 31 | inline def background = Style(background = Some(c)) 32 | inline def text = Style(text = Some(c)) 33 | 34 | object Theme: 35 | def apply(f: PartialFunction[CaptureGroup | Container, Style]): Theme = 36 | new Theme: 37 | // export f.{apply, isDefinedAt} 38 | override def apply(v1: CaptureGroup | Container): Style = if isDefinedAt(v1) then f(v1) else sys.error(s"Match error! $v1") 39 | override def isDefinedAt(x: CaptureGroup | Container): Boolean = f.isDefinedAt(x) 40 | 41 | opaque type Container = Unit 42 | val Container: Container = () 43 | 44 | def fromString(s: String): Option[Theme] = s.trim.toLowerCase() match 45 | case "kanagawa" => Some(Kanagawa) 46 | case "gruvbox" => Some(Gruvbox) 47 | case "vscode" => Some(VSCode) 48 | case "vscode-light" => Some(LightVSCode) 49 | case _ => Option.empty 50 | 51 | import CaptureGroup.* 52 | 53 | val LightVSCode: Theme = apply: 54 | case Container => 55 | rgb"255,255,255".background.copy(text = Some(rgb"0,0,0")) 56 | case Function => rgb"121,94,38".text 57 | case Keyword | KeywordFunction | Repeat | Conditional | KeywordOperator | 58 | KeywordReturn => 59 | rgb"0,0,255".text 60 | case Storageclass => 61 | rgb"0,0,255".text.underline 62 | case TypeQualifier => 63 | rgb"0,0,255".text.underline 64 | case PunctuationBracket | PunctuationDelimiter | PunctuationSpecial => 65 | rgb"0,0,0".text 66 | case Type => rgb"38,127,153".text 67 | case String => rgb"163,21,21".text 68 | case FunctionCall | MethodCall => rgb"121,94,38".text 69 | case Number | Float => rgb"9,134,88".text 70 | case Operator => rgb"0,0,0".text 71 | case Parameter => rgb"0,16,128".text 72 | case Include => rgb"0,0,255".text 73 | case Namespace => rgb"38,127,153".text 74 | case Property => rgb"0,16,128".text 75 | case Spell => rgb"96,139,78".text 76 | case Variable => rgb"0,16,128".text 77 | case Method => rgb"121,94,38".text 78 | case Boolean => rgb"9,134,88".text 79 | case TypeDefinition => rgb"38,127,153".text 80 | 81 | val VSCode: Theme = apply: 82 | case Container => 83 | rgb"30,30,30".background.copy(text = Some(rgb"212,212,212")) 84 | case Function => rgb"220,220,170".text 85 | case Keyword | KeywordFunction | Repeat | Conditional | KeywordOperator | 86 | KeywordReturn => 87 | rgb"197,134,192".text 88 | case Storageclass => 89 | rgb"86,156,214".text.underline 90 | case TypeQualifier => 91 | rgb"86,156,214".text.underline 92 | case PunctuationBracket | PunctuationDelimiter | PunctuationDelimiter => 93 | rgb"212,212,212".text 94 | case Type => rgb"78,201,176".text 95 | case String => rgb"206,145,120".text 96 | case FunctionCall | MethodCall => rgb"220,220,170".text 97 | case Number | Float => rgb"181,206,168".text 98 | case Operator => rgb"212,212,212".text 99 | case Parameter => rgb"156,220,254".text 100 | case Include => rgb"197,134,192".text 101 | case Namespace => rgb"78,201,176".text 102 | case Property => rgb"156,220,254".text 103 | case Spell => rgb"106,153,85".text 104 | case Variable => rgb"156,220,254".text 105 | case Method => rgb"220,220,170".text 106 | case Boolean => rgb"181,206,168".text 107 | case TypeDefinition => rgb"78,201,176".text 108 | 109 | val Gruvbox: Theme = apply: 110 | case Container => 111 | rgb"40,40,40".background.copy(text = Some(rgb"213,196,161")) 112 | case Function => rgb"184,187,38".text 113 | case Keyword | KeywordFunction | Repeat | Conditional | KeywordOperator | 114 | KeywordReturn => 115 | rgb"251,73,52".text 116 | case Storageclass => 117 | rgb"251,73,52".text.underline 118 | case TypeQualifier => 119 | rgb"251,73,52".text.underline 120 | case PunctuationBracket => 121 | rgb"168,153,132".text 122 | case PunctuationSpecial | PunctuationBracket | PunctuationDelimiter => 123 | rgb"254,128,25".text 124 | case Type => rgb"250,189,47".text 125 | case String => rgb"184,187,38".text 126 | case FunctionCall | MethodCall => rgb"184,187,38".text 127 | case Number => rgb"211,134,155".text 128 | case Operator => rgb"251,73,52".text 129 | case Parameter => rgb"213,196,161".text 130 | case Include => rgb"254,128,25".text 131 | case Namespace => rgb"250,189,47".text 132 | case Property => rgb"254,128,25".text 133 | case Spell => rgb"146,131,116".text 134 | case Variable => rgb"213,196,161".text 135 | case Method => rgb"184,187,38".text 136 | case Boolean => rgb"184,187,38".text 137 | 138 | val Kanagawa: Theme = apply: 139 | case Container => 140 | rgb"28,30,39".background.copy(text = Some(rgb"192,202,245")) 141 | case Function => rgb"122,162,247".text 142 | case Keyword | KeywordFunction | Repeat | Conditional | KeywordOperator | 143 | KeywordReturn => 144 | rgb"149,127,184".text 145 | case Storageclass => 146 | rgb"149,127,184".text.underline 147 | case TypeQualifier => 148 | rgb"149,127,184".text.underline 149 | case PunctuationBracket | PunctuationSpecial | PunctuationDelimiter => 150 | rgb"192,202,245".text 151 | case Type | TypeDefinition => rgb"122,168,159".text 152 | case String => rgb"152,187,108".text 153 | case FunctionCall | MethodCall => rgb"122,162,247".text 154 | case Number | Float => rgb"255,160,102".text 155 | case Operator => rgb"192,202,245".text 156 | case Parameter => rgb"192,202,245".text 157 | case Include => rgb"227,113,126".text 158 | case Namespace => rgb"122,168,159".text 159 | case Property => rgb"234,193,128".text 160 | case Spell => rgb"86,95,137".text 161 | case Variable => rgb"192,202,245".text 162 | case Method => rgb"122,162,247".text 163 | case Boolean => rgb"255,160,102".text 164 | 165 | def buildCSS(theme: Theme, mentioned: Set[CaptureGroup]) = 166 | val sb = new StringBuilder 167 | val f = theme.lift 168 | 169 | f(Container).foreach: block => 170 | sb ++= s"pre.ts-hl { \n${block.toCSS}\n}\n" 171 | 172 | mentioned.toList 173 | .sortBy(_.name) 174 | .foreach: cg => 175 | f(cg).foreach: block => 176 | sb ++= s".ts-hl-${cg.name.replace('.', '-')} {\n" 177 | sb ++= block.toCSS 178 | sb ++= "\n}\n" 179 | 180 | sb.result() 181 | end buildCSS 182 | end Theme 183 | -------------------------------------------------------------------------------- /webapp/src/main/scala/Webapp.scala: -------------------------------------------------------------------------------- 1 | package ts_highlight.webapp 2 | 3 | import com.raquo.laminar.api.L.* 4 | import org.scalajs.dom.* 5 | 6 | import scalajs.js 7 | import js.annotation.* 8 | import js.Array as Arr 9 | 10 | import ts_highlight.* 11 | import ts_highlight.themes.Theme 12 | import ts_highlight.themes.CaptureGroup 13 | import com.raquo.airstream.web.WebStorageVar 14 | 15 | @js.native @JSImport("/tree-sitter-scala.wasm?init&url", JSImport.Default) 16 | val imgUrl: String = js.native 17 | 18 | @js.native @JSImport("/highlights.scm?raw", JSImport.Default) 19 | val highlightQueries: String = js.native 20 | 21 | @js.native @JSImport( 22 | "web-tree-sitter/tree-sitter.wasm?init&url", 23 | JSImport.Default 24 | ) 25 | val wasmInit: String = js.native 26 | 27 | def show(n: Parser.Node) = 28 | import n.* 29 | s"Node[${startPosition.row},${startPosition.column} -> ${endPosition.row},${endPosition.column}]" 30 | 31 | extension [T <: js.Any](t: T) def dump() = console.log(t) 32 | 33 | def codeMirrorTextArea(target: Var[String]) = 34 | textArea( 35 | cls := "h-full", 36 | onInput.mapToValue --> target, 37 | value <-- target, 38 | onMountCallback(el => 39 | CodeMirror 40 | .fromTextArea( 41 | el.thisNode.ref, 42 | js.Dictionary( 43 | "value" -> target.now(), 44 | "lineNumbers" -> true, 45 | "mode" -> "text/x-scala" 46 | ) 47 | ) 48 | .on("change", value => target.set(value.getValue())) 49 | ) 50 | ) 51 | 52 | def app(treesitter: TreeSitter) = 53 | val lang = treesitter.getLanguage 54 | val codeVar = WebStorageVar 55 | .localStorage("syntax-highlighter-code", None) 56 | .text(SAMPLE_CODE) 57 | val annotatedCodeVar = Var("") 58 | val debugToggled = Var(false) 59 | val injectCSS = document.getElementById("inject") 60 | val theme = WebStorageVar.localStorage("theme", None).text("kanagawa") 61 | val showHLJS = 62 | WebStorageVar.localStorage("show-highlightjs", None).bool(false) 63 | 64 | def opt(v: String, label: String) = 65 | option(value := v, label, selected <-- theme.signal.map(_ == v)) 66 | 67 | val basicLink = 68 | cls := "text-indigo-600 hover:no-underline underline" 69 | 70 | val header = div( 71 | cls := "flex flex-col gap-4", 72 | h1("Scala code highlighter", cls := "text-4xl"), 73 | p( 74 | cls := "text-md", 75 | "This highlighter uses the Tree Sitter parser for Scala, compiled to WASM. It is much more accurate than any regex-based engines such as Highlight.js or Textmate grammars" 76 | ), 77 | p( 78 | a( 79 | "Github", 80 | href := "https://github.com/keynmol/scala-treesitter-highlighting", 81 | basicLink 82 | ), 83 | " | ", 84 | a( 85 | "Author", 86 | href := "https://blog.indoorvivants.com", 87 | basicLink 88 | ), 89 | " | ", 90 | a( 91 | "Tree Sitter Scala grammar", 92 | href := "https://github.com/tree-sitter/tree-sitter-scala/pulls", 93 | basicLink 94 | ) 95 | ) 96 | ) 97 | 98 | val themeSelector = 99 | div( 100 | cls := "flex flex-row gap-4 items-center", 101 | h2("Theme:", cls := "text-2xl"), 102 | select( 103 | cls := "text-2xl bg-white border-2 border-sky-700 p-2 text-black bg-sky-100 borde", 104 | opt("kanagawa", "Kanagawa"), 105 | opt("gruvbox", "Gruvbox"), 106 | opt("vscode", "VS Code (dark)"), 107 | opt("vscode-light", "VS Code (light)"), 108 | onChange.mapToValue --> theme 109 | ) 110 | ) 111 | 112 | val scalaCode = div( 113 | cls := "2xl:w-6/12 h-full overflow-auto", 114 | h2("Scala code:", cls := "text-2xl"), 115 | codeMirrorTextArea(codeVar) 116 | ) 117 | 118 | val highlightJSExample = div( 119 | cls("hidden") <-- showHLJS.signal.map(!_), 120 | child <-- codeVar.signal.map(code => codeBlock("scala", code)) 121 | ) 122 | 123 | val highlightedCode = div( 124 | cls := "2xl:w-6/12 flex flex-col gap-2", 125 | themeSelector, 126 | h3(cls := "text-2xl", "Tree Sitter highlighting:"), 127 | pre( 128 | cls := "ts-hl w-full", 129 | code(children <-- codeVar.signal.combineWith(theme.signal).map { 130 | (sourceCode, themeName) => 131 | val highlight = 132 | HighlightTokenizer( 133 | sourceCode, 134 | highlightQueries, 135 | treesitter 136 | ).tokens.toList 137 | 138 | val elements = List.newBuilder[HtmlElement] 139 | val theme = Theme.fromString(themeName).get 140 | val groups = scala.collection.mutable.Set.empty[CaptureGroup] 141 | 142 | highlight.foreach: token => 143 | token.kind.foreach: k => 144 | CaptureGroup.fromString(k).foreach(groups += _) 145 | elements.addOne( 146 | span( 147 | sourceCode.slice(token.start, token.finish), 148 | token.kind.map(c => cls := "ts-hl-" + c.replace('.', '-')) 149 | ) 150 | ) 151 | 152 | console.log(groups) 153 | 154 | injectCSS.textContent = Theme.buildCSS(theme, groups.toSet) 155 | 156 | elements.result() 157 | }) 158 | ), 159 | h3( 160 | cls := "text-2xl", 161 | child.text <-- showHLJS.signal.map(if _ then "➖" else "➕"), 162 | " HighlightJS highlighting:", 163 | cls := "cursor-pointer", 164 | onClick.mapToValue --> { _ => showHLJS.update(!_) } 165 | ), 166 | highlightJSExample 167 | ) 168 | 169 | div( 170 | cls := "content mx-auto w-10/12 bg-white/70 p-6 rounded-xl flex flex-col gap-4", 171 | header, 172 | div( 173 | cls := "flex md:flex-col sm:flex-col lg:flex-col 2xl:flex-row gap-4 w-full", 174 | scalaCode, 175 | highlightedCode 176 | ) 177 | 178 | // code( 179 | // styleAttr := "background: black; color: white", 180 | // display <-- debugToggled.signal.map( 181 | // if _ then display.block.value else display.none.value 182 | // ), 183 | // pre( 184 | // child.text <-- annotatedCodeVar 185 | // ) 186 | // ) 187 | ) 188 | end app 189 | 190 | def annotate[TS <: TreeSitter & Singleton]( 191 | text: String, 192 | ts: TS, 193 | query: ts.Query, 194 | captures: Iterable[ts.Capture] 195 | ): String = 196 | case class CaptureGroup(label: String, node: ts.Node) 197 | val lines = text.linesIterator.toList.zipWithIndex 198 | val annots = captures 199 | .map(c => CaptureGroup(c.name(query), c.node)) 200 | .groupMap(_.node.startPoint.row)(identity) 201 | 202 | val allLines = List.newBuilder[String] 203 | 204 | def indent(capture: CaptureGroup): String = 205 | " ".*( 206 | capture.node.startPoint.column 207 | ) 208 | 209 | def mark(capture: CaptureGroup): String = 210 | "^".*( 211 | capture.node.text(text).length 212 | ) 213 | 214 | lines.foreach: 215 | case (line, idx) => 216 | allLines += line 217 | annots 218 | .get(idx) 219 | .foreach: matches => 220 | matches.foreach: capture => 221 | allLines += indent(capture) + mark( 222 | capture 223 | ) + " " + capture.label.replace('.', '-') 224 | allLines.result().mkString("\n") 225 | end annotate 226 | 227 | inline def codeBlock(language: String, value: String) = 228 | pre( 229 | code( 230 | cls := s"language-$language", 231 | onMountCallback(mnt => hljs.highlightElement(mnt.thisNode.ref)), 232 | value 233 | ) 234 | ) 235 | 236 | @main def hello = 237 | val interface = TreeSitter(Parser) 238 | render(document.getElementById("content"), app(interface)) 239 | end hello 240 | 241 | val SAMPLE_CODE = 242 | """ 243 | def grammar(year: Int) = 244 | inline def token(str: String) = 245 | atomic(string(str.toLowerCase())) <~ whitespaces.void 246 | 247 | val PLANET_OF_THE_APES = token("Planet of the Apes") 248 | val FOR = token("for") 249 | val FROM = token("from") 250 | val THE = token("the") 251 | val OF = token("of") 252 | val BENEATH = token("Beneath") 253 | val ESCAPE = token("Escape") 254 | val CONQUEST = token("Conquest") 255 | val BATTLE = token("Battle") 256 | val RISE = token("Rise") 257 | val DAWN = token("Dawn") 258 | val WAR = token("War") 259 | val KINGDOM = token("Kingdom") 260 | val RETURN = token("Return") 261 | val TO = token("to") 262 | 263 | extension (p: Parsley[Outcome]) 264 | def releasedIn(releaseYear: Int) = 265 | Option.when(year >= releaseYear)(p) 266 | """.trim 267 | -------------------------------------------------------------------------------- /mod/tree-sitter-interface/src/main/resources/scala-native/generated/treesitter.c: -------------------------------------------------------------------------------- 1 | /* #include */ 2 | /* #include "tree_sitter/api.h" */ 3 | 4 | /* void __sn_wrap_treesitter_ts_node_child(TSNode *self, uint32_t child_index, TSNode *____return) { */ 5 | /* TSNode ____ret = ts_node_child(*self, child_index); */ 6 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 7 | /* } */ 8 | 9 | 10 | /* void __sn_wrap_treesitter_ts_node_child_by_field_id(TSNode *self, TSFieldId field_id, TSNode *____return) { */ 11 | /* TSNode ____ret = ts_node_child_by_field_id(*self, field_id); */ 12 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 13 | /* } */ 14 | 15 | 16 | /* void __sn_wrap_treesitter_ts_node_child_by_field_name(TSNode *self, const char * name, uint32_t name_length, TSNode *____return) { */ 17 | /* TSNode ____ret = ts_node_child_by_field_name(*self, name, name_length); */ 18 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 19 | /* } */ 20 | 21 | 22 | /* uint32_t __sn_wrap_treesitter_ts_node_child_count(TSNode *self) { */ 23 | /* return ts_node_child_count(*self); */ 24 | /* }; */ 25 | 26 | 27 | /* /1* uint32_t __sn_wrap_treesitter_ts_node_descendant_count(TSNode *self) { *1/ */ 28 | /* /1* return ts_node_descendant_count(*self); *1/ */ 29 | /* /1* }; *1/ */ 30 | 31 | 32 | /* void __sn_wrap_treesitter_ts_node_descendant_for_byte_range(TSNode *self, uint32_t start, uint32_t end, TSNode *____return) { */ 33 | /* TSNode ____ret = ts_node_descendant_for_byte_range(*self, start, end); */ 34 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 35 | /* } */ 36 | 37 | 38 | /* void __sn_wrap_treesitter_ts_node_descendant_for_point_range(TSNode *self, TSPoint *start, TSPoint *end, TSNode *____return) { */ 39 | /* TSNode ____ret = ts_node_descendant_for_point_range(*self, *start, *end); */ 40 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 41 | /* } */ 42 | 43 | 44 | /* uint32_t __sn_wrap_treesitter_ts_node_end_byte(TSNode *self) { */ 45 | /* return ts_node_end_byte(*self); */ 46 | /* }; */ 47 | 48 | 49 | /* void __sn_wrap_treesitter_ts_node_end_point(TSNode *self, TSPoint *____return) { */ 50 | /* TSPoint ____ret = ts_node_end_point(*self); */ 51 | /* memcpy(____return, &____ret, sizeof(TSPoint)); */ 52 | /* } */ 53 | 54 | 55 | /* _Bool __sn_wrap_treesitter_ts_node_eq(TSNode *self, TSNode *other) { */ 56 | /* return ts_node_eq(*self, *other); */ 57 | /* }; */ 58 | 59 | 60 | /* const char * __sn_wrap_treesitter_ts_node_field_name_for_child(TSNode *self, uint32_t child_index) { */ 61 | /* return ts_node_field_name_for_child(*self, child_index); */ 62 | /* }; */ 63 | 64 | 65 | /* void __sn_wrap_treesitter_ts_node_first_child_for_byte(TSNode *self, uint32_t byte, TSNode *____return) { */ 66 | /* TSNode ____ret = ts_node_first_child_for_byte(*self, byte); */ 67 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 68 | /* } */ 69 | 70 | 71 | /* void __sn_wrap_treesitter_ts_node_first_named_child_for_byte(TSNode *self, uint32_t byte, TSNode *____return) { */ 72 | /* TSNode ____ret = ts_node_first_named_child_for_byte(*self, byte); */ 73 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 74 | /* } */ 75 | 76 | 77 | /* /1* TSSymbol __sn_wrap_treesitter_ts_node_grammar_symbol(TSNode *self) { *1/ */ 78 | /* /1* return ts_node_grammar_symbol(*self); *1/ */ 79 | /* /1* }; *1/ */ 80 | 81 | 82 | /* /1* const char * __sn_wrap_treesitter_ts_node_grammar_type(TSNode *self) { *1/ */ 83 | /* /1* return ts_node_grammar_type(*self); *1/ */ 84 | /* /1* }; *1/ */ 85 | 86 | 87 | /* _Bool __sn_wrap_treesitter_ts_node_has_changes(TSNode *self) { */ 88 | /* return ts_node_has_changes(*self); */ 89 | /* }; */ 90 | 91 | 92 | /* /1* _Bool __sn_wrap_treesitter_ts_node_has_error(TSNode *self) { *1/ */ 93 | /* /1* return ts_node_has_error(*self); *1/ */ 94 | /* /1* }; *1/ */ 95 | 96 | 97 | /* /1* _Bool __sn_wrap_treesitter_ts_node_is_error(TSNode *self) { *1/ */ 98 | /* /1* return ts_node_is_error(*self); *1/ */ 99 | /* /1* }; *1/ */ 100 | 101 | 102 | /* _Bool __sn_wrap_treesitter_ts_node_is_extra(TSNode *self) { */ 103 | /* return ts_node_is_extra(*self); */ 104 | /* }; */ 105 | 106 | 107 | /* _Bool __sn_wrap_treesitter_ts_node_is_missing(TSNode *self) { */ 108 | /* return ts_node_is_missing(*self); */ 109 | /* }; */ 110 | 111 | 112 | /* _Bool __sn_wrap_treesitter_ts_node_is_named(TSNode *self) { */ 113 | /* return ts_node_is_named(*self); */ 114 | /* }; */ 115 | 116 | 117 | /* _Bool __sn_wrap_treesitter_ts_node_is_null(TSNode *self) { */ 118 | /* return ts_node_is_null(*self); */ 119 | /* }; */ 120 | 121 | 122 | /* /1* const TSLanguage * __sn_wrap_treesitter_ts_node_language(TSNode *self) { *1/ */ 123 | /* /1* return ts_node_language(*self); *1/ */ 124 | /* /1* }; *1/ */ 125 | 126 | 127 | /* void __sn_wrap_treesitter_ts_node_named_child(TSNode *self, uint32_t child_index, TSNode *____return) { */ 128 | /* TSNode ____ret = ts_node_named_child(*self, child_index); */ 129 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 130 | /* } */ 131 | 132 | 133 | /* uint32_t __sn_wrap_treesitter_ts_node_named_child_count(TSNode *self) { */ 134 | /* return ts_node_named_child_count(*self); */ 135 | /* }; */ 136 | 137 | 138 | /* void __sn_wrap_treesitter_ts_node_named_descendant_for_byte_range(TSNode *self, uint32_t start, uint32_t end, TSNode *____return) { */ 139 | /* TSNode ____ret = ts_node_named_descendant_for_byte_range(*self, start, end); */ 140 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 141 | /* } */ 142 | 143 | 144 | /* void __sn_wrap_treesitter_ts_node_named_descendant_for_point_range(TSNode *self, TSPoint *start, TSPoint *end, TSNode *____return) { */ 145 | /* TSNode ____ret = ts_node_named_descendant_for_point_range(*self, *start, *end); */ 146 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 147 | /* } */ 148 | 149 | 150 | /* void __sn_wrap_treesitter_ts_node_next_named_sibling(TSNode *self, TSNode *____return) { */ 151 | /* TSNode ____ret = ts_node_next_named_sibling(*self); */ 152 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 153 | /* } */ 154 | 155 | 156 | /* /1* TSStateId __sn_wrap_treesitter_ts_node_next_parse_state(TSNode *self) { *1/ */ 157 | /* /1* return ts_node_next_parse_state(*self); *1/ */ 158 | /* /1* }; *1/ */ 159 | 160 | 161 | /* void __sn_wrap_treesitter_ts_node_next_sibling(TSNode *self, TSNode *____return) { */ 162 | /* TSNode ____ret = ts_node_next_sibling(*self); */ 163 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 164 | /* } */ 165 | 166 | 167 | /* /1* void __sn_wrap_treesitter_ts_node_parent(TSNode *self, TSNode *____return) { *1/ */ 168 | /* /1* TSNode ____ret = ts_node_parent(*self); *1/ */ 169 | /* /1* memcpy(____return, &____ret, sizeof(TSNode)); *1/ */ 170 | /* /1* } *1/ */ 171 | 172 | 173 | /* /1* TSStateId __sn_wrap_treesitter_ts_node_parse_state(TSNode *self) { *1/ */ 174 | /* /1* return ts_node_parse_state(*self); *1/ */ 175 | /* /1* }; *1/ */ 176 | 177 | 178 | /* void __sn_wrap_treesitter_ts_node_prev_named_sibling(TSNode *self, TSNode *____return) { */ 179 | /* TSNode ____ret = ts_node_prev_named_sibling(*self); */ 180 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 181 | /* } */ 182 | 183 | 184 | /* void __sn_wrap_treesitter_ts_node_prev_sibling(TSNode *self, TSNode *____return) { */ 185 | /* TSNode ____ret = ts_node_prev_sibling(*self); */ 186 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 187 | /* } */ 188 | 189 | 190 | /* uint32_t __sn_wrap_treesitter_ts_node_start_byte(TSNode *self) { */ 191 | /* return ts_node_start_byte(*self); */ 192 | /* }; */ 193 | 194 | 195 | /* void __sn_wrap_treesitter_ts_node_start_point(TSNode *self, TSPoint *____return) { */ 196 | /* TSPoint ____ret = ts_node_start_point(*self); */ 197 | /* memcpy(____return, &____ret, sizeof(TSPoint)); */ 198 | /* } */ 199 | 200 | 201 | /* char * __sn_wrap_treesitter_ts_node_string(TSNode *self) { */ 202 | /* return ts_node_string(*self); */ 203 | /* }; */ 204 | 205 | 206 | /* TSSymbol __sn_wrap_treesitter_ts_node_symbol(TSNode *self) { */ 207 | /* return ts_node_symbol(*self); */ 208 | /* }; */ 209 | 210 | 211 | /* const char * __sn_wrap_treesitter_ts_node_type(TSNode *self) { */ 212 | /* return ts_node_type(*self); */ 213 | /* }; */ 214 | 215 | 216 | /* void __sn_wrap_treesitter_ts_parser_logger(const TSParser * self, TSLogger *____return) { */ 217 | /* TSLogger ____ret = ts_parser_logger(self); */ 218 | /* memcpy(____return, &____ret, sizeof(TSLogger)); */ 219 | /* } */ 220 | 221 | 222 | /* TSTree * __sn_wrap_treesitter_ts_parser_parse(TSParser * self, const TSTree * old_tree, TSInput *input) { */ 223 | /* return ts_parser_parse(self, old_tree, *input); */ 224 | /* }; */ 225 | 226 | 227 | /* void __sn_wrap_treesitter_ts_parser_set_logger(TSParser * self, TSLogger *logger) { */ 228 | /* ts_parser_set_logger(self, *logger); */ 229 | /* }; */ 230 | 231 | 232 | /* void __sn_wrap_treesitter_ts_query_cursor_exec(TSQueryCursor * self, const TSQuery * query, TSNode *node) { */ 233 | /* ts_query_cursor_exec(self, query, *node); */ 234 | /* }; */ 235 | 236 | 237 | /* void __sn_wrap_treesitter_ts_query_cursor_set_point_range(TSQueryCursor * self, TSPoint *start_point, TSPoint *end_point) { */ 238 | /* ts_query_cursor_set_point_range(self, *start_point, *end_point); */ 239 | /* }; */ 240 | 241 | 242 | /* void __sn_wrap_treesitter_ts_tree_cursor_copy(const TSTreeCursor * cursor, TSTreeCursor *____return) { */ 243 | /* TSTreeCursor ____ret = ts_tree_cursor_copy(cursor); */ 244 | /* memcpy(____return, &____ret, sizeof(TSTreeCursor)); */ 245 | /* } */ 246 | 247 | 248 | /* void __sn_wrap_treesitter_ts_tree_cursor_current_node(const TSTreeCursor * self, TSNode *____return) { */ 249 | /* TSNode ____ret = ts_tree_cursor_current_node(self); */ 250 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 251 | /* } */ 252 | 253 | 254 | /* int64_t __sn_wrap_treesitter_ts_tree_cursor_goto_first_child_for_point(TSTreeCursor * self, TSPoint *goal_point) { */ 255 | /* return ts_tree_cursor_goto_first_child_for_point(self, *goal_point); */ 256 | /* }; */ 257 | 258 | 259 | /* void __sn_wrap_treesitter_ts_tree_cursor_new(TSNode *node, TSTreeCursor *____return) { */ 260 | /* TSTreeCursor ____ret = ts_tree_cursor_new(*node); */ 261 | /* memcpy(____return, &____ret, sizeof(TSTreeCursor)); */ 262 | /* } */ 263 | 264 | 265 | /* void __sn_wrap_treesitter_ts_tree_cursor_reset(TSTreeCursor * self, TSNode *node) { */ 266 | /* ts_tree_cursor_reset(self, *node); */ 267 | /* }; */ 268 | 269 | 270 | /* void __sn_wrap_treesitter_ts_tree_root_node(const TSTree * self, TSNode *____return) { */ 271 | /* TSNode ____ret = ts_tree_root_node(self); */ 272 | /* memcpy(____return, &____ret, sizeof(TSNode)); */ 273 | /* } */ 274 | 275 | 276 | /* /1* void __sn_wrap_treesitter_ts_tree_root_node_with_offset(const TSTree * self, uint32_t offset_bytes, TSPoint *offset_extent, TSNode *____return) { *1/ */ 277 | /* /1* TSNode ____ret = ts_tree_root_node_with_offset(self, offset_bytes, *offset_extent); *1/ */ 278 | /* /1* memcpy(____return, &____ret, sizeof(TSNode)); *1/ */ 279 | /* /1* } *1/ */ 280 | -------------------------------------------------------------------------------- /mod/cmark-bindings/src/main/scala/generated/cmark.scala: -------------------------------------------------------------------------------- 1 | package cmark 2 | 3 | import _root_.scala.scalanative.unsafe.* 4 | import _root_.scala.scalanative.unsigned.* 5 | import _root_.scala.scalanative.libc.* 6 | import _root_.scala.scalanative.* 7 | 8 | object predef: 9 | private[cmark] trait CEnumU[T](using eq: T =:= UInt): 10 | given Tag[T] = Tag.UInt.asInstanceOf[Tag[T]] 11 | extension (inline t: T) 12 | inline def int: CInt = eq.apply(t).toInt 13 | inline def uint: CUnsignedInt = eq.apply(t) 14 | inline def value: CUnsignedInt = eq.apply(t) 15 | 16 | 17 | object enumerations: 18 | import predef.* 19 | opaque type cmark_delim_type = CUnsignedInt 20 | object cmark_delim_type extends CEnumU[cmark_delim_type]: 21 | given _tag: Tag[cmark_delim_type] = Tag.UInt 22 | inline def define(inline a: Long): cmark_delim_type = a.toUInt 23 | val CMARK_NO_DELIM = define(0) 24 | val CMARK_PERIOD_DELIM = define(1) 25 | val CMARK_PAREN_DELIM = define(2) 26 | inline def getName(inline value: cmark_delim_type): Option[String] = 27 | inline value match 28 | case CMARK_NO_DELIM => Some("CMARK_NO_DELIM") 29 | case CMARK_PERIOD_DELIM => Some("CMARK_PERIOD_DELIM") 30 | case CMARK_PAREN_DELIM => Some("CMARK_PAREN_DELIM") 31 | case _ => _root_.scala.None 32 | extension (a: cmark_delim_type) 33 | inline def &(b: cmark_delim_type): cmark_delim_type = a & b 34 | inline def |(b: cmark_delim_type): cmark_delim_type = a | b 35 | inline def is(b: cmark_delim_type): Boolean = (a & b) == b 36 | 37 | /** 38 | * ## Iterator 39 | */ 40 | opaque type cmark_event_type = CUnsignedInt 41 | object cmark_event_type extends CEnumU[cmark_event_type]: 42 | given _tag: Tag[cmark_event_type] = Tag.UInt 43 | inline def define(inline a: Long): cmark_event_type = a.toUInt 44 | val CMARK_EVENT_NONE = define(0) 45 | val CMARK_EVENT_DONE = define(1) 46 | val CMARK_EVENT_ENTER = define(2) 47 | val CMARK_EVENT_EXIT = define(3) 48 | inline def getName(inline value: cmark_event_type): Option[String] = 49 | inline value match 50 | case CMARK_EVENT_NONE => Some("CMARK_EVENT_NONE") 51 | case CMARK_EVENT_DONE => Some("CMARK_EVENT_DONE") 52 | case CMARK_EVENT_ENTER => Some("CMARK_EVENT_ENTER") 53 | case CMARK_EVENT_EXIT => Some("CMARK_EVENT_EXIT") 54 | case _ => _root_.scala.None 55 | extension (a: cmark_event_type) 56 | inline def &(b: cmark_event_type): cmark_event_type = a & b 57 | inline def |(b: cmark_event_type): cmark_event_type = a | b 58 | inline def is(b: cmark_event_type): Boolean = (a & b) == b 59 | 60 | opaque type cmark_list_type = CUnsignedInt 61 | object cmark_list_type extends CEnumU[cmark_list_type]: 62 | given _tag: Tag[cmark_list_type] = Tag.UInt 63 | inline def define(inline a: Long): cmark_list_type = a.toUInt 64 | val CMARK_NO_LIST = define(0) 65 | val CMARK_BULLET_LIST = define(1) 66 | val CMARK_ORDERED_LIST = define(2) 67 | inline def getName(inline value: cmark_list_type): Option[String] = 68 | inline value match 69 | case CMARK_NO_LIST => Some("CMARK_NO_LIST") 70 | case CMARK_BULLET_LIST => Some("CMARK_BULLET_LIST") 71 | case CMARK_ORDERED_LIST => Some("CMARK_ORDERED_LIST") 72 | case _ => _root_.scala.None 73 | extension (a: cmark_list_type) 74 | inline def &(b: cmark_list_type): cmark_list_type = a & b 75 | inline def |(b: cmark_list_type): cmark_list_type = a | b 76 | inline def is(b: cmark_list_type): Boolean = (a & b) == b 77 | 78 | /** 79 | * ## Node Structure 80 | */ 81 | opaque type cmark_node_type = CUnsignedInt 82 | object cmark_node_type extends CEnumU[cmark_node_type]: 83 | given _tag: Tag[cmark_node_type] = Tag.UInt 84 | inline def define(inline a: Long): cmark_node_type = a.toUInt 85 | val CMARK_NODE_NONE = define(0) 86 | val CMARK_NODE_DOCUMENT = define(1) 87 | val CMARK_NODE_BLOCK_QUOTE = define(2) 88 | val CMARK_NODE_LIST = define(3) 89 | val CMARK_NODE_ITEM = define(4) 90 | val CMARK_NODE_CODE_BLOCK = define(5) 91 | val CMARK_NODE_HTML_BLOCK = define(6) 92 | val CMARK_NODE_CUSTOM_BLOCK = define(7) 93 | val CMARK_NODE_PARAGRAPH = define(8) 94 | val CMARK_NODE_HEADING = define(9) 95 | val CMARK_NODE_THEMATIC_BREAK = define(10) 96 | val CMARK_NODE_FIRST_BLOCK = define(1) 97 | val CMARK_NODE_LAST_BLOCK = define(10) 98 | val CMARK_NODE_TEXT = define(11) 99 | val CMARK_NODE_SOFTBREAK = define(12) 100 | val CMARK_NODE_LINEBREAK = define(13) 101 | val CMARK_NODE_CODE = define(14) 102 | val CMARK_NODE_HTML_INLINE = define(15) 103 | val CMARK_NODE_CUSTOM_INLINE = define(16) 104 | val CMARK_NODE_EMPH = define(17) 105 | val CMARK_NODE_STRONG = define(18) 106 | val CMARK_NODE_LINK = define(19) 107 | val CMARK_NODE_IMAGE = define(20) 108 | val CMARK_NODE_FIRST_INLINE = define(11) 109 | val CMARK_NODE_LAST_INLINE = define(20) 110 | inline def getName(inline value: cmark_node_type): Option[String] = 111 | inline value match 112 | case CMARK_NODE_NONE => Some("CMARK_NODE_NONE") 113 | case CMARK_NODE_DOCUMENT => Some("CMARK_NODE_DOCUMENT") 114 | case CMARK_NODE_BLOCK_QUOTE => Some("CMARK_NODE_BLOCK_QUOTE") 115 | case CMARK_NODE_LIST => Some("CMARK_NODE_LIST") 116 | case CMARK_NODE_ITEM => Some("CMARK_NODE_ITEM") 117 | case CMARK_NODE_CODE_BLOCK => Some("CMARK_NODE_CODE_BLOCK") 118 | case CMARK_NODE_HTML_BLOCK => Some("CMARK_NODE_HTML_BLOCK") 119 | case CMARK_NODE_CUSTOM_BLOCK => Some("CMARK_NODE_CUSTOM_BLOCK") 120 | case CMARK_NODE_PARAGRAPH => Some("CMARK_NODE_PARAGRAPH") 121 | case CMARK_NODE_HEADING => Some("CMARK_NODE_HEADING") 122 | case CMARK_NODE_THEMATIC_BREAK => Some("CMARK_NODE_THEMATIC_BREAK") 123 | case CMARK_NODE_FIRST_BLOCK => Some("CMARK_NODE_FIRST_BLOCK") 124 | case CMARK_NODE_LAST_BLOCK => Some("CMARK_NODE_LAST_BLOCK") 125 | case CMARK_NODE_TEXT => Some("CMARK_NODE_TEXT") 126 | case CMARK_NODE_SOFTBREAK => Some("CMARK_NODE_SOFTBREAK") 127 | case CMARK_NODE_LINEBREAK => Some("CMARK_NODE_LINEBREAK") 128 | case CMARK_NODE_CODE => Some("CMARK_NODE_CODE") 129 | case CMARK_NODE_HTML_INLINE => Some("CMARK_NODE_HTML_INLINE") 130 | case CMARK_NODE_CUSTOM_INLINE => Some("CMARK_NODE_CUSTOM_INLINE") 131 | case CMARK_NODE_EMPH => Some("CMARK_NODE_EMPH") 132 | case CMARK_NODE_STRONG => Some("CMARK_NODE_STRONG") 133 | case CMARK_NODE_LINK => Some("CMARK_NODE_LINK") 134 | case CMARK_NODE_IMAGE => Some("CMARK_NODE_IMAGE") 135 | case CMARK_NODE_FIRST_INLINE => Some("CMARK_NODE_FIRST_INLINE") 136 | case CMARK_NODE_LAST_INLINE => Some("CMARK_NODE_LAST_INLINE") 137 | case _ => _root_.scala.None 138 | extension (a: cmark_node_type) 139 | inline def &(b: cmark_node_type): cmark_node_type = a & b 140 | inline def |(b: cmark_node_type): cmark_node_type = a | b 141 | inline def is(b: cmark_node_type): Boolean = (a & b) == b 142 | 143 | object aliases: 144 | import _root_.cmark.enumerations.* 145 | import _root_.cmark.predef.* 146 | import _root_.cmark.aliases.* 147 | import _root_.cmark.structs.* 148 | type FILE = libc.stdio.FILE 149 | object FILE: 150 | val _tag: Tag[FILE] = summon[Tag[libc.stdio.FILE]] 151 | inline def apply(inline o: libc.stdio.FILE): FILE = o 152 | extension (v: FILE) 153 | inline def value: libc.stdio.FILE = v 154 | 155 | type size_t = libc.stddef.size_t 156 | object size_t: 157 | val _tag: Tag[size_t] = summon[Tag[libc.stddef.size_t]] 158 | inline def apply(inline o: libc.stddef.size_t): size_t = o 159 | extension (v: size_t) 160 | inline def value: libc.stddef.size_t = v 161 | 162 | object structs: 163 | import _root_.cmark.enumerations.* 164 | import _root_.cmark.predef.* 165 | import _root_.cmark.aliases.* 166 | import _root_.cmark.structs.* 167 | opaque type cmark_iter = CStruct0 168 | object cmark_iter: 169 | given _tag: Tag[cmark_iter] = Tag.materializeCStruct0Tag 170 | 171 | /** 172 | * Defines the memory allocation functions to be used by CMark when parsing and allocating a document tree 173 | */ 174 | opaque type cmark_mem = CStruct3[CFuncPtr2[size_t, size_t, Ptr[Byte]], CFuncPtr2[Ptr[Byte], size_t, Ptr[Byte]], CFuncPtr1[Ptr[Byte], Unit]] 175 | object cmark_mem: 176 | given _tag: Tag[cmark_mem] = Tag.materializeCStruct3Tag[CFuncPtr2[size_t, size_t, Ptr[Byte]], CFuncPtr2[Ptr[Byte], size_t, Ptr[Byte]], CFuncPtr1[Ptr[Byte], Unit]] 177 | def apply()(using Zone): Ptr[cmark_mem] = scala.scalanative.unsafe.alloc[cmark_mem](1) 178 | def apply(calloc : CFuncPtr2[size_t, size_t, Ptr[Byte]], realloc : CFuncPtr2[Ptr[Byte], size_t, Ptr[Byte]], free : CFuncPtr1[Ptr[Byte], Unit])(using Zone): Ptr[cmark_mem] = 179 | val ____ptr = apply() 180 | (!____ptr).calloc = calloc 181 | (!____ptr).realloc = realloc 182 | (!____ptr).free = free 183 | ____ptr 184 | extension (struct: cmark_mem) 185 | def calloc : CFuncPtr2[size_t, size_t, Ptr[Byte]] = struct._1 186 | def calloc_=(value: CFuncPtr2[size_t, size_t, Ptr[Byte]]): Unit = !struct.at1 = value 187 | def realloc : CFuncPtr2[Ptr[Byte], size_t, Ptr[Byte]] = struct._2 188 | def realloc_=(value: CFuncPtr2[Ptr[Byte], size_t, Ptr[Byte]]): Unit = !struct.at2 = value 189 | def free : CFuncPtr1[Ptr[Byte], Unit] = struct._3 190 | def free_=(value: CFuncPtr1[Ptr[Byte], Unit]): Unit = !struct.at3 = value 191 | 192 | opaque type cmark_node = CStruct0 193 | object cmark_node: 194 | given _tag: Tag[cmark_node] = Tag.materializeCStruct0Tag 195 | 196 | opaque type cmark_parser = CStruct0 197 | object cmark_parser: 198 | given _tag: Tag[cmark_parser] = Tag.materializeCStruct0Tag 199 | 200 | 201 | @extern 202 | private[cmark] object extern_functions: 203 | import _root_.cmark.enumerations.* 204 | import _root_.cmark.predef.* 205 | import _root_.cmark.aliases.* 206 | import _root_.cmark.structs.* 207 | /** 208 | * Consolidates adjacent text nodes. 209 | */ 210 | def cmark_consolidate_text_nodes(root : Ptr[cmark_node]): Unit = extern 211 | 212 | /** 213 | * Returns a pointer to the default memory allocator. 214 | */ 215 | def cmark_get_default_mem_allocator(): Ptr[cmark_mem] = extern 216 | 217 | /** 218 | * Frees the memory allocated for an iterator. 219 | */ 220 | def cmark_iter_free(iter : Ptr[cmark_iter]): Unit = extern 221 | 222 | /** 223 | * Returns the current event type. 224 | */ 225 | def cmark_iter_get_event_type(iter : Ptr[cmark_iter]): cmark_event_type = extern 226 | 227 | /** 228 | * Returns the current node. 229 | */ 230 | def cmark_iter_get_node(iter : Ptr[cmark_iter]): Ptr[cmark_node] = extern 231 | 232 | /** 233 | * Returns the root node. 234 | */ 235 | def cmark_iter_get_root(iter : Ptr[cmark_iter]): Ptr[cmark_node] = extern 236 | 237 | /** 238 | * Creates a new iterator starting at 'root'. The current node and event type are undefined until 'cmark_iter_next' is called for the first time. The memory allocated for the iterator should be released using 'cmark_iter_free' when it is no longer needed. 239 | */ 240 | def cmark_iter_new(root : Ptr[cmark_node]): Ptr[cmark_iter] = extern 241 | 242 | /** 243 | * Advances to the next node and returns the event type (`CMARK_EVENT_ENTER`, `CMARK_EVENT_EXIT` or `CMARK_EVENT_DONE`). 244 | */ 245 | def cmark_iter_next(iter : Ptr[cmark_iter]): cmark_event_type = extern 246 | 247 | /** 248 | * Resets the iterator so that the current node is 'current' and the event type is 'event_type'. The new current node must be a descendant of the root node or the root node itself. 249 | */ 250 | def cmark_iter_reset(iter : Ptr[cmark_iter], current : Ptr[cmark_node], event_type : cmark_event_type): Unit = extern 251 | 252 | /** 253 | * Convert 'text' (assumed to be a UTF-8 encoded string with length 'len') from CommonMark Markdown to HTML, returning a null-terminated, UTF-8-encoded string. It is the caller's responsibility to free the returned buffer. 254 | */ 255 | def cmark_markdown_to_html(text : CString, len : size_t, options : CInt): CString = extern 256 | 257 | /** 258 | * Adds 'child' to the end of the children of 'node'. Returns 1 on success, 0 on failure. 259 | */ 260 | def cmark_node_append_child(node : Ptr[cmark_node], child : Ptr[cmark_node]): CInt = extern 261 | 262 | /** 263 | * Returns the first child of 'node', or NULL if 'node' has no children. 264 | */ 265 | def cmark_node_first_child(node : Ptr[cmark_node]): Ptr[cmark_node] = extern 266 | 267 | /** 268 | * Frees the memory allocated for a node and any children. 269 | */ 270 | def cmark_node_free(node : Ptr[cmark_node]): Unit = extern 271 | 272 | /** 273 | * Returns the column at which 'node' ends. 274 | */ 275 | def cmark_node_get_end_column(node : Ptr[cmark_node]): CInt = extern 276 | 277 | /** 278 | * Returns the line on which 'node' ends. 279 | */ 280 | def cmark_node_get_end_line(node : Ptr[cmark_node]): CInt = extern 281 | 282 | /** 283 | * Returns the info string from a fenced code block. 284 | */ 285 | def cmark_node_get_fence_info(node : Ptr[cmark_node]): CString = extern 286 | 287 | /** 288 | * Returns the heading level of 'node', or 0 if 'node' is not a heading. 289 | */ 290 | def cmark_node_get_heading_level(node : Ptr[cmark_node]): CInt = extern 291 | 292 | /** 293 | * Returns the list delimiter type of 'node', or `CMARK_NO_DELIM` if 'node' is not a list. 294 | */ 295 | def cmark_node_get_list_delim(node : Ptr[cmark_node]): cmark_delim_type = extern 296 | 297 | /** 298 | * Returns starting number of 'node', if it is an ordered list, otherwise 0. 299 | */ 300 | def cmark_node_get_list_start(node : Ptr[cmark_node]): CInt = extern 301 | 302 | /** 303 | * Returns 1 if 'node' is a tight list, 0 otherwise. 304 | */ 305 | def cmark_node_get_list_tight(node : Ptr[cmark_node]): CInt = extern 306 | 307 | /** 308 | * Returns the list type of 'node', or `CMARK_NO_LIST` if 'node' is not a list. 309 | */ 310 | def cmark_node_get_list_type(node : Ptr[cmark_node]): cmark_list_type = extern 311 | 312 | /** 313 | * Returns the string contents of 'node', or an empty string if none is set. Returns NULL if called on a node that does not have string content. 314 | */ 315 | def cmark_node_get_literal(node : Ptr[cmark_node]): CString = extern 316 | 317 | /** 318 | * Returns the literal "on enter" text for a custom 'node', or an empty string if no on_enter is set. Returns NULL if called on a non-custom node. 319 | */ 320 | def cmark_node_get_on_enter(node : Ptr[cmark_node]): CString = extern 321 | 322 | /** 323 | * Returns the literal "on exit" text for a custom 'node', or an empty string if no on_exit is set. Returns NULL if called on a non-custom node. 324 | */ 325 | def cmark_node_get_on_exit(node : Ptr[cmark_node]): CString = extern 326 | 327 | /** 328 | * Returns the column at which 'node' begins. 329 | */ 330 | def cmark_node_get_start_column(node : Ptr[cmark_node]): CInt = extern 331 | 332 | /** 333 | * Returns the line on which 'node' begins. 334 | */ 335 | def cmark_node_get_start_line(node : Ptr[cmark_node]): CInt = extern 336 | 337 | /** 338 | * Returns the title of a link or image 'node', or an empty string if no title is set. Returns NULL if called on a node that is not a link or image. 339 | */ 340 | def cmark_node_get_title(node : Ptr[cmark_node]): CString = extern 341 | 342 | /** 343 | * Returns the type of 'node', or `CMARK_NODE_NONE` on error. 344 | */ 345 | def cmark_node_get_type(node : Ptr[cmark_node]): cmark_node_type = extern 346 | 347 | /** 348 | * Like 'cmark_node_get_type', but returns a string representation of the type, or `""`. 349 | */ 350 | def cmark_node_get_type_string(node : Ptr[cmark_node]): CString = extern 351 | 352 | /** 353 | * Returns the URL of a link or image 'node', or an empty string if no URL is set. Returns NULL if called on a node that is not a link or image. 354 | */ 355 | def cmark_node_get_url(node : Ptr[cmark_node]): CString = extern 356 | 357 | /** 358 | * Returns the user data of 'node'. 359 | */ 360 | def cmark_node_get_user_data(node : Ptr[cmark_node]): Ptr[Byte] = extern 361 | 362 | /** 363 | * Inserts 'sibling' after 'node'. Returns 1 on success, 0 on failure. 364 | */ 365 | def cmark_node_insert_after(node : Ptr[cmark_node], sibling : Ptr[cmark_node]): CInt = extern 366 | 367 | /** 368 | * Inserts 'sibling' before 'node'. Returns 1 on success, 0 on failure. 369 | */ 370 | def cmark_node_insert_before(node : Ptr[cmark_node], sibling : Ptr[cmark_node]): CInt = extern 371 | 372 | /** 373 | * Returns the last child of 'node', or NULL if 'node' has no children. 374 | */ 375 | def cmark_node_last_child(node : Ptr[cmark_node]): Ptr[cmark_node] = extern 376 | 377 | /** 378 | * Creates a new node of type 'type'. Note that the node may have other required properties, which it is the caller's responsibility to assign. 379 | */ 380 | def cmark_node_new(`type` : cmark_node_type): Ptr[cmark_node] = extern 381 | 382 | /** 383 | * Same as `cmark_node_new`, but explicitly listing the memory allocator used to allocate the node. Note: be sure to use the same allocator for every node in a tree, or bad things can happen. 384 | */ 385 | def cmark_node_new_with_mem(`type` : cmark_node_type, mem : Ptr[cmark_mem]): Ptr[cmark_node] = extern 386 | 387 | /** 388 | * Returns the next node in the sequence after 'node', or NULL if there is none. 389 | */ 390 | def cmark_node_next(node : Ptr[cmark_node]): Ptr[cmark_node] = extern 391 | 392 | /** 393 | * Returns the parent of 'node', or NULL if there is none. 394 | */ 395 | def cmark_node_parent(node : Ptr[cmark_node]): Ptr[cmark_node] = extern 396 | 397 | /** 398 | * Adds 'child' to the beginning of the children of 'node'. Returns 1 on success, 0 on failure. 399 | */ 400 | def cmark_node_prepend_child(node : Ptr[cmark_node], child : Ptr[cmark_node]): CInt = extern 401 | 402 | /** 403 | * Returns the previous node in the sequence after 'node', or NULL if there is none. 404 | */ 405 | def cmark_node_previous(node : Ptr[cmark_node]): Ptr[cmark_node] = extern 406 | 407 | /** 408 | * Replaces 'oldnode' with 'newnode' and unlinks 'oldnode' (but does not free its memory). Returns 1 on success, 0 on failure. 409 | */ 410 | def cmark_node_replace(oldnode : Ptr[cmark_node], newnode : Ptr[cmark_node]): CInt = extern 411 | 412 | /** 413 | * Sets the info string in a fenced code block, returning 1 on success and 0 on failure. 414 | */ 415 | def cmark_node_set_fence_info(node : Ptr[cmark_node], info : CString): CInt = extern 416 | 417 | /** 418 | * Sets the heading level of 'node', returning 1 on success and 0 on error. 419 | */ 420 | def cmark_node_set_heading_level(node : Ptr[cmark_node], level : CInt): CInt = extern 421 | 422 | /** 423 | * Sets the list delimiter type of 'node', returning 1 on success and 0 on error. 424 | */ 425 | def cmark_node_set_list_delim(node : Ptr[cmark_node], delim : cmark_delim_type): CInt = extern 426 | 427 | /** 428 | * Sets starting number of 'node', if it is an ordered list. Returns 1 on success, 0 on failure. 429 | */ 430 | def cmark_node_set_list_start(node : Ptr[cmark_node], start : CInt): CInt = extern 431 | 432 | /** 433 | * Sets the "tightness" of a list. Returns 1 on success, 0 on failure. 434 | */ 435 | def cmark_node_set_list_tight(node : Ptr[cmark_node], tight : CInt): CInt = extern 436 | 437 | /** 438 | * Sets the list type of 'node', returning 1 on success and 0 on error. 439 | */ 440 | def cmark_node_set_list_type(node : Ptr[cmark_node], `type` : cmark_list_type): CInt = extern 441 | 442 | /** 443 | * Sets the string contents of 'node'. Returns 1 on success, 0 on failure. 444 | */ 445 | def cmark_node_set_literal(node : Ptr[cmark_node], content : CString): CInt = extern 446 | 447 | /** 448 | * Sets the literal text to render "on enter" for a custom 'node'. Any children of the node will be rendered after this text. Returns 1 on success 0 on failure. 449 | */ 450 | def cmark_node_set_on_enter(node : Ptr[cmark_node], on_enter : CString): CInt = extern 451 | 452 | /** 453 | * Sets the literal text to render "on exit" for a custom 'node'. Any children of the node will be rendered before this text. Returns 1 on success 0 on failure. 454 | */ 455 | def cmark_node_set_on_exit(node : Ptr[cmark_node], on_exit : CString): CInt = extern 456 | 457 | /** 458 | * Sets the title of a link or image 'node'. Returns 1 on success, 0 on failure. 459 | */ 460 | def cmark_node_set_title(node : Ptr[cmark_node], title : CString): CInt = extern 461 | 462 | /** 463 | * Sets the URL of a link or image 'node'. Returns 1 on success, 0 on failure. 464 | */ 465 | def cmark_node_set_url(node : Ptr[cmark_node], url : CString): CInt = extern 466 | 467 | /** 468 | * Sets arbitrary user data for 'node'. Returns 1 on success, 0 on failure. 469 | */ 470 | def cmark_node_set_user_data(node : Ptr[cmark_node], user_data : Ptr[Byte]): CInt = extern 471 | 472 | /** 473 | * Unlinks a 'node', removing it from the tree, but not freeing its memory. (Use 'cmark_node_free' for that.) 474 | */ 475 | def cmark_node_unlink(node : Ptr[cmark_node]): Unit = extern 476 | 477 | /** 478 | * Parse a CommonMark document in 'buffer' of length 'len'. Returns a pointer to a tree of nodes. The memory allocated for the node tree should be released using 'cmark_node_free' when it is no longer needed. 479 | */ 480 | def cmark_parse_document(buffer : CString, len : size_t, options : CInt): Ptr[cmark_node] = extern 481 | 482 | /** 483 | * Parse a CommonMark document in file 'f', returning a pointer to a tree of nodes. The memory allocated for the node tree should be released using 'cmark_node_free' when it is no longer needed. 484 | */ 485 | def cmark_parse_file(f : Ptr[FILE], options : CInt): Ptr[cmark_node] = extern 486 | 487 | /** 488 | * Feeds a string of length 'len' to 'parser'. 489 | */ 490 | def cmark_parser_feed(parser : Ptr[cmark_parser], buffer : CString, len : size_t): Unit = extern 491 | 492 | /** 493 | * Finish parsing and return a pointer to a tree of nodes. 494 | */ 495 | def cmark_parser_finish(parser : Ptr[cmark_parser]): Ptr[cmark_node] = extern 496 | 497 | /** 498 | * Frees memory allocated for a parser object. 499 | */ 500 | def cmark_parser_free(parser : Ptr[cmark_parser]): Unit = extern 501 | 502 | /** 503 | * Creates a new parser object. 504 | */ 505 | def cmark_parser_new(options : CInt): Ptr[cmark_parser] = extern 506 | 507 | /** 508 | * Creates a new parser object with the given memory allocator 509 | */ 510 | def cmark_parser_new_with_mem(options : CInt, mem : Ptr[cmark_mem]): Ptr[cmark_parser] = extern 511 | 512 | /** 513 | * Render a 'node' tree as a commonmark document. It is the caller's responsibility to free the returned buffer. 514 | */ 515 | def cmark_render_commonmark(root : Ptr[cmark_node], options : CInt, width : CInt): CString = extern 516 | 517 | /** 518 | * Render a 'node' tree as an HTML fragment. It is up to the user to add an appropriate header and footer. It is the caller's responsibility to free the returned buffer. 519 | */ 520 | def cmark_render_html(root : Ptr[cmark_node], options : CInt): CString = extern 521 | 522 | /** 523 | * Render a 'node' tree as a LaTeX document. It is the caller's responsibility to free the returned buffer. 524 | */ 525 | def cmark_render_latex(root : Ptr[cmark_node], options : CInt, width : CInt): CString = extern 526 | 527 | /** 528 | * Render a 'node' tree as a groff man page, without the header. It is the caller's responsibility to free the returned buffer. 529 | */ 530 | def cmark_render_man(root : Ptr[cmark_node], options : CInt, width : CInt): CString = extern 531 | 532 | /** 533 | * Render a 'node' tree as XML. It is the caller's responsibility to free the returned buffer. 534 | */ 535 | def cmark_render_xml(root : Ptr[cmark_node], options : CInt): CString = extern 536 | 537 | /** 538 | * The library version as integer for runtime checks. Also available as macro CMARK_VERSION for compile time checks. 539 | */ 540 | def cmark_version(): CInt = extern 541 | 542 | /** 543 | * The library version string for runtime checks. Also available as macro CMARK_VERSION_STRING for compile time checks. 544 | */ 545 | def cmark_version_string(): CString = extern 546 | 547 | 548 | object functions: 549 | import _root_.cmark.enumerations.* 550 | import _root_.cmark.predef.* 551 | import _root_.cmark.aliases.* 552 | import _root_.cmark.structs.* 553 | import extern_functions.* 554 | export extern_functions.* 555 | 556 | object types: 557 | export _root_.cmark.structs.* 558 | export _root_.cmark.aliases.* 559 | export _root_.cmark.enumerations.* 560 | 561 | object all: 562 | export _root_.cmark.enumerations.cmark_delim_type 563 | export _root_.cmark.enumerations.cmark_event_type 564 | export _root_.cmark.enumerations.cmark_list_type 565 | export _root_.cmark.enumerations.cmark_node_type 566 | export _root_.cmark.aliases.FILE 567 | export _root_.cmark.aliases.size_t 568 | export _root_.cmark.structs.cmark_iter 569 | export _root_.cmark.structs.cmark_mem 570 | export _root_.cmark.structs.cmark_node 571 | export _root_.cmark.structs.cmark_parser 572 | export _root_.cmark.functions.cmark_consolidate_text_nodes 573 | export _root_.cmark.functions.cmark_get_default_mem_allocator 574 | export _root_.cmark.functions.cmark_iter_free 575 | export _root_.cmark.functions.cmark_iter_get_event_type 576 | export _root_.cmark.functions.cmark_iter_get_node 577 | export _root_.cmark.functions.cmark_iter_get_root 578 | export _root_.cmark.functions.cmark_iter_new 579 | export _root_.cmark.functions.cmark_iter_next 580 | export _root_.cmark.functions.cmark_iter_reset 581 | export _root_.cmark.functions.cmark_markdown_to_html 582 | export _root_.cmark.functions.cmark_node_append_child 583 | export _root_.cmark.functions.cmark_node_first_child 584 | export _root_.cmark.functions.cmark_node_free 585 | export _root_.cmark.functions.cmark_node_get_end_column 586 | export _root_.cmark.functions.cmark_node_get_end_line 587 | export _root_.cmark.functions.cmark_node_get_fence_info 588 | export _root_.cmark.functions.cmark_node_get_heading_level 589 | export _root_.cmark.functions.cmark_node_get_list_delim 590 | export _root_.cmark.functions.cmark_node_get_list_start 591 | export _root_.cmark.functions.cmark_node_get_list_tight 592 | export _root_.cmark.functions.cmark_node_get_list_type 593 | export _root_.cmark.functions.cmark_node_get_literal 594 | export _root_.cmark.functions.cmark_node_get_on_enter 595 | export _root_.cmark.functions.cmark_node_get_on_exit 596 | export _root_.cmark.functions.cmark_node_get_start_column 597 | export _root_.cmark.functions.cmark_node_get_start_line 598 | export _root_.cmark.functions.cmark_node_get_title 599 | export _root_.cmark.functions.cmark_node_get_type 600 | export _root_.cmark.functions.cmark_node_get_type_string 601 | export _root_.cmark.functions.cmark_node_get_url 602 | export _root_.cmark.functions.cmark_node_get_user_data 603 | export _root_.cmark.functions.cmark_node_insert_after 604 | export _root_.cmark.functions.cmark_node_insert_before 605 | export _root_.cmark.functions.cmark_node_last_child 606 | export _root_.cmark.functions.cmark_node_new 607 | export _root_.cmark.functions.cmark_node_new_with_mem 608 | export _root_.cmark.functions.cmark_node_next 609 | export _root_.cmark.functions.cmark_node_parent 610 | export _root_.cmark.functions.cmark_node_prepend_child 611 | export _root_.cmark.functions.cmark_node_previous 612 | export _root_.cmark.functions.cmark_node_replace 613 | export _root_.cmark.functions.cmark_node_set_fence_info 614 | export _root_.cmark.functions.cmark_node_set_heading_level 615 | export _root_.cmark.functions.cmark_node_set_list_delim 616 | export _root_.cmark.functions.cmark_node_set_list_start 617 | export _root_.cmark.functions.cmark_node_set_list_tight 618 | export _root_.cmark.functions.cmark_node_set_list_type 619 | export _root_.cmark.functions.cmark_node_set_literal 620 | export _root_.cmark.functions.cmark_node_set_on_enter 621 | export _root_.cmark.functions.cmark_node_set_on_exit 622 | export _root_.cmark.functions.cmark_node_set_title 623 | export _root_.cmark.functions.cmark_node_set_url 624 | export _root_.cmark.functions.cmark_node_set_user_data 625 | export _root_.cmark.functions.cmark_node_unlink 626 | export _root_.cmark.functions.cmark_parse_document 627 | export _root_.cmark.functions.cmark_parse_file 628 | export _root_.cmark.functions.cmark_parser_feed 629 | export _root_.cmark.functions.cmark_parser_finish 630 | export _root_.cmark.functions.cmark_parser_free 631 | export _root_.cmark.functions.cmark_parser_new 632 | export _root_.cmark.functions.cmark_parser_new_with_mem 633 | export _root_.cmark.functions.cmark_render_commonmark 634 | export _root_.cmark.functions.cmark_render_html 635 | export _root_.cmark.functions.cmark_render_latex 636 | export _root_.cmark.functions.cmark_render_man 637 | export _root_.cmark.functions.cmark_render_xml 638 | export _root_.cmark.functions.cmark_version 639 | export _root_.cmark.functions.cmark_version_string -------------------------------------------------------------------------------- /mod/treesitter-bindings/src/main/scala/generated/tree_sitter.scala: -------------------------------------------------------------------------------- 1 | package tree_sitter 2 | 3 | import _root_.scala.scalanative.unsafe.* 4 | import _root_.scala.scalanative.unsigned.* 5 | import _root_.scala.scalanative.libc.* 6 | import _root_.scala.scalanative.* 7 | 8 | object predef: 9 | private[tree_sitter] trait CEnumU[T](using eq: T =:= UInt): 10 | given Tag[T] = Tag.UInt.asInstanceOf[Tag[T]] 11 | extension (inline t: T) 12 | inline def int: CInt = eq.apply(t).toInt 13 | inline def uint: CUnsignedInt = eq.apply(t) 14 | inline def value: CUnsignedInt = eq.apply(t) 15 | 16 | 17 | object enumerations: 18 | import predef.* 19 | opaque type TSInputEncoding = CUnsignedInt 20 | object TSInputEncoding extends CEnumU[TSInputEncoding]: 21 | given _tag: Tag[TSInputEncoding] = Tag.UInt 22 | inline def define(inline a: Long): TSInputEncoding = a.toUInt 23 | val TSInputEncodingUTF8 = define(0) 24 | val TSInputEncodingUTF16 = define(1) 25 | inline def getName(inline value: TSInputEncoding): Option[String] = 26 | inline value match 27 | case TSInputEncodingUTF8 => Some("TSInputEncodingUTF8") 28 | case TSInputEncodingUTF16 => Some("TSInputEncodingUTF16") 29 | case _ => _root_.scala.None 30 | extension (a: TSInputEncoding) 31 | inline def &(b: TSInputEncoding): TSInputEncoding = a & b 32 | inline def |(b: TSInputEncoding): TSInputEncoding = a | b 33 | inline def is(b: TSInputEncoding): Boolean = (a & b) == b 34 | 35 | opaque type TSLogType = CUnsignedInt 36 | object TSLogType extends CEnumU[TSLogType]: 37 | given _tag: Tag[TSLogType] = Tag.UInt 38 | inline def define(inline a: Long): TSLogType = a.toUInt 39 | val TSLogTypeParse = define(0) 40 | val TSLogTypeLex = define(1) 41 | inline def getName(inline value: TSLogType): Option[String] = 42 | inline value match 43 | case TSLogTypeParse => Some("TSLogTypeParse") 44 | case TSLogTypeLex => Some("TSLogTypeLex") 45 | case _ => _root_.scala.None 46 | extension (a: TSLogType) 47 | inline def &(b: TSLogType): TSLogType = a & b 48 | inline def |(b: TSLogType): TSLogType = a | b 49 | inline def is(b: TSLogType): Boolean = (a & b) == b 50 | 51 | opaque type TSQuantifier = CUnsignedInt 52 | object TSQuantifier extends CEnumU[TSQuantifier]: 53 | given _tag: Tag[TSQuantifier] = Tag.UInt 54 | inline def define(inline a: Long): TSQuantifier = a.toUInt 55 | val TSQuantifierZero = define(0) 56 | val TSQuantifierZeroOrOne = define(1) 57 | val TSQuantifierZeroOrMore = define(2) 58 | val TSQuantifierOne = define(3) 59 | val TSQuantifierOneOrMore = define(4) 60 | inline def getName(inline value: TSQuantifier): Option[String] = 61 | inline value match 62 | case TSQuantifierZero => Some("TSQuantifierZero") 63 | case TSQuantifierZeroOrOne => Some("TSQuantifierZeroOrOne") 64 | case TSQuantifierZeroOrMore => Some("TSQuantifierZeroOrMore") 65 | case TSQuantifierOne => Some("TSQuantifierOne") 66 | case TSQuantifierOneOrMore => Some("TSQuantifierOneOrMore") 67 | case _ => _root_.scala.None 68 | extension (a: TSQuantifier) 69 | inline def &(b: TSQuantifier): TSQuantifier = a & b 70 | inline def |(b: TSQuantifier): TSQuantifier = a | b 71 | inline def is(b: TSQuantifier): Boolean = (a & b) == b 72 | 73 | opaque type TSQueryError = CUnsignedInt 74 | object TSQueryError extends CEnumU[TSQueryError]: 75 | given _tag: Tag[TSQueryError] = Tag.UInt 76 | inline def define(inline a: Long): TSQueryError = a.toUInt 77 | val TSQueryErrorNone = define(0) 78 | val TSQueryErrorSyntax = define(1) 79 | val TSQueryErrorNodeType = define(2) 80 | val TSQueryErrorField = define(3) 81 | val TSQueryErrorCapture = define(4) 82 | val TSQueryErrorStructure = define(5) 83 | val TSQueryErrorLanguage = define(6) 84 | inline def getName(inline value: TSQueryError): Option[String] = 85 | inline value match 86 | case TSQueryErrorNone => Some("TSQueryErrorNone") 87 | case TSQueryErrorSyntax => Some("TSQueryErrorSyntax") 88 | case TSQueryErrorNodeType => Some("TSQueryErrorNodeType") 89 | case TSQueryErrorField => Some("TSQueryErrorField") 90 | case TSQueryErrorCapture => Some("TSQueryErrorCapture") 91 | case TSQueryErrorStructure => Some("TSQueryErrorStructure") 92 | case TSQueryErrorLanguage => Some("TSQueryErrorLanguage") 93 | case _ => _root_.scala.None 94 | extension (a: TSQueryError) 95 | inline def &(b: TSQueryError): TSQueryError = a & b 96 | inline def |(b: TSQueryError): TSQueryError = a | b 97 | inline def is(b: TSQueryError): Boolean = (a & b) == b 98 | 99 | opaque type TSQueryPredicateStepType = CUnsignedInt 100 | object TSQueryPredicateStepType extends CEnumU[TSQueryPredicateStepType]: 101 | given _tag: Tag[TSQueryPredicateStepType] = Tag.UInt 102 | inline def define(inline a: Long): TSQueryPredicateStepType = a.toUInt 103 | val TSQueryPredicateStepTypeDone = define(0) 104 | val TSQueryPredicateStepTypeCapture = define(1) 105 | val TSQueryPredicateStepTypeString = define(2) 106 | inline def getName(inline value: TSQueryPredicateStepType): Option[String] = 107 | inline value match 108 | case TSQueryPredicateStepTypeDone => Some("TSQueryPredicateStepTypeDone") 109 | case TSQueryPredicateStepTypeCapture => Some("TSQueryPredicateStepTypeCapture") 110 | case TSQueryPredicateStepTypeString => Some("TSQueryPredicateStepTypeString") 111 | case _ => _root_.scala.None 112 | extension (a: TSQueryPredicateStepType) 113 | inline def &(b: TSQueryPredicateStepType): TSQueryPredicateStepType = a & b 114 | inline def |(b: TSQueryPredicateStepType): TSQueryPredicateStepType = a | b 115 | inline def is(b: TSQueryPredicateStepType): Boolean = (a & b) == b 116 | 117 | opaque type TSSymbolType = CUnsignedInt 118 | object TSSymbolType extends CEnumU[TSSymbolType]: 119 | given _tag: Tag[TSSymbolType] = Tag.UInt 120 | inline def define(inline a: Long): TSSymbolType = a.toUInt 121 | val TSSymbolTypeRegular = define(0) 122 | val TSSymbolTypeAnonymous = define(1) 123 | val TSSymbolTypeAuxiliary = define(2) 124 | inline def getName(inline value: TSSymbolType): Option[String] = 125 | inline value match 126 | case TSSymbolTypeRegular => Some("TSSymbolTypeRegular") 127 | case TSSymbolTypeAnonymous => Some("TSSymbolTypeAnonymous") 128 | case TSSymbolTypeAuxiliary => Some("TSSymbolTypeAuxiliary") 129 | case _ => _root_.scala.None 130 | extension (a: TSSymbolType) 131 | inline def &(b: TSSymbolType): TSSymbolType = a & b 132 | inline def |(b: TSSymbolType): TSSymbolType = a | b 133 | inline def is(b: TSSymbolType): Boolean = (a & b) == b 134 | 135 | object aliases: 136 | import _root_.tree_sitter.enumerations.* 137 | import _root_.tree_sitter.predef.* 138 | import _root_.tree_sitter.aliases.* 139 | import _root_.tree_sitter.structs.* 140 | type FILE = libc.stdio.FILE 141 | object FILE: 142 | val _tag: Tag[FILE] = summon[Tag[libc.stdio.FILE]] 143 | inline def apply(inline o: libc.stdio.FILE): FILE = o 144 | extension (v: FILE) 145 | inline def value: libc.stdio.FILE = v 146 | 147 | type TSFieldId = uint16_t 148 | object TSFieldId: 149 | given _tag: Tag[TSFieldId] = uint16_t._tag 150 | inline def apply(inline o: uint16_t): TSFieldId = o 151 | extension (v: TSFieldId) 152 | inline def value: uint16_t = v 153 | 154 | /** 155 | * **************** 156 | */ 157 | type TSSymbol = uint16_t 158 | object TSSymbol: 159 | given _tag: Tag[TSSymbol] = uint16_t._tag 160 | inline def apply(inline o: uint16_t): TSSymbol = o 161 | extension (v: TSSymbol) 162 | inline def value: uint16_t = v 163 | 164 | type int64_t = scala.Long 165 | object int64_t: 166 | val _tag: Tag[int64_t] = summon[Tag[scala.Long]] 167 | inline def apply(inline o: scala.Long): int64_t = o 168 | extension (v: int64_t) 169 | inline def value: scala.Long = v 170 | 171 | type size_t = libc.stddef.size_t 172 | object size_t: 173 | val _tag: Tag[size_t] = summon[Tag[libc.stddef.size_t]] 174 | inline def apply(inline o: libc.stddef.size_t): size_t = o 175 | extension (v: size_t) 176 | inline def value: libc.stddef.size_t = v 177 | 178 | type uint16_t = scala.scalanative.unsigned.UShort 179 | object uint16_t: 180 | val _tag: Tag[uint16_t] = summon[Tag[scala.scalanative.unsigned.UShort]] 181 | inline def apply(inline o: scala.scalanative.unsigned.UShort): uint16_t = o 182 | extension (v: uint16_t) 183 | inline def value: scala.scalanative.unsigned.UShort = v 184 | 185 | type uint32_t = scala.scalanative.unsigned.UInt 186 | object uint32_t: 187 | val _tag: Tag[uint32_t] = summon[Tag[scala.scalanative.unsigned.UInt]] 188 | inline def apply(inline o: scala.scalanative.unsigned.UInt): uint32_t = o 189 | extension (v: uint32_t) 190 | inline def value: scala.scalanative.unsigned.UInt = v 191 | 192 | type uint64_t = scala.scalanative.unsigned.ULong 193 | object uint64_t: 194 | val _tag: Tag[uint64_t] = summon[Tag[scala.scalanative.unsigned.ULong]] 195 | inline def apply(inline o: scala.scalanative.unsigned.ULong): uint64_t = o 196 | extension (v: uint64_t) 197 | inline def value: scala.scalanative.unsigned.ULong = v 198 | 199 | object structs: 200 | import _root_.tree_sitter.enumerations.* 201 | import _root_.tree_sitter.predef.* 202 | import _root_.tree_sitter.aliases.* 203 | import _root_.tree_sitter.structs.* 204 | opaque type TSInput = CStruct3[Ptr[Byte], CFuncPtr4[Ptr[Byte], uint32_t, TSPoint, Ptr[uint32_t], CString], TSInputEncoding] 205 | object TSInput: 206 | given _tag: Tag[TSInput] = Tag.materializeCStruct3Tag[Ptr[Byte], CFuncPtr4[Ptr[Byte], uint32_t, TSPoint, Ptr[uint32_t], CString], TSInputEncoding] 207 | def apply()(using Zone): Ptr[TSInput] = scala.scalanative.unsafe.alloc[TSInput](1) 208 | def apply(payload : Ptr[Byte], read : CFuncPtr4[Ptr[Byte], uint32_t, TSPoint, Ptr[uint32_t], CString], encoding : TSInputEncoding)(using Zone): Ptr[TSInput] = 209 | val ____ptr = apply() 210 | (!____ptr).payload = payload 211 | (!____ptr).read = read 212 | (!____ptr).encoding = encoding 213 | ____ptr 214 | extension (struct: TSInput) 215 | def payload : Ptr[Byte] = struct._1 216 | def payload_=(value: Ptr[Byte]): Unit = !struct.at1 = value 217 | def read : CFuncPtr4[Ptr[Byte], uint32_t, TSPoint, Ptr[uint32_t], CString] = struct._2 218 | def read_=(value: CFuncPtr4[Ptr[Byte], uint32_t, TSPoint, Ptr[uint32_t], CString]): Unit = !struct.at2 = value 219 | def encoding : TSInputEncoding = struct._3 220 | def encoding_=(value: TSInputEncoding): Unit = !struct.at3 = value 221 | 222 | opaque type TSInputEdit = CStruct6[uint32_t, uint32_t, uint32_t, TSPoint, TSPoint, TSPoint] 223 | object TSInputEdit: 224 | given _tag: Tag[TSInputEdit] = Tag.materializeCStruct6Tag[uint32_t, uint32_t, uint32_t, TSPoint, TSPoint, TSPoint] 225 | def apply()(using Zone): Ptr[TSInputEdit] = scala.scalanative.unsafe.alloc[TSInputEdit](1) 226 | def apply(start_byte : uint32_t, old_end_byte : uint32_t, new_end_byte : uint32_t, start_point : TSPoint, old_end_point : TSPoint, new_end_point : TSPoint)(using Zone): Ptr[TSInputEdit] = 227 | val ____ptr = apply() 228 | (!____ptr).start_byte = start_byte 229 | (!____ptr).old_end_byte = old_end_byte 230 | (!____ptr).new_end_byte = new_end_byte 231 | (!____ptr).start_point = start_point 232 | (!____ptr).old_end_point = old_end_point 233 | (!____ptr).new_end_point = new_end_point 234 | ____ptr 235 | extension (struct: TSInputEdit) 236 | def start_byte : uint32_t = struct._1 237 | def start_byte_=(value: uint32_t): Unit = !struct.at1 = value 238 | def old_end_byte : uint32_t = struct._2 239 | def old_end_byte_=(value: uint32_t): Unit = !struct.at2 = value 240 | def new_end_byte : uint32_t = struct._3 241 | def new_end_byte_=(value: uint32_t): Unit = !struct.at3 = value 242 | def start_point : TSPoint = struct._4 243 | def start_point_=(value: TSPoint): Unit = !struct.at4 = value 244 | def old_end_point : TSPoint = struct._5 245 | def old_end_point_=(value: TSPoint): Unit = !struct.at5 = value 246 | def new_end_point : TSPoint = struct._6 247 | def new_end_point_=(value: TSPoint): Unit = !struct.at6 = value 248 | 249 | opaque type TSLanguage = CStruct0 250 | object TSLanguage: 251 | given _tag: Tag[TSLanguage] = Tag.materializeCStruct0Tag 252 | 253 | opaque type TSLogger = CStruct2[Ptr[Byte], CFuncPtr3[Ptr[Byte], TSLogType, CString, Unit]] 254 | object TSLogger: 255 | given _tag: Tag[TSLogger] = Tag.materializeCStruct2Tag[Ptr[Byte], CFuncPtr3[Ptr[Byte], TSLogType, CString, Unit]] 256 | def apply()(using Zone): Ptr[TSLogger] = scala.scalanative.unsafe.alloc[TSLogger](1) 257 | def apply(payload : Ptr[Byte], log : CFuncPtr3[Ptr[Byte], TSLogType, CString, Unit])(using Zone): Ptr[TSLogger] = 258 | val ____ptr = apply() 259 | (!____ptr).payload = payload 260 | (!____ptr).log = log 261 | ____ptr 262 | extension (struct: TSLogger) 263 | def payload : Ptr[Byte] = struct._1 264 | def payload_=(value: Ptr[Byte]): Unit = !struct.at1 = value 265 | def log : CFuncPtr3[Ptr[Byte], TSLogType, CString, Unit] = struct._2 266 | def log_=(value: CFuncPtr3[Ptr[Byte], TSLogType, CString, Unit]): Unit = !struct.at2 = value 267 | 268 | opaque type TSNode = CStruct3[CArray[uint32_t, Nat._4], Ptr[Byte], Ptr[TSTree]] 269 | object TSNode: 270 | given _tag: Tag[TSNode] = Tag.materializeCStruct3Tag[CArray[uint32_t, Nat._4], Ptr[Byte], Ptr[TSTree]] 271 | def apply()(using Zone): Ptr[TSNode] = scala.scalanative.unsafe.alloc[TSNode](1) 272 | def apply(context : CArray[uint32_t, Nat._4], id : Ptr[Byte], tree : Ptr[TSTree])(using Zone): Ptr[TSNode] = 273 | val ____ptr = apply() 274 | (!____ptr).context = context 275 | (!____ptr).id = id 276 | (!____ptr).tree = tree 277 | ____ptr 278 | extension (struct: TSNode) 279 | def context : CArray[uint32_t, Nat._4] = struct._1 280 | def context_=(value: CArray[uint32_t, Nat._4]): Unit = !struct.at1 = value 281 | def id : Ptr[Byte] = struct._2 282 | def id_=(value: Ptr[Byte]): Unit = !struct.at2 = value 283 | def tree : Ptr[TSTree] = struct._3 284 | def tree_=(value: Ptr[TSTree]): Unit = !struct.at3 = value 285 | 286 | opaque type TSParser = CStruct0 287 | object TSParser: 288 | given _tag: Tag[TSParser] = Tag.materializeCStruct0Tag 289 | 290 | opaque type TSPoint = CStruct2[uint32_t, uint32_t] 291 | object TSPoint: 292 | given _tag: Tag[TSPoint] = Tag.materializeCStruct2Tag[uint32_t, uint32_t] 293 | def apply()(using Zone): Ptr[TSPoint] = scala.scalanative.unsafe.alloc[TSPoint](1) 294 | def apply(row : uint32_t, column : uint32_t)(using Zone): Ptr[TSPoint] = 295 | val ____ptr = apply() 296 | (!____ptr).row = row 297 | (!____ptr).column = column 298 | ____ptr 299 | extension (struct: TSPoint) 300 | def row : uint32_t = struct._1 301 | def row_=(value: uint32_t): Unit = !struct.at1 = value 302 | def column : uint32_t = struct._2 303 | def column_=(value: uint32_t): Unit = !struct.at2 = value 304 | 305 | opaque type TSQuery = CStruct0 306 | object TSQuery: 307 | given _tag: Tag[TSQuery] = Tag.materializeCStruct0Tag 308 | 309 | opaque type TSQueryCapture = CStruct2[TSNode, uint32_t] 310 | object TSQueryCapture: 311 | given _tag: Tag[TSQueryCapture] = Tag.materializeCStruct2Tag[TSNode, uint32_t] 312 | def apply()(using Zone): Ptr[TSQueryCapture] = scala.scalanative.unsafe.alloc[TSQueryCapture](1) 313 | def apply(node : TSNode, index : uint32_t)(using Zone): Ptr[TSQueryCapture] = 314 | val ____ptr = apply() 315 | (!____ptr).node = node 316 | (!____ptr).index = index 317 | ____ptr 318 | extension (struct: TSQueryCapture) 319 | def node : TSNode = struct._1 320 | def node_=(value: TSNode): Unit = !struct.at1 = value 321 | def index : uint32_t = struct._2 322 | def index_=(value: uint32_t): Unit = !struct.at2 = value 323 | 324 | opaque type TSQueryCursor = CStruct0 325 | object TSQueryCursor: 326 | given _tag: Tag[TSQueryCursor] = Tag.materializeCStruct0Tag 327 | 328 | opaque type TSQueryMatch = CStruct4[uint32_t, uint16_t, uint16_t, Ptr[TSQueryCapture]] 329 | object TSQueryMatch: 330 | given _tag: Tag[TSQueryMatch] = Tag.materializeCStruct4Tag[uint32_t, uint16_t, uint16_t, Ptr[TSQueryCapture]] 331 | def apply()(using Zone): Ptr[TSQueryMatch] = scala.scalanative.unsafe.alloc[TSQueryMatch](1) 332 | def apply(id : uint32_t, pattern_index : uint16_t, capture_count : uint16_t, captures : Ptr[TSQueryCapture])(using Zone): Ptr[TSQueryMatch] = 333 | val ____ptr = apply() 334 | (!____ptr).id = id 335 | (!____ptr).pattern_index = pattern_index 336 | (!____ptr).capture_count = capture_count 337 | (!____ptr).captures = captures 338 | ____ptr 339 | extension (struct: TSQueryMatch) 340 | def id : uint32_t = struct._1 341 | def id_=(value: uint32_t): Unit = !struct.at1 = value 342 | def pattern_index : uint16_t = struct._2 343 | def pattern_index_=(value: uint16_t): Unit = !struct.at2 = value 344 | def capture_count : uint16_t = struct._3 345 | def capture_count_=(value: uint16_t): Unit = !struct.at3 = value 346 | def captures : Ptr[TSQueryCapture] = struct._4 347 | def captures_=(value: Ptr[TSQueryCapture]): Unit = !struct.at4 = value 348 | 349 | opaque type TSQueryPredicateStep = CStruct2[TSQueryPredicateStepType, uint32_t] 350 | object TSQueryPredicateStep: 351 | given _tag: Tag[TSQueryPredicateStep] = Tag.materializeCStruct2Tag[TSQueryPredicateStepType, uint32_t] 352 | def apply()(using Zone): Ptr[TSQueryPredicateStep] = scala.scalanative.unsafe.alloc[TSQueryPredicateStep](1) 353 | def apply(`type` : TSQueryPredicateStepType, value_id : uint32_t)(using Zone): Ptr[TSQueryPredicateStep] = 354 | val ____ptr = apply() 355 | (!____ptr).`type` = `type` 356 | (!____ptr).value_id = value_id 357 | ____ptr 358 | extension (struct: TSQueryPredicateStep) 359 | def `type` : TSQueryPredicateStepType = struct._1 360 | def type_=(value: TSQueryPredicateStepType): Unit = !struct.at1 = value 361 | def value_id : uint32_t = struct._2 362 | def value_id_=(value: uint32_t): Unit = !struct.at2 = value 363 | 364 | opaque type TSRange = CStruct4[TSPoint, TSPoint, uint32_t, uint32_t] 365 | object TSRange: 366 | given _tag: Tag[TSRange] = Tag.materializeCStruct4Tag[TSPoint, TSPoint, uint32_t, uint32_t] 367 | def apply()(using Zone): Ptr[TSRange] = scala.scalanative.unsafe.alloc[TSRange](1) 368 | def apply(start_point : TSPoint, end_point : TSPoint, start_byte : uint32_t, end_byte : uint32_t)(using Zone): Ptr[TSRange] = 369 | val ____ptr = apply() 370 | (!____ptr).start_point = start_point 371 | (!____ptr).end_point = end_point 372 | (!____ptr).start_byte = start_byte 373 | (!____ptr).end_byte = end_byte 374 | ____ptr 375 | extension (struct: TSRange) 376 | def start_point : TSPoint = struct._1 377 | def start_point_=(value: TSPoint): Unit = !struct.at1 = value 378 | def end_point : TSPoint = struct._2 379 | def end_point_=(value: TSPoint): Unit = !struct.at2 = value 380 | def start_byte : uint32_t = struct._3 381 | def start_byte_=(value: uint32_t): Unit = !struct.at3 = value 382 | def end_byte : uint32_t = struct._4 383 | def end_byte_=(value: uint32_t): Unit = !struct.at4 = value 384 | 385 | opaque type TSTree = CStruct0 386 | object TSTree: 387 | given _tag: Tag[TSTree] = Tag.materializeCStruct0Tag 388 | 389 | opaque type TSTreeCursor = CStruct3[Ptr[Byte], Ptr[Byte], CArray[uint32_t, Nat._2]] 390 | object TSTreeCursor: 391 | given _tag: Tag[TSTreeCursor] = Tag.materializeCStruct3Tag[Ptr[Byte], Ptr[Byte], CArray[uint32_t, Nat._2]] 392 | def apply()(using Zone): Ptr[TSTreeCursor] = scala.scalanative.unsafe.alloc[TSTreeCursor](1) 393 | def apply(tree : Ptr[Byte], id : Ptr[Byte], context : CArray[uint32_t, Nat._2])(using Zone): Ptr[TSTreeCursor] = 394 | val ____ptr = apply() 395 | (!____ptr).tree = tree 396 | (!____ptr).id = id 397 | (!____ptr).context = context 398 | ____ptr 399 | extension (struct: TSTreeCursor) 400 | def tree : Ptr[Byte] = struct._1 401 | def tree_=(value: Ptr[Byte]): Unit = !struct.at1 = value 402 | def id : Ptr[Byte] = struct._2 403 | def id_=(value: Ptr[Byte]): Unit = !struct.at2 = value 404 | def context : CArray[uint32_t, Nat._2] = struct._3 405 | def context_=(value: CArray[uint32_t, Nat._2]): Unit = !struct.at3 = value 406 | 407 | 408 | @extern 409 | private[tree_sitter] object extern_functions: 410 | import _root_.tree_sitter.enumerations.* 411 | import _root_.tree_sitter.predef.* 412 | import _root_.tree_sitter.aliases.* 413 | import _root_.tree_sitter.structs.* 414 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_child(_0 : Ptr[TSNode], _1 : uint32_t, __return : Ptr[TSNode]): Unit = extern 415 | 416 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_child_by_field_id(_0 : Ptr[TSNode], _1 : TSFieldId, __return : Ptr[TSNode]): Unit = extern 417 | 418 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_child_by_field_name(self : Ptr[TSNode], field_name : CString, field_name_length : uint32_t, __return : Ptr[TSNode]): Unit = extern 419 | 420 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_child_count(_0 : Ptr[TSNode]): uint32_t = extern 421 | 422 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_descendant_for_byte_range(_0 : Ptr[TSNode], _1 : uint32_t, _2 : uint32_t, __return : Ptr[TSNode]): Unit = extern 423 | 424 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_descendant_for_point_range(_0 : Ptr[TSNode], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint], __return : Ptr[TSNode]): Unit = extern 425 | 426 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_end_byte(_0 : Ptr[TSNode]): uint32_t = extern 427 | 428 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_end_point(_0 : Ptr[TSNode], __return : Ptr[TSPoint]): Unit = extern 429 | 430 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_eq(_0 : Ptr[TSNode], _1 : Ptr[TSNode]): Boolean = extern 431 | 432 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_field_name_for_child(_0 : Ptr[TSNode], _1 : uint32_t): CString = extern 433 | 434 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_first_child_for_byte(_0 : Ptr[TSNode], _1 : uint32_t, __return : Ptr[TSNode]): Unit = extern 435 | 436 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_first_named_child_for_byte(_0 : Ptr[TSNode], _1 : uint32_t, __return : Ptr[TSNode]): Unit = extern 437 | 438 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_has_changes(_0 : Ptr[TSNode]): Boolean = extern 439 | 440 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_has_error(_0 : Ptr[TSNode]): Boolean = extern 441 | 442 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_is_extra(_0 : Ptr[TSNode]): Boolean = extern 443 | 444 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_is_missing(_0 : Ptr[TSNode]): Boolean = extern 445 | 446 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_is_named(_0 : Ptr[TSNode]): Boolean = extern 447 | 448 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_is_null(_0 : Ptr[TSNode]): Boolean = extern 449 | 450 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_named_child(_0 : Ptr[TSNode], _1 : uint32_t, __return : Ptr[TSNode]): Unit = extern 451 | 452 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_named_child_count(_0 : Ptr[TSNode]): uint32_t = extern 453 | 454 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_named_descendant_for_byte_range(_0 : Ptr[TSNode], _1 : uint32_t, _2 : uint32_t, __return : Ptr[TSNode]): Unit = extern 455 | 456 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_named_descendant_for_point_range(_0 : Ptr[TSNode], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint], __return : Ptr[TSNode]): Unit = extern 457 | 458 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_next_named_sibling(_0 : Ptr[TSNode], __return : Ptr[TSNode]): Unit = extern 459 | 460 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_next_sibling(_0 : Ptr[TSNode], __return : Ptr[TSNode]): Unit = extern 461 | 462 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_parent(_0 : Ptr[TSNode], __return : Ptr[TSNode]): Unit = extern 463 | 464 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_prev_named_sibling(_0 : Ptr[TSNode], __return : Ptr[TSNode]): Unit = extern 465 | 466 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_prev_sibling(_0 : Ptr[TSNode], __return : Ptr[TSNode]): Unit = extern 467 | 468 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_start_byte(_0 : Ptr[TSNode]): uint32_t = extern 469 | 470 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_start_point(_0 : Ptr[TSNode], __return : Ptr[TSPoint]): Unit = extern 471 | 472 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_string(_0 : Ptr[TSNode]): CString = extern 473 | 474 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_symbol(_0 : Ptr[TSNode]): TSSymbol = extern 475 | 476 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_node_type(_0 : Ptr[TSNode]): CString = extern 477 | 478 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_parser_logger(self : Ptr[TSParser], __return : Ptr[TSLogger]): Unit = extern 479 | 480 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_parser_parse(self : Ptr[TSParser], old_tree : Ptr[TSTree], input : Ptr[TSInput]): Ptr[TSTree] = extern 481 | 482 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_parser_set_logger(self : Ptr[TSParser], logger : Ptr[TSLogger]): Unit = extern 483 | 484 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_query_cursor_exec(_0 : Ptr[TSQueryCursor], _1 : Ptr[TSQuery], _2 : Ptr[TSNode]): Unit = extern 485 | 486 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_query_cursor_set_point_range(_0 : Ptr[TSQueryCursor], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint]): Unit = extern 487 | 488 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_tree_cursor_copy(_0 : Ptr[TSTreeCursor], __return : Ptr[TSTreeCursor]): Unit = extern 489 | 490 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_tree_cursor_current_node(_0 : Ptr[TSTreeCursor], __return : Ptr[TSNode]): Unit = extern 491 | 492 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_tree_cursor_goto_first_child_for_point(_0 : Ptr[TSTreeCursor], _1 : Ptr[TSPoint]): int64_t = extern 493 | 494 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_tree_cursor_new(_0 : Ptr[TSNode], __return : Ptr[TSTreeCursor]): Unit = extern 495 | 496 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_tree_cursor_reset(_0 : Ptr[TSTreeCursor], _1 : Ptr[TSNode]): Unit = extern 497 | 498 | private[tree_sitter] def __sn_wrap_tree_sitter_ts_tree_root_node(self : Ptr[TSTree], __return : Ptr[TSNode]): Unit = extern 499 | 500 | /** 501 | * Get the number of distinct field names in the language. 502 | */ 503 | def ts_language_field_count(_0 : Ptr[TSLanguage]): uint32_t = extern 504 | 505 | /** 506 | * Get the numerical id for the given field name string. 507 | */ 508 | def ts_language_field_id_for_name(_0 : Ptr[TSLanguage], _1 : CString, _2 : uint32_t): TSFieldId = extern 509 | 510 | /** 511 | * Get the field name string for the given numerical id. 512 | */ 513 | def ts_language_field_name_for_id(_0 : Ptr[TSLanguage], _1 : TSFieldId): CString = extern 514 | 515 | /** 516 | * Get the number of distinct node types in the language. 517 | */ 518 | def ts_language_symbol_count(_0 : Ptr[TSLanguage]): uint32_t = extern 519 | 520 | /** 521 | * Get the numerical id for the given node type string. 522 | */ 523 | def ts_language_symbol_for_name(self : Ptr[TSLanguage], string : CString, length : uint32_t, is_named : Boolean): TSSymbol = extern 524 | 525 | /** 526 | * Get a node type string for the given numerical id. 527 | */ 528 | def ts_language_symbol_name(_0 : Ptr[TSLanguage], _1 : TSSymbol): CString = extern 529 | 530 | /** 531 | * Check whether the given node type id belongs to named nodes, anonymous nodes, or a hidden nodes. 532 | */ 533 | def ts_language_symbol_type(_0 : Ptr[TSLanguage], _1 : TSSymbol): TSSymbolType = extern 534 | 535 | /** 536 | * Get the ABI version number for this language. This version number is used to ensure that languages were generated by a compatible version of Tree-sitter. 537 | */ 538 | def ts_language_version(_0 : Ptr[TSLanguage]): uint32_t = extern 539 | 540 | /** 541 | * Edit the node to keep it in-sync with source code that has been edited. 542 | */ 543 | def ts_node_edit(_0 : Ptr[TSNode], _1 : Ptr[TSInputEdit]): Unit = extern 544 | 545 | /** 546 | * Get the parser's current cancellation flag pointer. 547 | */ 548 | def ts_parser_cancellation_flag(self : Ptr[TSParser]): Ptr[size_t] = extern 549 | 550 | /** 551 | * Delete the parser, freeing all of the memory that it used. 552 | */ 553 | def ts_parser_delete(parser : Ptr[TSParser]): Unit = extern 554 | 555 | /** 556 | * Get the ranges of text that the parser will include when parsing. 557 | */ 558 | def ts_parser_included_ranges(self : Ptr[TSParser], length : Ptr[uint32_t]): Ptr[TSRange] = extern 559 | 560 | /** 561 | * Get the parser's current language. 562 | */ 563 | def ts_parser_language(self : Ptr[TSParser]): Ptr[TSLanguage] = extern 564 | 565 | /** 566 | * Create a new parser. 567 | */ 568 | def ts_parser_new(): Ptr[TSParser] = extern 569 | 570 | /** 571 | * Use the parser to parse some source code stored in one contiguous buffer. The first two parameters are the same as in the `ts_parser_parse` function above. The second two parameters indicate the location of the buffer and its length in bytes. 572 | */ 573 | def ts_parser_parse_string(self : Ptr[TSParser], old_tree : Ptr[TSTree], string : CString, length : uint32_t): Ptr[TSTree] = extern 574 | 575 | /** 576 | * Use the parser to parse some source code stored in one contiguous buffer with a given encoding. The first four parameters work the same as in the `ts_parser_parse_string` method above. The final parameter indicates whether the text is encoded as UTF8 or UTF16. 577 | */ 578 | def ts_parser_parse_string_encoding(self : Ptr[TSParser], old_tree : Ptr[TSTree], string : CString, length : uint32_t, encoding : TSInputEncoding): Ptr[TSTree] = extern 579 | 580 | /** 581 | * Set the file descriptor to which the parser should write debugging graphs during parsing. The graphs are formatted in the DOT language. You may want to pipe these graphs directly to a `dot(1)` process in order to generate SVG output. You can turn off this logging by passing a negative number. 582 | */ 583 | def ts_parser_print_dot_graphs(self : Ptr[TSParser], file : CInt): Unit = extern 584 | 585 | /** 586 | * Instruct the parser to start the next parse from the beginning. 587 | */ 588 | def ts_parser_reset(self : Ptr[TSParser]): Unit = extern 589 | 590 | /** 591 | * Set the parser's current cancellation flag pointer. 592 | */ 593 | def ts_parser_set_cancellation_flag(self : Ptr[TSParser], flag : Ptr[size_t]): Unit = extern 594 | 595 | /** 596 | * Set the ranges of text that the parser should include when parsing. 597 | */ 598 | def ts_parser_set_included_ranges(self : Ptr[TSParser], ranges : Ptr[TSRange], length : uint32_t): Boolean = extern 599 | 600 | /** 601 | * Set the language that the parser should use for parsing. 602 | */ 603 | def ts_parser_set_language(self : Ptr[TSParser], language : Ptr[TSLanguage]): Boolean = extern 604 | 605 | /** 606 | * Set the maximum duration in microseconds that parsing should be allowed to take before halting. 607 | */ 608 | def ts_parser_set_timeout_micros(self : Ptr[TSParser], timeout : uint64_t): Unit = extern 609 | 610 | /** 611 | * Get the duration in microseconds that parsing is allowed to take. 612 | */ 613 | def ts_parser_timeout_micros(self : Ptr[TSParser]): uint64_t = extern 614 | 615 | def ts_query_capture_count(_0 : Ptr[TSQuery]): uint32_t = extern 616 | 617 | /** 618 | * Get the name and length of one of the query's captures, or one of the query's string literals. Each capture and string is associated with a numeric id based on the order that it appeared in the query's source. 619 | */ 620 | def ts_query_capture_name_for_id(_0 : Ptr[TSQuery], id : uint32_t, length : Ptr[uint32_t]): CString = extern 621 | 622 | /** 623 | * Get the quantifier of the query's captures. Each capture is * associated with a numeric id based on the order that it appeared in the query's source. 624 | */ 625 | def ts_query_capture_quantifier_for_id(_0 : Ptr[TSQuery], pattern_id : uint32_t, capture_id : uint32_t): TSQuantifier = extern 626 | 627 | /** 628 | * Delete a query cursor, freeing all of the memory that it used. 629 | */ 630 | def ts_query_cursor_delete(_0 : Ptr[TSQueryCursor]): Unit = extern 631 | 632 | /** 633 | * Manage the maximum number of in-progress matches allowed by this query cursor. 634 | */ 635 | def ts_query_cursor_did_exceed_match_limit(_0 : Ptr[TSQueryCursor]): Boolean = extern 636 | 637 | def ts_query_cursor_match_limit(_0 : Ptr[TSQueryCursor]): uint32_t = extern 638 | 639 | /** 640 | * Create a new cursor for executing a given query. 641 | */ 642 | def ts_query_cursor_new(): Ptr[TSQueryCursor] = extern 643 | 644 | /** 645 | * Advance to the next capture of the currently running query. 646 | */ 647 | def ts_query_cursor_next_capture(_0 : Ptr[TSQueryCursor], `match` : Ptr[TSQueryMatch], capture_index : Ptr[uint32_t]): Boolean = extern 648 | 649 | /** 650 | * Advance to the next match of the currently running query. 651 | */ 652 | def ts_query_cursor_next_match(_0 : Ptr[TSQueryCursor], `match` : Ptr[TSQueryMatch]): Boolean = extern 653 | 654 | def ts_query_cursor_remove_match(_0 : Ptr[TSQueryCursor], id : uint32_t): Unit = extern 655 | 656 | /** 657 | * Set the range of bytes or (row, column) positions in which the query will be executed. 658 | */ 659 | def ts_query_cursor_set_byte_range(_0 : Ptr[TSQueryCursor], _1 : uint32_t, _2 : uint32_t): Unit = extern 660 | 661 | def ts_query_cursor_set_match_limit(_0 : Ptr[TSQueryCursor], _1 : uint32_t): Unit = extern 662 | 663 | /** 664 | * Delete a query, freeing all of the memory that it used. 665 | */ 666 | def ts_query_delete(_0 : Ptr[TSQuery]): Unit = extern 667 | 668 | /** 669 | * Disable a certain capture within a query. 670 | */ 671 | def ts_query_disable_capture(_0 : Ptr[TSQuery], _1 : CString, _2 : uint32_t): Unit = extern 672 | 673 | /** 674 | * Disable a certain pattern within a query. 675 | */ 676 | def ts_query_disable_pattern(_0 : Ptr[TSQuery], _1 : uint32_t): Unit = extern 677 | 678 | def ts_query_is_pattern_guaranteed_at_step(self : Ptr[TSQuery], byte_offset : uint32_t): Boolean = extern 679 | 680 | /** 681 | * Create a new query from a string containing one or more S-expression patterns. The query is associated with a particular language, and can only be run on syntax nodes parsed with that language. 682 | */ 683 | def ts_query_new(language : Ptr[TSLanguage], source : CString, source_len : uint32_t, error_offset : Ptr[uint32_t], error_type : Ptr[TSQueryError]): Ptr[TSQuery] = extern 684 | 685 | /** 686 | * Get the number of patterns, captures, or string literals in the query. 687 | */ 688 | def ts_query_pattern_count(_0 : Ptr[TSQuery]): uint32_t = extern 689 | 690 | /** 691 | * Get all of the predicates for the given pattern in the query. 692 | */ 693 | def ts_query_predicates_for_pattern(self : Ptr[TSQuery], pattern_index : uint32_t, length : Ptr[uint32_t]): Ptr[TSQueryPredicateStep] = extern 694 | 695 | /** 696 | * Get the byte offset where the given pattern starts in the query's source. 697 | */ 698 | def ts_query_start_byte_for_pattern(_0 : Ptr[TSQuery], _1 : uint32_t): uint32_t = extern 699 | 700 | def ts_query_string_count(_0 : Ptr[TSQuery]): uint32_t = extern 701 | 702 | def ts_query_string_value_for_id(_0 : Ptr[TSQuery], id : uint32_t, length : Ptr[uint32_t]): CString = extern 703 | 704 | /** 705 | * Set the allocation functions used by the library. 706 | */ 707 | def ts_set_allocator(new_malloc : CFuncPtr1[size_t, Ptr[Byte]], new_calloc : CFuncPtr2[size_t, size_t, Ptr[Byte]], new_realloc : CFuncPtr2[Ptr[Byte], size_t, Ptr[Byte]], new_free : CFuncPtr1[Ptr[Byte], Unit]): Unit = extern 708 | 709 | /** 710 | * Create a shallow copy of the syntax tree. This is very fast. 711 | */ 712 | def ts_tree_copy(self : Ptr[TSTree]): Ptr[TSTree] = extern 713 | 714 | /** 715 | * Get the field id of the tree cursor's current node. 716 | */ 717 | def ts_tree_cursor_current_field_id(_0 : Ptr[TSTreeCursor]): TSFieldId = extern 718 | 719 | /** 720 | * Get the field name of the tree cursor's current node. 721 | */ 722 | def ts_tree_cursor_current_field_name(_0 : Ptr[TSTreeCursor]): CString = extern 723 | 724 | /** 725 | * Delete a tree cursor, freeing all of the memory that it used. 726 | */ 727 | def ts_tree_cursor_delete(_0 : Ptr[TSTreeCursor]): Unit = extern 728 | 729 | /** 730 | * Move the cursor to the first child of its current node. 731 | */ 732 | def ts_tree_cursor_goto_first_child(_0 : Ptr[TSTreeCursor]): Boolean = extern 733 | 734 | /** 735 | * Move the cursor to the first child of its current node that extends beyond the given byte offset or point. 736 | */ 737 | def ts_tree_cursor_goto_first_child_for_byte(_0 : Ptr[TSTreeCursor], _1 : uint32_t): int64_t = extern 738 | 739 | /** 740 | * Move the cursor to the next sibling of its current node. 741 | */ 742 | def ts_tree_cursor_goto_next_sibling(_0 : Ptr[TSTreeCursor]): Boolean = extern 743 | 744 | /** 745 | * Move the cursor to the parent of its current node. 746 | */ 747 | def ts_tree_cursor_goto_parent(_0 : Ptr[TSTreeCursor]): Boolean = extern 748 | 749 | /** 750 | * Delete the syntax tree, freeing all of the memory that it used. 751 | */ 752 | def ts_tree_delete(self : Ptr[TSTree]): Unit = extern 753 | 754 | /** 755 | * Edit the syntax tree to keep it in sync with source code that has been edited. 756 | */ 757 | def ts_tree_edit(self : Ptr[TSTree], edit : Ptr[TSInputEdit]): Unit = extern 758 | 759 | /** 760 | * Compare an old edited syntax tree to a new syntax tree representing the same document, returning an array of ranges whose syntactic structure has changed. 761 | */ 762 | def ts_tree_get_changed_ranges(old_tree : Ptr[TSTree], new_tree : Ptr[TSTree], length : Ptr[uint32_t]): Ptr[TSRange] = extern 763 | 764 | /** 765 | * Get the language that was used to parse the syntax tree. 766 | */ 767 | def ts_tree_language(_0 : Ptr[TSTree]): Ptr[TSLanguage] = extern 768 | 769 | /** 770 | * Write a DOT graph describing the syntax tree to the given file. 771 | */ 772 | def ts_tree_print_dot_graph(_0 : Ptr[TSTree], _1 : Ptr[FILE]): Unit = extern 773 | 774 | 775 | object functions: 776 | import _root_.tree_sitter.enumerations.* 777 | import _root_.tree_sitter.predef.* 778 | import _root_.tree_sitter.aliases.* 779 | import _root_.tree_sitter.structs.* 780 | import extern_functions.* 781 | export extern_functions.* 782 | 783 | /** 784 | * Get the node's child at the given index, where zero represents the first child. 785 | */ 786 | def ts_node_child(_0 : TSNode, _1 : uint32_t)(using Zone): TSNode = 787 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 788 | !(__ptr_0 + 0) = _0 789 | __sn_wrap_tree_sitter_ts_node_child((__ptr_0 + 0), _1, (__ptr_0 + 1)) 790 | !(__ptr_0 + 1) 791 | 792 | /** 793 | * Get the node's child at the given index, where zero represents the first child. 794 | */ 795 | def ts_node_child(_0 : Ptr[TSNode], _1 : uint32_t)(__return : Ptr[TSNode]): Unit = 796 | __sn_wrap_tree_sitter_ts_node_child(_0, _1, __return) 797 | 798 | /** 799 | * Get the node's child at the given index, where zero represents the first child. 800 | */ 801 | def ts_node_child(_0 : Ptr[TSNode], _1 : uint32_t)(using Zone): TSNode = 802 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 803 | __sn_wrap_tree_sitter_ts_node_child(_0, _1, (__ptr_0 + 0)) 804 | !(__ptr_0 + 0) 805 | 806 | /** 807 | * Get the node's child with the given numerical field id. 808 | */ 809 | def ts_node_child_by_field_id(_0 : Ptr[TSNode], _1 : TSFieldId)(__return : Ptr[TSNode]): Unit = 810 | __sn_wrap_tree_sitter_ts_node_child_by_field_id(_0, _1, __return) 811 | 812 | /** 813 | * Get the node's child with the given numerical field id. 814 | */ 815 | def ts_node_child_by_field_id(_0 : TSNode, _1 : TSFieldId)(using Zone): TSNode = 816 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 817 | !(__ptr_0 + 0) = _0 818 | __sn_wrap_tree_sitter_ts_node_child_by_field_id((__ptr_0 + 0), _1, (__ptr_0 + 1)) 819 | !(__ptr_0 + 1) 820 | 821 | /** 822 | * Get the node's child with the given numerical field id. 823 | */ 824 | def ts_node_child_by_field_id(_0 : Ptr[TSNode], _1 : TSFieldId)(using Zone): TSNode = 825 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 826 | __sn_wrap_tree_sitter_ts_node_child_by_field_id(_0, _1, (__ptr_0 + 0)) 827 | !(__ptr_0 + 0) 828 | 829 | /** 830 | * Get the node's child with the given field name. 831 | */ 832 | def ts_node_child_by_field_name(self : Ptr[TSNode], field_name : CString, field_name_length : uint32_t)(__return : Ptr[TSNode]): Unit = 833 | __sn_wrap_tree_sitter_ts_node_child_by_field_name(self, field_name, field_name_length, __return) 834 | 835 | /** 836 | * Get the node's child with the given field name. 837 | */ 838 | def ts_node_child_by_field_name(self : TSNode, field_name : CString, field_name_length : uint32_t)(using Zone): TSNode = 839 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 840 | !(__ptr_0 + 0) = self 841 | __sn_wrap_tree_sitter_ts_node_child_by_field_name((__ptr_0 + 0), field_name, field_name_length, (__ptr_0 + 1)) 842 | !(__ptr_0 + 1) 843 | 844 | /** 845 | * Get the node's child with the given field name. 846 | */ 847 | def ts_node_child_by_field_name(self : Ptr[TSNode], field_name : CString, field_name_length : uint32_t)(using Zone): TSNode = 848 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 849 | __sn_wrap_tree_sitter_ts_node_child_by_field_name(self, field_name, field_name_length, (__ptr_0 + 0)) 850 | !(__ptr_0 + 0) 851 | 852 | /** 853 | * Get the node's number of children. 854 | */ 855 | def ts_node_child_count(_0 : TSNode)(using Zone): uint32_t = 856 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 857 | !(__ptr_0 + 0) = _0 858 | __sn_wrap_tree_sitter_ts_node_child_count((__ptr_0 + 0)) 859 | 860 | /** 861 | * Get the node's number of children. 862 | */ 863 | def ts_node_child_count(_0 : Ptr[TSNode]): uint32_t = 864 | __sn_wrap_tree_sitter_ts_node_child_count(_0) 865 | 866 | /** 867 | * Get the smallest node within this node that spans the given range of bytes or (row, column) positions. 868 | */ 869 | def ts_node_descendant_for_byte_range(_0 : Ptr[TSNode], _1 : uint32_t, _2 : uint32_t)(__return : Ptr[TSNode]): Unit = 870 | __sn_wrap_tree_sitter_ts_node_descendant_for_byte_range(_0, _1, _2, __return) 871 | 872 | /** 873 | * Get the smallest node within this node that spans the given range of bytes or (row, column) positions. 874 | */ 875 | def ts_node_descendant_for_byte_range(_0 : TSNode, _1 : uint32_t, _2 : uint32_t)(using Zone): TSNode = 876 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 877 | !(__ptr_0 + 0) = _0 878 | __sn_wrap_tree_sitter_ts_node_descendant_for_byte_range((__ptr_0 + 0), _1, _2, (__ptr_0 + 1)) 879 | !(__ptr_0 + 1) 880 | 881 | /** 882 | * Get the smallest node within this node that spans the given range of bytes or (row, column) positions. 883 | */ 884 | def ts_node_descendant_for_byte_range(_0 : Ptr[TSNode], _1 : uint32_t, _2 : uint32_t)(using Zone): TSNode = 885 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 886 | __sn_wrap_tree_sitter_ts_node_descendant_for_byte_range(_0, _1, _2, (__ptr_0 + 0)) 887 | !(__ptr_0 + 0) 888 | 889 | def ts_node_descendant_for_point_range(_0 : Ptr[TSNode], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint])(__return : Ptr[TSNode]): Unit = 890 | __sn_wrap_tree_sitter_ts_node_descendant_for_point_range(_0, _1, _2, __return) 891 | 892 | def ts_node_descendant_for_point_range(_0 : TSNode, _1 : TSPoint, _2 : TSPoint)(using Zone): TSNode = 893 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 894 | val __ptr_1: Ptr[TSPoint] = alloc[TSPoint](2) 895 | !(__ptr_0 + 0) = _0 896 | !(__ptr_1 + 0) = _1 897 | !(__ptr_1 + 1) = _2 898 | __sn_wrap_tree_sitter_ts_node_descendant_for_point_range((__ptr_0 + 0), (__ptr_1 + 0), (__ptr_1 + 1), (__ptr_0 + 1)) 899 | !(__ptr_0 + 1) 900 | 901 | def ts_node_descendant_for_point_range(_0 : Ptr[TSNode], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint])(using Zone): TSNode = 902 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 903 | __sn_wrap_tree_sitter_ts_node_descendant_for_point_range(_0, _1, _2, (__ptr_0 + 0)) 904 | !(__ptr_0 + 0) 905 | 906 | /** 907 | * Get the node's end byte. 908 | */ 909 | def ts_node_end_byte(_0 : Ptr[TSNode]): uint32_t = 910 | __sn_wrap_tree_sitter_ts_node_end_byte(_0) 911 | 912 | /** 913 | * Get the node's end byte. 914 | */ 915 | def ts_node_end_byte(_0 : TSNode)(using Zone): uint32_t = 916 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 917 | !(__ptr_0 + 0) = _0 918 | __sn_wrap_tree_sitter_ts_node_end_byte((__ptr_0 + 0)) 919 | 920 | /** 921 | * Get the node's end position in terms of rows and columns. 922 | */ 923 | def ts_node_end_point(_0 : Ptr[TSNode])(using Zone): TSPoint = 924 | val __ptr_0: Ptr[TSPoint] = alloc[TSPoint](1) 925 | __sn_wrap_tree_sitter_ts_node_end_point(_0, (__ptr_0 + 0)) 926 | !(__ptr_0 + 0) 927 | 928 | /** 929 | * Get the node's end position in terms of rows and columns. 930 | */ 931 | def ts_node_end_point(_0 : Ptr[TSNode])(__return : Ptr[TSPoint]): Unit = 932 | __sn_wrap_tree_sitter_ts_node_end_point(_0, __return) 933 | 934 | /** 935 | * Get the node's end position in terms of rows and columns. 936 | */ 937 | def ts_node_end_point(_0 : TSNode)(using Zone): TSPoint = 938 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 939 | val __ptr_1: Ptr[TSPoint] = alloc[TSPoint](1) 940 | !(__ptr_0 + 0) = _0 941 | __sn_wrap_tree_sitter_ts_node_end_point((__ptr_0 + 0), (__ptr_1 + 0)) 942 | !(__ptr_1 + 0) 943 | 944 | /** 945 | * Check if two nodes are identical. 946 | */ 947 | def ts_node_eq(_0 : Ptr[TSNode], _1 : Ptr[TSNode]): Boolean = 948 | __sn_wrap_tree_sitter_ts_node_eq(_0, _1) 949 | 950 | /** 951 | * Check if two nodes are identical. 952 | */ 953 | def ts_node_eq(_0 : TSNode, _1 : TSNode)(using Zone): Boolean = 954 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 955 | !(__ptr_0 + 0) = _0 956 | !(__ptr_0 + 1) = _1 957 | __sn_wrap_tree_sitter_ts_node_eq((__ptr_0 + 0), (__ptr_0 + 1)) 958 | 959 | /** 960 | * Get the field name for node's child at the given index, where zero represents the first child. Returns NULL, if no field is found. 961 | */ 962 | def ts_node_field_name_for_child(_0 : TSNode, _1 : uint32_t)(using Zone): CString = 963 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 964 | !(__ptr_0 + 0) = _0 965 | __sn_wrap_tree_sitter_ts_node_field_name_for_child((__ptr_0 + 0), _1) 966 | 967 | /** 968 | * Get the field name for node's child at the given index, where zero represents the first child. Returns NULL, if no field is found. 969 | */ 970 | def ts_node_field_name_for_child(_0 : Ptr[TSNode], _1 : uint32_t): CString = 971 | __sn_wrap_tree_sitter_ts_node_field_name_for_child(_0, _1) 972 | 973 | /** 974 | * Get the node's first child that extends beyond the given byte offset. 975 | */ 976 | def ts_node_first_child_for_byte(_0 : Ptr[TSNode], _1 : uint32_t)(using Zone): TSNode = 977 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 978 | __sn_wrap_tree_sitter_ts_node_first_child_for_byte(_0, _1, (__ptr_0 + 0)) 979 | !(__ptr_0 + 0) 980 | 981 | /** 982 | * Get the node's first child that extends beyond the given byte offset. 983 | */ 984 | def ts_node_first_child_for_byte(_0 : TSNode, _1 : uint32_t)(using Zone): TSNode = 985 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 986 | !(__ptr_0 + 0) = _0 987 | __sn_wrap_tree_sitter_ts_node_first_child_for_byte((__ptr_0 + 0), _1, (__ptr_0 + 1)) 988 | !(__ptr_0 + 1) 989 | 990 | /** 991 | * Get the node's first child that extends beyond the given byte offset. 992 | */ 993 | def ts_node_first_child_for_byte(_0 : Ptr[TSNode], _1 : uint32_t)(__return : Ptr[TSNode]): Unit = 994 | __sn_wrap_tree_sitter_ts_node_first_child_for_byte(_0, _1, __return) 995 | 996 | /** 997 | * Get the node's first named child that extends beyond the given byte offset. 998 | */ 999 | def ts_node_first_named_child_for_byte(_0 : TSNode, _1 : uint32_t)(using Zone): TSNode = 1000 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1001 | !(__ptr_0 + 0) = _0 1002 | __sn_wrap_tree_sitter_ts_node_first_named_child_for_byte((__ptr_0 + 0), _1, (__ptr_0 + 1)) 1003 | !(__ptr_0 + 1) 1004 | 1005 | /** 1006 | * Get the node's first named child that extends beyond the given byte offset. 1007 | */ 1008 | def ts_node_first_named_child_for_byte(_0 : Ptr[TSNode], _1 : uint32_t)(using Zone): TSNode = 1009 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1010 | __sn_wrap_tree_sitter_ts_node_first_named_child_for_byte(_0, _1, (__ptr_0 + 0)) 1011 | !(__ptr_0 + 0) 1012 | 1013 | /** 1014 | * Get the node's first named child that extends beyond the given byte offset. 1015 | */ 1016 | def ts_node_first_named_child_for_byte(_0 : Ptr[TSNode], _1 : uint32_t)(__return : Ptr[TSNode]): Unit = 1017 | __sn_wrap_tree_sitter_ts_node_first_named_child_for_byte(_0, _1, __return) 1018 | 1019 | /** 1020 | * Check if a syntax node has been edited. 1021 | */ 1022 | def ts_node_has_changes(_0 : Ptr[TSNode]): Boolean = 1023 | __sn_wrap_tree_sitter_ts_node_has_changes(_0) 1024 | 1025 | /** 1026 | * Check if a syntax node has been edited. 1027 | */ 1028 | def ts_node_has_changes(_0 : TSNode)(using Zone): Boolean = 1029 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1030 | !(__ptr_0 + 0) = _0 1031 | __sn_wrap_tree_sitter_ts_node_has_changes((__ptr_0 + 0)) 1032 | 1033 | /** 1034 | * Check if the node is a syntax error or contains any syntax errors. 1035 | */ 1036 | def ts_node_has_error(_0 : TSNode)(using Zone): Boolean = 1037 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1038 | !(__ptr_0 + 0) = _0 1039 | __sn_wrap_tree_sitter_ts_node_has_error((__ptr_0 + 0)) 1040 | 1041 | /** 1042 | * Check if the node is a syntax error or contains any syntax errors. 1043 | */ 1044 | def ts_node_has_error(_0 : Ptr[TSNode]): Boolean = 1045 | __sn_wrap_tree_sitter_ts_node_has_error(_0) 1046 | 1047 | /** 1048 | * Check if the node is *extra*. Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere. 1049 | */ 1050 | def ts_node_is_extra(_0 : Ptr[TSNode]): Boolean = 1051 | __sn_wrap_tree_sitter_ts_node_is_extra(_0) 1052 | 1053 | /** 1054 | * Check if the node is *extra*. Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere. 1055 | */ 1056 | def ts_node_is_extra(_0 : TSNode)(using Zone): Boolean = 1057 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1058 | !(__ptr_0 + 0) = _0 1059 | __sn_wrap_tree_sitter_ts_node_is_extra((__ptr_0 + 0)) 1060 | 1061 | /** 1062 | * Check if the node is *missing*. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors. 1063 | */ 1064 | def ts_node_is_missing(_0 : Ptr[TSNode]): Boolean = 1065 | __sn_wrap_tree_sitter_ts_node_is_missing(_0) 1066 | 1067 | /** 1068 | * Check if the node is *missing*. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors. 1069 | */ 1070 | def ts_node_is_missing(_0 : TSNode)(using Zone): Boolean = 1071 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1072 | !(__ptr_0 + 0) = _0 1073 | __sn_wrap_tree_sitter_ts_node_is_missing((__ptr_0 + 0)) 1074 | 1075 | /** 1076 | * Check if the node is *named*. Named nodes correspond to named rules in the grammar, whereas *anonymous* nodes correspond to string literals in the grammar. 1077 | */ 1078 | def ts_node_is_named(_0 : TSNode)(using Zone): Boolean = 1079 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1080 | !(__ptr_0 + 0) = _0 1081 | __sn_wrap_tree_sitter_ts_node_is_named((__ptr_0 + 0)) 1082 | 1083 | /** 1084 | * Check if the node is *named*. Named nodes correspond to named rules in the grammar, whereas *anonymous* nodes correspond to string literals in the grammar. 1085 | */ 1086 | def ts_node_is_named(_0 : Ptr[TSNode]): Boolean = 1087 | __sn_wrap_tree_sitter_ts_node_is_named(_0) 1088 | 1089 | /** 1090 | * Check if the node is null. Functions like `ts_node_child` and `ts_node_next_sibling` will return a null node to indicate that no such node was found. 1091 | */ 1092 | def ts_node_is_null(_0 : TSNode)(using Zone): Boolean = 1093 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1094 | !(__ptr_0 + 0) = _0 1095 | __sn_wrap_tree_sitter_ts_node_is_null((__ptr_0 + 0)) 1096 | 1097 | /** 1098 | * Check if the node is null. Functions like `ts_node_child` and `ts_node_next_sibling` will return a null node to indicate that no such node was found. 1099 | */ 1100 | def ts_node_is_null(_0 : Ptr[TSNode]): Boolean = 1101 | __sn_wrap_tree_sitter_ts_node_is_null(_0) 1102 | 1103 | /** 1104 | * Get the node's *named* child at the given index. 1105 | */ 1106 | def ts_node_named_child(_0 : TSNode, _1 : uint32_t)(using Zone): TSNode = 1107 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1108 | !(__ptr_0 + 0) = _0 1109 | __sn_wrap_tree_sitter_ts_node_named_child((__ptr_0 + 0), _1, (__ptr_0 + 1)) 1110 | !(__ptr_0 + 1) 1111 | 1112 | /** 1113 | * Get the node's *named* child at the given index. 1114 | */ 1115 | def ts_node_named_child(_0 : Ptr[TSNode], _1 : uint32_t)(using Zone): TSNode = 1116 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1117 | __sn_wrap_tree_sitter_ts_node_named_child(_0, _1, (__ptr_0 + 0)) 1118 | !(__ptr_0 + 0) 1119 | 1120 | /** 1121 | * Get the node's *named* child at the given index. 1122 | */ 1123 | def ts_node_named_child(_0 : Ptr[TSNode], _1 : uint32_t)(__return : Ptr[TSNode]): Unit = 1124 | __sn_wrap_tree_sitter_ts_node_named_child(_0, _1, __return) 1125 | 1126 | /** 1127 | * Get the node's number of *named* children. 1128 | */ 1129 | def ts_node_named_child_count(_0 : Ptr[TSNode]): uint32_t = 1130 | __sn_wrap_tree_sitter_ts_node_named_child_count(_0) 1131 | 1132 | /** 1133 | * Get the node's number of *named* children. 1134 | */ 1135 | def ts_node_named_child_count(_0 : TSNode)(using Zone): uint32_t = 1136 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1137 | !(__ptr_0 + 0) = _0 1138 | __sn_wrap_tree_sitter_ts_node_named_child_count((__ptr_0 + 0)) 1139 | 1140 | /** 1141 | * Get the smallest named node within this node that spans the given range of bytes or (row, column) positions. 1142 | */ 1143 | def ts_node_named_descendant_for_byte_range(_0 : TSNode, _1 : uint32_t, _2 : uint32_t)(using Zone): TSNode = 1144 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1145 | !(__ptr_0 + 0) = _0 1146 | __sn_wrap_tree_sitter_ts_node_named_descendant_for_byte_range((__ptr_0 + 0), _1, _2, (__ptr_0 + 1)) 1147 | !(__ptr_0 + 1) 1148 | 1149 | /** 1150 | * Get the smallest named node within this node that spans the given range of bytes or (row, column) positions. 1151 | */ 1152 | def ts_node_named_descendant_for_byte_range(_0 : Ptr[TSNode], _1 : uint32_t, _2 : uint32_t)(using Zone): TSNode = 1153 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1154 | __sn_wrap_tree_sitter_ts_node_named_descendant_for_byte_range(_0, _1, _2, (__ptr_0 + 0)) 1155 | !(__ptr_0 + 0) 1156 | 1157 | /** 1158 | * Get the smallest named node within this node that spans the given range of bytes or (row, column) positions. 1159 | */ 1160 | def ts_node_named_descendant_for_byte_range(_0 : Ptr[TSNode], _1 : uint32_t, _2 : uint32_t)(__return : Ptr[TSNode]): Unit = 1161 | __sn_wrap_tree_sitter_ts_node_named_descendant_for_byte_range(_0, _1, _2, __return) 1162 | 1163 | def ts_node_named_descendant_for_point_range(_0 : TSNode, _1 : TSPoint, _2 : TSPoint)(using Zone): TSNode = 1164 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1165 | val __ptr_1: Ptr[TSPoint] = alloc[TSPoint](2) 1166 | !(__ptr_0 + 0) = _0 1167 | !(__ptr_1 + 0) = _1 1168 | !(__ptr_1 + 1) = _2 1169 | __sn_wrap_tree_sitter_ts_node_named_descendant_for_point_range((__ptr_0 + 0), (__ptr_1 + 0), (__ptr_1 + 1), (__ptr_0 + 1)) 1170 | !(__ptr_0 + 1) 1171 | 1172 | def ts_node_named_descendant_for_point_range(_0 : Ptr[TSNode], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint])(using Zone): TSNode = 1173 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1174 | __sn_wrap_tree_sitter_ts_node_named_descendant_for_point_range(_0, _1, _2, (__ptr_0 + 0)) 1175 | !(__ptr_0 + 0) 1176 | 1177 | def ts_node_named_descendant_for_point_range(_0 : Ptr[TSNode], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint])(__return : Ptr[TSNode]): Unit = 1178 | __sn_wrap_tree_sitter_ts_node_named_descendant_for_point_range(_0, _1, _2, __return) 1179 | 1180 | /** 1181 | * Get the node's next / previous *named* sibling. 1182 | */ 1183 | def ts_node_next_named_sibling(_0 : Ptr[TSNode])(__return : Ptr[TSNode]): Unit = 1184 | __sn_wrap_tree_sitter_ts_node_next_named_sibling(_0, __return) 1185 | 1186 | /** 1187 | * Get the node's next / previous *named* sibling. 1188 | */ 1189 | def ts_node_next_named_sibling(_0 : TSNode)(using Zone): TSNode = 1190 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1191 | !(__ptr_0 + 0) = _0 1192 | __sn_wrap_tree_sitter_ts_node_next_named_sibling((__ptr_0 + 0), (__ptr_0 + 1)) 1193 | !(__ptr_0 + 1) 1194 | 1195 | /** 1196 | * Get the node's next / previous *named* sibling. 1197 | */ 1198 | def ts_node_next_named_sibling(_0 : Ptr[TSNode])(using Zone): TSNode = 1199 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1200 | __sn_wrap_tree_sitter_ts_node_next_named_sibling(_0, (__ptr_0 + 0)) 1201 | !(__ptr_0 + 0) 1202 | 1203 | /** 1204 | * Get the node's next / previous sibling. 1205 | */ 1206 | def ts_node_next_sibling(_0 : Ptr[TSNode])(using Zone): TSNode = 1207 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1208 | __sn_wrap_tree_sitter_ts_node_next_sibling(_0, (__ptr_0 + 0)) 1209 | !(__ptr_0 + 0) 1210 | 1211 | /** 1212 | * Get the node's next / previous sibling. 1213 | */ 1214 | def ts_node_next_sibling(_0 : TSNode)(using Zone): TSNode = 1215 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1216 | !(__ptr_0 + 0) = _0 1217 | __sn_wrap_tree_sitter_ts_node_next_sibling((__ptr_0 + 0), (__ptr_0 + 1)) 1218 | !(__ptr_0 + 1) 1219 | 1220 | /** 1221 | * Get the node's next / previous sibling. 1222 | */ 1223 | def ts_node_next_sibling(_0 : Ptr[TSNode])(__return : Ptr[TSNode]): Unit = 1224 | __sn_wrap_tree_sitter_ts_node_next_sibling(_0, __return) 1225 | 1226 | /** 1227 | * Get the node's immediate parent. 1228 | */ 1229 | def ts_node_parent(_0 : Ptr[TSNode])(__return : Ptr[TSNode]): Unit = 1230 | __sn_wrap_tree_sitter_ts_node_parent(_0, __return) 1231 | 1232 | /** 1233 | * Get the node's immediate parent. 1234 | */ 1235 | def ts_node_parent(_0 : Ptr[TSNode])(using Zone): TSNode = 1236 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1237 | __sn_wrap_tree_sitter_ts_node_parent(_0, (__ptr_0 + 0)) 1238 | !(__ptr_0 + 0) 1239 | 1240 | /** 1241 | * Get the node's immediate parent. 1242 | */ 1243 | def ts_node_parent(_0 : TSNode)(using Zone): TSNode = 1244 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1245 | !(__ptr_0 + 0) = _0 1246 | __sn_wrap_tree_sitter_ts_node_parent((__ptr_0 + 0), (__ptr_0 + 1)) 1247 | !(__ptr_0 + 1) 1248 | 1249 | def ts_node_prev_named_sibling(_0 : Ptr[TSNode])(using Zone): TSNode = 1250 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1251 | __sn_wrap_tree_sitter_ts_node_prev_named_sibling(_0, (__ptr_0 + 0)) 1252 | !(__ptr_0 + 0) 1253 | 1254 | def ts_node_prev_named_sibling(_0 : Ptr[TSNode])(__return : Ptr[TSNode]): Unit = 1255 | __sn_wrap_tree_sitter_ts_node_prev_named_sibling(_0, __return) 1256 | 1257 | def ts_node_prev_named_sibling(_0 : TSNode)(using Zone): TSNode = 1258 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1259 | !(__ptr_0 + 0) = _0 1260 | __sn_wrap_tree_sitter_ts_node_prev_named_sibling((__ptr_0 + 0), (__ptr_0 + 1)) 1261 | !(__ptr_0 + 1) 1262 | 1263 | def ts_node_prev_sibling(_0 : TSNode)(using Zone): TSNode = 1264 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](2) 1265 | !(__ptr_0 + 0) = _0 1266 | __sn_wrap_tree_sitter_ts_node_prev_sibling((__ptr_0 + 0), (__ptr_0 + 1)) 1267 | !(__ptr_0 + 1) 1268 | 1269 | def ts_node_prev_sibling(_0 : Ptr[TSNode])(using Zone): TSNode = 1270 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1271 | __sn_wrap_tree_sitter_ts_node_prev_sibling(_0, (__ptr_0 + 0)) 1272 | !(__ptr_0 + 0) 1273 | 1274 | def ts_node_prev_sibling(_0 : Ptr[TSNode])(__return : Ptr[TSNode]): Unit = 1275 | __sn_wrap_tree_sitter_ts_node_prev_sibling(_0, __return) 1276 | 1277 | /** 1278 | * Get the node's start byte. 1279 | */ 1280 | def ts_node_start_byte(_0 : Ptr[TSNode]): uint32_t = 1281 | __sn_wrap_tree_sitter_ts_node_start_byte(_0) 1282 | 1283 | /** 1284 | * Get the node's start byte. 1285 | */ 1286 | def ts_node_start_byte(_0 : TSNode)(using Zone): uint32_t = 1287 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1288 | !(__ptr_0 + 0) = _0 1289 | __sn_wrap_tree_sitter_ts_node_start_byte((__ptr_0 + 0)) 1290 | 1291 | /** 1292 | * Get the node's start position in terms of rows and columns. 1293 | */ 1294 | def ts_node_start_point(_0 : TSNode)(using Zone): TSPoint = 1295 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1296 | val __ptr_1: Ptr[TSPoint] = alloc[TSPoint](1) 1297 | !(__ptr_0 + 0) = _0 1298 | __sn_wrap_tree_sitter_ts_node_start_point((__ptr_0 + 0), (__ptr_1 + 0)) 1299 | !(__ptr_1 + 0) 1300 | 1301 | /** 1302 | * Get the node's start position in terms of rows and columns. 1303 | */ 1304 | def ts_node_start_point(_0 : Ptr[TSNode])(__return : Ptr[TSPoint]): Unit = 1305 | __sn_wrap_tree_sitter_ts_node_start_point(_0, __return) 1306 | 1307 | /** 1308 | * Get the node's start position in terms of rows and columns. 1309 | */ 1310 | def ts_node_start_point(_0 : Ptr[TSNode])(using Zone): TSPoint = 1311 | val __ptr_0: Ptr[TSPoint] = alloc[TSPoint](1) 1312 | __sn_wrap_tree_sitter_ts_node_start_point(_0, (__ptr_0 + 0)) 1313 | !(__ptr_0 + 0) 1314 | 1315 | /** 1316 | * Get an S-expression representing the node as a string. 1317 | */ 1318 | def ts_node_string(_0 : Ptr[TSNode]): CString = 1319 | __sn_wrap_tree_sitter_ts_node_string(_0) 1320 | 1321 | /** 1322 | * Get an S-expression representing the node as a string. 1323 | */ 1324 | def ts_node_string(_0 : TSNode)(using Zone): CString = 1325 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1326 | !(__ptr_0 + 0) = _0 1327 | __sn_wrap_tree_sitter_ts_node_string((__ptr_0 + 0)) 1328 | 1329 | /** 1330 | * Get the node's type as a numerical id. 1331 | */ 1332 | def ts_node_symbol(_0 : Ptr[TSNode]): TSSymbol = 1333 | __sn_wrap_tree_sitter_ts_node_symbol(_0) 1334 | 1335 | /** 1336 | * Get the node's type as a numerical id. 1337 | */ 1338 | def ts_node_symbol(_0 : TSNode)(using Zone): TSSymbol = 1339 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1340 | !(__ptr_0 + 0) = _0 1341 | __sn_wrap_tree_sitter_ts_node_symbol((__ptr_0 + 0)) 1342 | 1343 | /** 1344 | * Get the node's type as a null-terminated string. 1345 | */ 1346 | def ts_node_type(_0 : Ptr[TSNode]): CString = 1347 | __sn_wrap_tree_sitter_ts_node_type(_0) 1348 | 1349 | /** 1350 | * Get the node's type as a null-terminated string. 1351 | */ 1352 | def ts_node_type(_0 : TSNode)(using Zone): CString = 1353 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1354 | !(__ptr_0 + 0) = _0 1355 | __sn_wrap_tree_sitter_ts_node_type((__ptr_0 + 0)) 1356 | 1357 | /** 1358 | * Get the parser's current logger. 1359 | */ 1360 | def ts_parser_logger(self : Ptr[TSParser])(__return : Ptr[TSLogger]): Unit = 1361 | __sn_wrap_tree_sitter_ts_parser_logger(self, __return) 1362 | 1363 | /** 1364 | * Get the parser's current logger. 1365 | */ 1366 | def ts_parser_logger(self : Ptr[TSParser])(using Zone): TSLogger = 1367 | val __ptr_0: Ptr[TSLogger] = alloc[TSLogger](1) 1368 | __sn_wrap_tree_sitter_ts_parser_logger(self, (__ptr_0 + 0)) 1369 | !(__ptr_0 + 0) 1370 | 1371 | /** 1372 | * Use the parser to parse some source code and create a syntax tree. 1373 | */ 1374 | def ts_parser_parse(self : Ptr[TSParser], old_tree : Ptr[TSTree], input : Ptr[TSInput]): Ptr[TSTree] = 1375 | __sn_wrap_tree_sitter_ts_parser_parse(self, old_tree, input) 1376 | 1377 | /** 1378 | * Use the parser to parse some source code and create a syntax tree. 1379 | */ 1380 | def ts_parser_parse(self : Ptr[TSParser], old_tree : Ptr[TSTree], input : TSInput)(using Zone): Ptr[TSTree] = 1381 | val __ptr_0: Ptr[TSInput] = alloc[TSInput](1) 1382 | !(__ptr_0 + 0) = input 1383 | __sn_wrap_tree_sitter_ts_parser_parse(self, old_tree, (__ptr_0 + 0)) 1384 | 1385 | /** 1386 | * Set the logger that a parser should use during parsing. 1387 | */ 1388 | def ts_parser_set_logger(self : Ptr[TSParser], logger : TSLogger)(using Zone): Unit = 1389 | val __ptr_0: Ptr[TSLogger] = alloc[TSLogger](1) 1390 | !(__ptr_0 + 0) = logger 1391 | __sn_wrap_tree_sitter_ts_parser_set_logger(self, (__ptr_0 + 0)) 1392 | 1393 | /** 1394 | * Set the logger that a parser should use during parsing. 1395 | */ 1396 | def ts_parser_set_logger(self : Ptr[TSParser], logger : Ptr[TSLogger]): Unit = 1397 | __sn_wrap_tree_sitter_ts_parser_set_logger(self, logger) 1398 | 1399 | /** 1400 | * Start running a given query on a given node. 1401 | */ 1402 | def ts_query_cursor_exec(_0 : Ptr[TSQueryCursor], _1 : Ptr[TSQuery], _2 : Ptr[TSNode]): Unit = 1403 | __sn_wrap_tree_sitter_ts_query_cursor_exec(_0, _1, _2) 1404 | 1405 | /** 1406 | * Start running a given query on a given node. 1407 | */ 1408 | def ts_query_cursor_exec(_0 : Ptr[TSQueryCursor], _1 : Ptr[TSQuery], _2 : TSNode)(using Zone): Unit = 1409 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1410 | !(__ptr_0 + 0) = _2 1411 | __sn_wrap_tree_sitter_ts_query_cursor_exec(_0, _1, (__ptr_0 + 0)) 1412 | 1413 | def ts_query_cursor_set_point_range(_0 : Ptr[TSQueryCursor], _1 : Ptr[TSPoint], _2 : Ptr[TSPoint]): Unit = 1414 | __sn_wrap_tree_sitter_ts_query_cursor_set_point_range(_0, _1, _2) 1415 | 1416 | def ts_query_cursor_set_point_range(_0 : Ptr[TSQueryCursor], _1 : TSPoint, _2 : TSPoint)(using Zone): Unit = 1417 | val __ptr_0: Ptr[TSPoint] = alloc[TSPoint](2) 1418 | !(__ptr_0 + 0) = _1 1419 | !(__ptr_0 + 1) = _2 1420 | __sn_wrap_tree_sitter_ts_query_cursor_set_point_range(_0, (__ptr_0 + 0), (__ptr_0 + 1)) 1421 | 1422 | def ts_tree_cursor_copy(_0 : Ptr[TSTreeCursor])(using Zone): TSTreeCursor = 1423 | val __ptr_0: Ptr[TSTreeCursor] = alloc[TSTreeCursor](1) 1424 | __sn_wrap_tree_sitter_ts_tree_cursor_copy(_0, (__ptr_0 + 0)) 1425 | !(__ptr_0 + 0) 1426 | 1427 | def ts_tree_cursor_copy(_0 : Ptr[TSTreeCursor])(__return : Ptr[TSTreeCursor]): Unit = 1428 | __sn_wrap_tree_sitter_ts_tree_cursor_copy(_0, __return) 1429 | 1430 | /** 1431 | * Get the tree cursor's current node. 1432 | */ 1433 | def ts_tree_cursor_current_node(_0 : Ptr[TSTreeCursor])(__return : Ptr[TSNode]): Unit = 1434 | __sn_wrap_tree_sitter_ts_tree_cursor_current_node(_0, __return) 1435 | 1436 | /** 1437 | * Get the tree cursor's current node. 1438 | */ 1439 | def ts_tree_cursor_current_node(_0 : Ptr[TSTreeCursor])(using Zone): TSNode = 1440 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1441 | __sn_wrap_tree_sitter_ts_tree_cursor_current_node(_0, (__ptr_0 + 0)) 1442 | !(__ptr_0 + 0) 1443 | 1444 | def ts_tree_cursor_goto_first_child_for_point(_0 : Ptr[TSTreeCursor], _1 : Ptr[TSPoint]): int64_t = 1445 | __sn_wrap_tree_sitter_ts_tree_cursor_goto_first_child_for_point(_0, _1) 1446 | 1447 | def ts_tree_cursor_goto_first_child_for_point(_0 : Ptr[TSTreeCursor], _1 : TSPoint)(using Zone): int64_t = 1448 | val __ptr_0: Ptr[TSPoint] = alloc[TSPoint](1) 1449 | !(__ptr_0 + 0) = _1 1450 | __sn_wrap_tree_sitter_ts_tree_cursor_goto_first_child_for_point(_0, (__ptr_0 + 0)) 1451 | 1452 | /** 1453 | * Create a new tree cursor starting from the given node. 1454 | */ 1455 | def ts_tree_cursor_new(_0 : TSNode)(using Zone): TSTreeCursor = 1456 | val __ptr_0: Ptr[TSTreeCursor] = alloc[TSTreeCursor](1) 1457 | val __ptr_1: Ptr[TSNode] = alloc[TSNode](1) 1458 | !(__ptr_1 + 0) = _0 1459 | __sn_wrap_tree_sitter_ts_tree_cursor_new((__ptr_1 + 0), (__ptr_0 + 0)) 1460 | !(__ptr_0 + 0) 1461 | 1462 | /** 1463 | * Create a new tree cursor starting from the given node. 1464 | */ 1465 | def ts_tree_cursor_new(_0 : Ptr[TSNode])(using Zone): TSTreeCursor = 1466 | val __ptr_0: Ptr[TSTreeCursor] = alloc[TSTreeCursor](1) 1467 | __sn_wrap_tree_sitter_ts_tree_cursor_new(_0, (__ptr_0 + 0)) 1468 | !(__ptr_0 + 0) 1469 | 1470 | /** 1471 | * Create a new tree cursor starting from the given node. 1472 | */ 1473 | def ts_tree_cursor_new(_0 : Ptr[TSNode])(__return : Ptr[TSTreeCursor]): Unit = 1474 | __sn_wrap_tree_sitter_ts_tree_cursor_new(_0, __return) 1475 | 1476 | /** 1477 | * Re-initialize a tree cursor to start at a different node. 1478 | */ 1479 | def ts_tree_cursor_reset(_0 : Ptr[TSTreeCursor], _1 : TSNode)(using Zone): Unit = 1480 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1481 | !(__ptr_0 + 0) = _1 1482 | __sn_wrap_tree_sitter_ts_tree_cursor_reset(_0, (__ptr_0 + 0)) 1483 | 1484 | /** 1485 | * Re-initialize a tree cursor to start at a different node. 1486 | */ 1487 | def ts_tree_cursor_reset(_0 : Ptr[TSTreeCursor], _1 : Ptr[TSNode]): Unit = 1488 | __sn_wrap_tree_sitter_ts_tree_cursor_reset(_0, _1) 1489 | 1490 | /** 1491 | * Get the root node of the syntax tree. 1492 | */ 1493 | def ts_tree_root_node(self : Ptr[TSTree])(using Zone): TSNode = 1494 | val __ptr_0: Ptr[TSNode] = alloc[TSNode](1) 1495 | __sn_wrap_tree_sitter_ts_tree_root_node(self, (__ptr_0 + 0)) 1496 | !(__ptr_0 + 0) 1497 | 1498 | /** 1499 | * Get the root node of the syntax tree. 1500 | */ 1501 | def ts_tree_root_node(self : Ptr[TSTree])(__return : Ptr[TSNode]): Unit = 1502 | __sn_wrap_tree_sitter_ts_tree_root_node(self, __return) 1503 | 1504 | object types: 1505 | export _root_.tree_sitter.structs.* 1506 | export _root_.tree_sitter.aliases.* 1507 | export _root_.tree_sitter.enumerations.* 1508 | 1509 | object all: 1510 | export _root_.tree_sitter.enumerations.TSInputEncoding 1511 | export _root_.tree_sitter.enumerations.TSLogType 1512 | export _root_.tree_sitter.enumerations.TSQuantifier 1513 | export _root_.tree_sitter.enumerations.TSQueryError 1514 | export _root_.tree_sitter.enumerations.TSQueryPredicateStepType 1515 | export _root_.tree_sitter.enumerations.TSSymbolType 1516 | export _root_.tree_sitter.aliases.FILE 1517 | export _root_.tree_sitter.aliases.TSFieldId 1518 | export _root_.tree_sitter.aliases.TSSymbol 1519 | export _root_.tree_sitter.aliases.int64_t 1520 | export _root_.tree_sitter.aliases.size_t 1521 | export _root_.tree_sitter.aliases.uint16_t 1522 | export _root_.tree_sitter.aliases.uint32_t 1523 | export _root_.tree_sitter.aliases.uint64_t 1524 | export _root_.tree_sitter.structs.TSInput 1525 | export _root_.tree_sitter.structs.TSInputEdit 1526 | export _root_.tree_sitter.structs.TSLanguage 1527 | export _root_.tree_sitter.structs.TSLogger 1528 | export _root_.tree_sitter.structs.TSNode 1529 | export _root_.tree_sitter.structs.TSParser 1530 | export _root_.tree_sitter.structs.TSPoint 1531 | export _root_.tree_sitter.structs.TSQuery 1532 | export _root_.tree_sitter.structs.TSQueryCapture 1533 | export _root_.tree_sitter.structs.TSQueryCursor 1534 | export _root_.tree_sitter.structs.TSQueryMatch 1535 | export _root_.tree_sitter.structs.TSQueryPredicateStep 1536 | export _root_.tree_sitter.structs.TSRange 1537 | export _root_.tree_sitter.structs.TSTree 1538 | export _root_.tree_sitter.structs.TSTreeCursor 1539 | export _root_.tree_sitter.functions.ts_language_field_count 1540 | export _root_.tree_sitter.functions.ts_language_field_id_for_name 1541 | export _root_.tree_sitter.functions.ts_language_field_name_for_id 1542 | export _root_.tree_sitter.functions.ts_language_symbol_count 1543 | export _root_.tree_sitter.functions.ts_language_symbol_for_name 1544 | export _root_.tree_sitter.functions.ts_language_symbol_name 1545 | export _root_.tree_sitter.functions.ts_language_symbol_type 1546 | export _root_.tree_sitter.functions.ts_language_version 1547 | export _root_.tree_sitter.functions.ts_node_edit 1548 | export _root_.tree_sitter.functions.ts_parser_cancellation_flag 1549 | export _root_.tree_sitter.functions.ts_parser_delete 1550 | export _root_.tree_sitter.functions.ts_parser_included_ranges 1551 | export _root_.tree_sitter.functions.ts_parser_language 1552 | export _root_.tree_sitter.functions.ts_parser_new 1553 | export _root_.tree_sitter.functions.ts_parser_parse_string 1554 | export _root_.tree_sitter.functions.ts_parser_parse_string_encoding 1555 | export _root_.tree_sitter.functions.ts_parser_print_dot_graphs 1556 | export _root_.tree_sitter.functions.ts_parser_reset 1557 | export _root_.tree_sitter.functions.ts_parser_set_cancellation_flag 1558 | export _root_.tree_sitter.functions.ts_parser_set_included_ranges 1559 | export _root_.tree_sitter.functions.ts_parser_set_language 1560 | export _root_.tree_sitter.functions.ts_parser_set_timeout_micros 1561 | export _root_.tree_sitter.functions.ts_parser_timeout_micros 1562 | export _root_.tree_sitter.functions.ts_query_capture_count 1563 | export _root_.tree_sitter.functions.ts_query_capture_name_for_id 1564 | export _root_.tree_sitter.functions.ts_query_capture_quantifier_for_id 1565 | export _root_.tree_sitter.functions.ts_query_cursor_delete 1566 | export _root_.tree_sitter.functions.ts_query_cursor_did_exceed_match_limit 1567 | export _root_.tree_sitter.functions.ts_query_cursor_match_limit 1568 | export _root_.tree_sitter.functions.ts_query_cursor_new 1569 | export _root_.tree_sitter.functions.ts_query_cursor_next_capture 1570 | export _root_.tree_sitter.functions.ts_query_cursor_next_match 1571 | export _root_.tree_sitter.functions.ts_query_cursor_remove_match 1572 | export _root_.tree_sitter.functions.ts_query_cursor_set_byte_range 1573 | export _root_.tree_sitter.functions.ts_query_cursor_set_match_limit 1574 | export _root_.tree_sitter.functions.ts_query_delete 1575 | export _root_.tree_sitter.functions.ts_query_disable_capture 1576 | export _root_.tree_sitter.functions.ts_query_disable_pattern 1577 | export _root_.tree_sitter.functions.ts_query_is_pattern_guaranteed_at_step 1578 | export _root_.tree_sitter.functions.ts_query_new 1579 | export _root_.tree_sitter.functions.ts_query_pattern_count 1580 | export _root_.tree_sitter.functions.ts_query_predicates_for_pattern 1581 | export _root_.tree_sitter.functions.ts_query_start_byte_for_pattern 1582 | export _root_.tree_sitter.functions.ts_query_string_count 1583 | export _root_.tree_sitter.functions.ts_query_string_value_for_id 1584 | export _root_.tree_sitter.functions.ts_set_allocator 1585 | export _root_.tree_sitter.functions.ts_tree_copy 1586 | export _root_.tree_sitter.functions.ts_tree_cursor_current_field_id 1587 | export _root_.tree_sitter.functions.ts_tree_cursor_current_field_name 1588 | export _root_.tree_sitter.functions.ts_tree_cursor_delete 1589 | export _root_.tree_sitter.functions.ts_tree_cursor_goto_first_child 1590 | export _root_.tree_sitter.functions.ts_tree_cursor_goto_first_child_for_byte 1591 | export _root_.tree_sitter.functions.ts_tree_cursor_goto_next_sibling 1592 | export _root_.tree_sitter.functions.ts_tree_cursor_goto_parent 1593 | export _root_.tree_sitter.functions.ts_tree_delete 1594 | export _root_.tree_sitter.functions.ts_tree_edit 1595 | export _root_.tree_sitter.functions.ts_tree_get_changed_ranges 1596 | export _root_.tree_sitter.functions.ts_tree_language 1597 | export _root_.tree_sitter.functions.ts_tree_print_dot_graph 1598 | export _root_.tree_sitter.functions.ts_node_child 1599 | export _root_.tree_sitter.functions.ts_node_child_by_field_id 1600 | export _root_.tree_sitter.functions.ts_node_child_by_field_name 1601 | export _root_.tree_sitter.functions.ts_node_child_count 1602 | export _root_.tree_sitter.functions.ts_node_descendant_for_byte_range 1603 | export _root_.tree_sitter.functions.ts_node_descendant_for_point_range 1604 | export _root_.tree_sitter.functions.ts_node_end_byte 1605 | export _root_.tree_sitter.functions.ts_node_end_point 1606 | export _root_.tree_sitter.functions.ts_node_eq 1607 | export _root_.tree_sitter.functions.ts_node_field_name_for_child 1608 | export _root_.tree_sitter.functions.ts_node_first_child_for_byte 1609 | export _root_.tree_sitter.functions.ts_node_first_named_child_for_byte 1610 | export _root_.tree_sitter.functions.ts_node_has_changes 1611 | export _root_.tree_sitter.functions.ts_node_has_error 1612 | export _root_.tree_sitter.functions.ts_node_is_extra 1613 | export _root_.tree_sitter.functions.ts_node_is_missing 1614 | export _root_.tree_sitter.functions.ts_node_is_named 1615 | export _root_.tree_sitter.functions.ts_node_is_null 1616 | export _root_.tree_sitter.functions.ts_node_named_child 1617 | export _root_.tree_sitter.functions.ts_node_named_child_count 1618 | export _root_.tree_sitter.functions.ts_node_named_descendant_for_byte_range 1619 | export _root_.tree_sitter.functions.ts_node_named_descendant_for_point_range 1620 | export _root_.tree_sitter.functions.ts_node_next_named_sibling 1621 | export _root_.tree_sitter.functions.ts_node_next_sibling 1622 | export _root_.tree_sitter.functions.ts_node_parent 1623 | export _root_.tree_sitter.functions.ts_node_prev_named_sibling 1624 | export _root_.tree_sitter.functions.ts_node_prev_sibling 1625 | export _root_.tree_sitter.functions.ts_node_start_byte 1626 | export _root_.tree_sitter.functions.ts_node_start_point 1627 | export _root_.tree_sitter.functions.ts_node_string 1628 | export _root_.tree_sitter.functions.ts_node_symbol 1629 | export _root_.tree_sitter.functions.ts_node_type 1630 | export _root_.tree_sitter.functions.ts_parser_logger 1631 | export _root_.tree_sitter.functions.ts_parser_parse 1632 | export _root_.tree_sitter.functions.ts_parser_set_logger 1633 | export _root_.tree_sitter.functions.ts_query_cursor_exec 1634 | export _root_.tree_sitter.functions.ts_query_cursor_set_point_range 1635 | export _root_.tree_sitter.functions.ts_tree_cursor_copy 1636 | export _root_.tree_sitter.functions.ts_tree_cursor_current_node 1637 | export _root_.tree_sitter.functions.ts_tree_cursor_goto_first_child_for_point 1638 | export _root_.tree_sitter.functions.ts_tree_cursor_new 1639 | export _root_.tree_sitter.functions.ts_tree_cursor_reset 1640 | export _root_.tree_sitter.functions.ts_tree_root_node --------------------------------------------------------------------------------