### Install Project Package Source: https://github.com/bearcove/arborium/blob/main/langs/group-willow/markdown/def/sample.md Installs the project's package using npm. Ensure Node.js and npm are installed. ```bash npm install my-package ``` -------------------------------- ### Setup Visual Regression Tests Source: https://github.com/bearcove/arborium/blob/main/tests/visual/README.md Navigate to the visual testing directory and install dependencies, including the Playwright Chromium browser. ```bash cd tests/visual npm install npx playwright install chromium ``` -------------------------------- ### Install Dependencies Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/CONTRIBUTING.md Install the necessary Node.js dependencies for the web binding. This should be run after cloning the repository. ```sh npm install ``` -------------------------------- ### Running the Arborium Example JSON Crate Source: https://github.com/bearcove/arborium/blob/main/EXTERNAL_GRAMMAR_CRATES.md Command to execute a full Arborium example crate that demonstrates grammar registration and JSON highlighting. ```bash cargo run --manifest-path examples/arborium-example-json/Cargo.toml --example highlight_with_arborium ``` -------------------------------- ### Running the Arborium JSON Example Source: https://github.com/bearcove/arborium/blob/main/examples/arborium-example-json/README.md Command to execute the Arborium JSON example using Cargo. This command builds and runs the `highlight_with_arborium` example, demonstrating the integration of the custom grammar crate. ```bash cargo run --manifest-path examples/arborium-example-json/Cargo.toml --example highlight_with_arborium ``` -------------------------------- ### Start Local Web Server for Testing Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Starts a local web server to test syntax highlighting in a browser. This server provides a UI for selecting languages, loading samples, and previewing highlighting. ```bash # Production mode (optimized build) cargo xtask serve ``` -------------------------------- ### Serve WASM Demo Source: https://github.com/bearcove/arborium/blob/main/DEVELOP.md Start the development server to test the WASM plugin. ```bash cargo xtask serve ``` -------------------------------- ### Build WASM Module and Serve Example Source: https://github.com/bearcove/arborium/blob/main/examples/wasm-browser/README.md Build the WebAssembly module for browser use and serve the example locally. This includes Rust language support by default. ```bash # From repository root cd examples/wasm-browser # Build the WASM module (includes Rust language support) wasm-pack build --target web --release # Serve the example python3 -m http.server 8080 # or npx serve . ``` -------------------------------- ### Install ImageMagick Source: https://github.com/bearcove/arborium/blob/main/tests/visual/README.md Install ImageMagick, which is required for JPEG-XL support. This is necessary for snapshot compression. ```bash # macOS brew install imagemagick # Linux (Ubuntu/Debian) apt install imagemagick ``` -------------------------------- ### Vim Script List Creation Examples Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Provides examples of creating lists in Vim script, including empty lists and lists containing other lists. ```vimscript :let mylist = [1, "two", 3, "four"] :let emptylist = [] :let nestlist = [[11, 12], [21, 22], [31, 32]] ``` -------------------------------- ### Start Local Web Server in Development Mode Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Starts the local web server in development mode, which offers faster rebuilds at the cost of optimizations. This is ideal for rapid iteration during development. ```bash # Development mode (faster rebuilds, no optimizations) cargo xtask serve --dev ``` -------------------------------- ### Example: Unpack List for Item Processing in Vimscript Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Illustrates unpacking a list into separate variables for processing, such as getting an item and its updated state. ```vimscript :let [s, item] = GetItem(s) ``` -------------------------------- ### Install Asciidoctor using gem install Source: https://github.com/bearcove/arborium/blob/main/demo/samples/asciidoc.adoc Installs the Asciidoctor gem directly. It is recommended to set up RVM before installation. ```bash gem install asciidoctor ``` -------------------------------- ### Compare Themes and Detect Language Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-cli/README.md Examples of comparing different themes and relying on auto-detection for language. ```bash # Compare different themes arborium --theme nord mycode.rs arborium --theme dracula mycode.rs # Highlight a script with shebang detection arborium script.py # Detects Python from .py extension echo '#!/usr/bin/env python3 print("hello")' | arborium - # Detects from shebang ``` -------------------------------- ### Build the Library Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/CONTRIBUTING.md Build the Web-tree-sitter library. This process requires a Rust toolchain to be installed. ```sh npm run build ``` -------------------------------- ### Start Development Server Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Launch the development server to test the Arborium integration. This allows for interactive testing of syntax highlighting and language features. ```bash cargo xtask serve --dev ``` -------------------------------- ### Vimscript Exception Handling Example Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Demonstrates throwing and catching custom exceptions with hierarchical structures and additional data. Includes examples for range errors, math overflows, zero division, and I/O write errors. ```vimscript :function! CheckRange(a, func) : if a:a < 0 : throw "EXCEPT:MATHERR:RANGE(" .. a:func .. ")" : endif :endfunction : :function! Add(a, b) : call CheckRange(a:a, "Add") : call CheckRange(a:b, "Add") : let c = a:a + a:b : if c < 0 : throw "EXCEPT:MATHERR:OVERFLOW" : endif : return c :endfunction : :function! Div(a, b) : call CheckRange(a:a, "Div") : call CheckRange(a:b, "Div") : if (a:b == 0) : throw "EXCEPT:MATHERR:ZERODIV" : endif : return a:a / a:b :endfunction : :function! Write(file) : try : execute "write" fnameescape(a:file) : catch /^Vim(write):/ : throw "EXCEPT:IO(" .. getcwd() .. ", " .. a:file .. "):WRITEERR" : endtry :endfunction : :try : : " something with arithmetic and I/O : :catch /^EXCEPT:MATHERR:RANGE/ : let function = substitute(v:exception, '.*(\(\a\+\)).*', '\1', "") : echo "Range error in" function : :catch /^EXCEPT:MATHERR/ " catches OVERFLOW and ZERODIV : echo "Math error" : :catch /^EXCEPT:IO/ : let dir = substitute(v:exception, '.*(\(.\+\),\s*\.\+\)).*', '\1', "") : let file = substitute(v:exception, '.*(. +, *\(. +\)).*', '\1', "") : if file !~ '^/' : let file = dir .. "/" .. file : endif : echo 'I/O error for "' .. file .. '"' : :catch /^EXCEPT/ : echo "Unspecified error" : :endtry ``` -------------------------------- ### Load web-tree-sitter with import (Vite) Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/README.md Install the web-tree-sitter module from NPM and load it using a system like Vite. ```javascript import { Parser } from 'web-tree-sitter'; Parser.init().then(() => { /* the library is ready */ }); ``` -------------------------------- ### Rust Code Highlighting Example Source: https://github.com/bearcove/arborium/blob/main/xtask/templates/index.stpl.html Basic example of using Arborium in Rust to highlight a code string. Ensure the necessary grammar is loaded. ```rust use arborium::highlight; let code = "fn main() { println!(\"Hello, world!\"); }\n"; let highlighted_code = highlight("rust", code).unwrap(); println!("{highlighted_code}"); ``` -------------------------------- ### Install tree-sitter CLI and language for wasm generation Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/README.md Install the tree-sitter-cli and the specific tree-sitter language package (e.g., tree-sitter-javascript) as development dependencies before generating a .wasm file. ```sh npm install --save-dev tree-sitter-cli tree-sitter-javascript ``` -------------------------------- ### Dictionary Creation Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Examples of creating dictionaries using literal syntax with string keys and values, and an empty dictionary. ```vimscript :let mydict = {'one': 1, 'two': 2, 'three': 3} ``` ```vimscript :let emptydict = {} ``` -------------------------------- ### Install Arborium Package Source: https://github.com/bearcove/arborium/blob/main/packages/arborium/README.md Install the Arborium package using npm. This is the first step for integrating Arborium into your project. ```bash npm install @arborium/arborium ``` -------------------------------- ### Install tree-sitter-javascript from npm Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/README.md Install the tree-sitter-javascript package from npm to obtain its .wasm language file. This is the recommended method for acquiring language files. ```sh npm install tree-sitter-javascript ``` -------------------------------- ### Install LLVM on macOS Source: https://github.com/bearcove/arborium/blob/main/README.template.md Install the LLVM compiler suite using Homebrew, which is required for WASM compilation on macOS. ```bash brew install llvm ``` -------------------------------- ### List Slicing Examples Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows how to create new lists by slicing existing ones. A slice `[:]` creates a shallow copy of the entire list. ```vimscript :let l = mylist[:3] " first four items :let l = mylist[4:4] " List with one item :let l = mylist[:] " shallow copy of a List ``` -------------------------------- ### Example: Append to Path Option in Vimscript Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Demonstrates appending a directory to the 'path' option, extending the search path for files. ```vimscript :let &path = &path .. ',/usr/local/include' ``` -------------------------------- ### Install Arborium CLI Tool Source: https://github.com/bearcove/arborium/blob/main/README.md Install the Arborium command-line interface tool using Cargo. This tool can be used for syntax highlighting in the terminal. ```bash cargo install arborium-cli ``` -------------------------------- ### Basic Groovy Syntax Example Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Demonstrates fundamental Groovy features such as classes, closures, and string interpolation. This is useful for showcasing basic language constructs. ```groovy // Basic Groovy features class Person { String name int age def greet() { println "Hello, I'm ${name} and I'm ${age} years old" } } // Closures def numbers = [1, 2, 3, 4, 5] def doubled = numbers.collect { it * 2 } // DSL-style builders def person = new Person(name: 'Alice', age: 30) person.greet() ``` -------------------------------- ### Syntax Highlighting Query (`highlights.scm`) Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Maps syntax tree nodes to highlight groups for syntax highlighting. Example shown for Kotlin. ```scheme ; Keywords [ "fun" "class" "interface" "object" "val" "var" ] @keyword ; Functions (function_declaration (simple_identifier) @function) ; Strings (string_literal) @string ; Comments (line_comment) @comment (multiline_comment) @comment ; Operators [ "+" "-" "*" "/" "=" "==" "!=" ] @operator ; Types (type_identifier) @type ; Constants (boolean_literal) @constant.builtin (integer_literal) @number ``` -------------------------------- ### Language Injection Query for Markdown (`injections.scm`) Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Injects documentation comments as markdown. Example shown for WIT. ```scheme ; Inject documentation comments as markdown ((comment) @injection.content (#set! injection.language "markdown")) ``` -------------------------------- ### Example: Sequential Assignment with List Unpacking in Vimscript Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Demonstrates sequential assignment during list unpacking where a later variable depends on an earlier one, showing the evaluation order. ```vimscript :let x = [0, 1] ``` ```vimscript :let i = 0 ``` ```vimscript :let [i, x[i]] = [1, 2] ``` ```vimscript :echo x ``` -------------------------------- ### Code Block Examples Source: https://github.com/bearcove/arborium/blob/main/xtask/templates/index.stpl.html Illustrates how code blocks should be structured for Arborium highlighting when using the automatic script tag. ```html
console.log("Hello, Arborium!");
body {
  color: #333;
}
``` -------------------------------- ### Logical OR and AND Operators Example Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows the usage of logical OR (||) and logical AND (&&) operators. Note that '&&' has precedence over '||', and expressions short-circuit. ```vimscript &nu || &list && &shell == "csh" ``` ```vimscript echo a || b ``` ```vimscript echo exists("b") && b == "yes" ``` -------------------------------- ### Example: Unpack List with Remaining Items in Vimscript Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows how to unpack a list into specific variables and collect any remaining items into a final 'rest' variable. ```vimscript :let [a, b; rest] = ["aval", "bval", 3, 4] ``` ```vimscript :let [a, b; rest] = ("aval", "bval", 3, 4) ``` -------------------------------- ### Example: Set Terminal Code in Vimscript Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows how to set a terminal code, like 't_k1', to a specific escape sequence. ```vimscript :let &t_k1 = "\[234;" ``` -------------------------------- ### Load web-tree-sitter with require (Webpack) Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/README.md Install the web-tree-sitter module from NPM and load it using a system like Webpack. ```javascript const { Parser } = require('web-tree-sitter'); Parser.init().then(() => { /* the library is ready */ }); ``` -------------------------------- ### Arborium KDL Grammar Configuration Source: https://github.com/bearcove/arborium/blob/main/DEVELOP.md Example of an `arborium.kdl` file, which defines the source of truth for a grammar crate's configuration. ```kdl repo "https://github.com/tree-sitter/tree-sitter-rust" commit "abc123..." license "MIT" grammar { id "rust" name "Rust" tag "code" tier 1 icon "devicon-plain:rust" aliases "rs" has-scanner #true generate-plugin #true sample { path "samples/example.rs" description "Example code" license "MIT" } } ``` -------------------------------- ### Vim Script Partial Function Creation Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Example of creating a partial function (Funcref with bound dictionary and arguments) using function(). ```vimscript let Cb = function('Callback', ['foo'], myDict) call Cb('bar') ``` -------------------------------- ### Python Dataclass and Function Source: https://github.com/bearcove/arborium/blob/main/demo/iife-demo.html Python example using dataclasses for data modeling and a function to process a list of users. ```Python from dataclasses import dataclass from typing import List, Optional @dataclass class User: name: str email: str age: Optional[int] = None def process_users(users: List[User]) -> dict: return { user.name: user.email for user in users if user.age is None or user.age >= 18 } ``` -------------------------------- ### Vim Script Dictionary Method Binding Example Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Demonstrates how dictionary methods are automatically bound to the dictionary instance when accessed or assigned. ```vimscript let myDict.myFunction = MyFunction call myDict.myFunction() let otherDict.myFunction = myDict.myFunction call otherDict.myFunction() ``` -------------------------------- ### Lambda Method Call Example Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows how to use a lambda function with the `->` operator for method calls. The lambda receives the object as its first argument. ```vimscript :GetPercentage()->{x -> x * 100}()->printf('%d%%') ``` -------------------------------- ### Publishing Language Group Crates Source: https://github.com/bearcove/arborium/blob/main/DEVELOP.md Example command for publishing crates within a specific language group, such as 'acorn'. These can be published in any order after pre-group crates. ```bash cargo xtask publish crates --group acorn ``` -------------------------------- ### Getting Line Number of Exception Throw Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt A practical example defining a function to retrieve the line number where an exception was thrown, using v:throwpoint. ```vimscript :function! LineNumber() : return substitute(v:throwpoint, '.*\D\(\d\+\).*', '\1', "") :endfunction :command! LineNumber try | throw "" | catch | echo LineNumber() | endtry ``` -------------------------------- ### Method Chaining Example Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Illustrates chaining multiple method calls on a list, passing the result of one method to the next. This is useful for complex data transformations. ```vimscript :mylist->filter(filterexpr)->map(mapexpr)->sort()->join() ``` -------------------------------- ### Timer callback with lambda Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Starts a timer that repeatedly executes a lambda function to echo a message three times with a 500ms interval. ```vimscript :let timer = timer_start(500, \ {-> execute("echo 'Handler called'", "")}, \ {'repeat': 3}) ``` -------------------------------- ### Install Asciidoctor on macOS Source: https://github.com/bearcove/arborium/blob/main/demo/samples/asciidoc.adoc Installs the Asciidoctor gem on macOS using the Homebrew package manager. Ensure Homebrew is installed. ```bash brew install asciidoctor ``` -------------------------------- ### Safely get Tuple item with get() Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Use the `get()` function to retrieve a tuple item by index, providing a default value if the index is out of bounds. ```vimscript :echo get(mytuple, idx) :echo get(mytuple, idx, "NONE") ``` -------------------------------- ### Blob Literal Example Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Demonstrates the syntax for creating a blob literal in Vim script using hexadecimal characters prefixed with '0z'. ```vimscript :let b = 0zFF00ED015DAF ``` -------------------------------- ### Serve Demo Website Source: https://github.com/bearcove/arborium/blob/main/README.template.md This command serves the WASM demo website, typically involving `wasm-pack`. ```bash cargo xtask serve-demo ``` -------------------------------- ### Recommended Workflow for Adding a New Language Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md This sequence of commands outlines the recommended steps for adding a new language to Arborium, from initial setup to testing and iteration. ```bash # 1. Create language structure mkdir -p langs/group-cedar/groovy/def/grammar/queries/samples # 2. Add files (arborium.yaml, grammar files, samples) # ... (copy files from upstream repo) # 3. Generate crate cargo xtask gen groovy # 4. Validate configuration cargo xtask lint # 5. Build (if generate-plugin is enabled) cargo xtask build groovy # 6. Start dev server cargo xtask serve --dev # 7. Test in browser at http://localhost:8080 # - Select "Groovy" from language dropdown # - Load sample files # - Verify syntax highlighting # 8. Iterate as needed # - Edit queries/highlights.scm to improve highlighting # - Re-run: cargo xtask gen groovy # - Refresh browser to see changes ``` -------------------------------- ### Highlight File and Stdin Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-cli/README.md Demonstrates highlighting a file by its extension and piping code from stdin. ```bash # Highlight a file (auto-detects language from extension) arborium file.rs # Highlight from stdin cat file.py | arborium - ``` -------------------------------- ### Check Asciidoctor Version Source: https://github.com/bearcove/arborium/blob/main/demo/samples/asciidoc.adoc Verifies the installed Asciidoctor version using the command line interface. This command is available after successful installation. ```bash asciidoctor --version ``` -------------------------------- ### Using Arborium Theme and Generating CSS Source: https://github.com/bearcove/arborium/blob/main/xtask/templates/arborium_theme_readme.stpl.md Demonstrates how to use a built-in theme, generate CSS for it, and access highlight definitions. Requires the arborium_theme crate. ```rust use arborium_theme::{Theme, builtin, HIGHLIGHTS}; // Use a built-in theme let theme = builtin::catppuccin_mocha(); // Generate CSS for the theme let css = theme.to_css("[data-theme=\"mocha\"]"); // Access highlight definitions for def in HIGHLIGHTS { println!("{} -> ", def.name, def.tag); } ``` -------------------------------- ### Serve WASM Demo Locally Source: https://github.com/bearcove/arborium/blob/main/README.template.md Builds and serves the WASM demo locally with optional address and port binding. Includes a `--dev` flag for faster development builds. ```bash cargo xtask serve-demo [options] ``` ```bash cargo xtask serve-demo --dev ``` -------------------------------- ### Safely Get Byte from Blob Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Retrieves a byte from a blob using `get()`, returning -1 or a specified default if the index is invalid. ```vimscript :echo get(myblob, idx) ``` ```vimscript :echo get(myblob, idx, 999) ``` -------------------------------- ### Execute Command with +eval Feature Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt This example shows how to execute commands when the '+eval' feature is available by using 'finish' to exit the script prematurely. The subsequent commands are skipped. ```vimscript if 1 echo "commands executed with +eval" finish endif args " command executed without +eval ``` -------------------------------- ### Install Arborium Plugin Source: https://github.com/bearcove/arborium/blob/main/xtask/templates/plugin_readme.stpl.md Install the Arborium grammar plugin using npm. This command adds the specified grammar package to your project dependencies. ```bash npm install @arborium/<%= grammar_id %> ``` -------------------------------- ### Serve WASM Demo Locally Source: https://github.com/bearcove/arborium/blob/main/xtask/README.md Builds and serves the WASM demo locally. Can specify a port or use a fast dev build. ```bash cargo xtask serve # Build and serve on auto-selected port ``` ```bash cargo xtask serve --dev # Fast dev build (skip wasm-opt) ``` ```bash cargo xtask serve -p 3000 # Serve on specific port ``` -------------------------------- ### Install Asciidoctor on Alpine Linux Source: https://github.com/bearcove/arborium/blob/main/demo/samples/asciidoc.adoc Installs the Asciidoctor gem on Alpine Linux using the apk package manager. Ensure you have sudo privileges. ```bash sudo apk add asciidoctor ``` -------------------------------- ### Arborium Sample File Configuration Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Shows how to reference sample files within the `arborium.yaml` configuration. This is essential for integrating sample code into the Arborium project. ```yaml samples: - path: samples/example.groovy description: Basic Groovy syntax demonstrating classes, closures, and string interpolation link: https://github.com/tree-sitter/tree-sitter-groovy/blob/main/examples/basic.groovy license: Apache-2.0 - path: samples/DSL.groovy description: Groovy builder pattern showing DSL capabilities link: https://github.com/tree-sitter/tree-sitter-groovy/blob/main/examples/dsl.groovy license: Apache-2.0 ``` -------------------------------- ### Safe List Item Access with get() Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Use the get() function to safely access list items, providing a default value if the index is invalid. ```vimscript :echo get(mylist, idx) ``` ```vimscript :echo get(mylist, idx, "NONE") ``` -------------------------------- ### Literal String Example Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows an example of a literal string constant in Vim script, where backslashes are treated literally except for doubling a single quote. ```vimscript if a =~ '\s*' ``` -------------------------------- ### Build Docker Image Source: https://github.com/bearcove/arborium/blob/main/demo/samples/just.txt Builds the plugin-builder Docker image for linux/amd64. Requires Docker and the CI Dockerfile. ```just docker-build: docker build --platform linux/amd64 -t {{docker_image}}:{{docker_tag}} -f Dockerfile.ci . ``` -------------------------------- ### Example Parse Tree Node Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md This example shows a parse tree structure for a function declaration, highlighting the 'simple_identifier' node which can be targeted for specific highlighting rules. ```text (source_file (function_declaration name: (simple_identifier) ; ← Target this for @function parameters: (parameter_list) body: (block))) ``` -------------------------------- ### Exception Handling After Command Execution (BufWritePost) Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows how an exception thrown after a command's main action (e.g., BufWritePost) is handled. If the main action fails, autocommands are skipped, and an error is thrown. This example demonstrates catching such errors. ```vim :autocmd BufWritePost * echo "File successfully written!" : ``` ```vim :try : write /i/m/p/o/s/s/i/b/l/e :catch : echo v:exception :endtry ``` -------------------------------- ### Run Tests with Coverage Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/CONTRIBUTING.md Execute the test suite and generate coverage information. This command is run from the lib/binding_web directory. ```sh npm test -- --coverage ``` -------------------------------- ### Get Vim Executable Path Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Use exepath() to get the full path of the Vim executable, which is useful for ensuring the correct Vim instance is invoked, especially when dealing with relative paths or different operating systems. ```vimscript echo exepath(v:progpath) ``` -------------------------------- ### Build and Serve Language Crate Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md Use `cargo xtask build` to compile a specific language or all languages. `cargo xtask serve` starts a demo server for testing syntax highlighting. ```bash # Build a specific language cargo xtask build groovy # Build all languages cargo xtask build # Run the demo server (includes all languages) cargo xtask serve # Development mode (faster rebuilds) cargo xtask serve --dev ``` -------------------------------- ### Get Length of Dictionary Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Returns the number of key-value pairs in a dictionary. ```vimscript :let l = len(dict) ``` -------------------------------- ### Troubleshooting: Sample File Not Found Source: https://github.com/bearcove/arborium/blob/main/ADDING_GRAMMARS.md This error occurs when a sample file referenced in the `arborium.yaml` configuration does not exist at the specified path. ```bash Error: Sample file samples/example.groovy does not exist ``` -------------------------------- ### Run Tests Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/CONTRIBUTING.md Execute the test suite for the Web-tree-sitter binding. This command is run from the lib/binding_web directory. ```sh npm test ``` -------------------------------- ### Multi-line Method Chaining Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Demonstrates how to split method chaining across multiple lines for better readability using line continuation (`\`). ```vimscript :mylist \ ->filter(filterexpr) \ ->map(mapexpr) \ ->sort() \ ->join() ``` -------------------------------- ### Get Minimum Value in Dictionary Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Finds the minimum value among all entries in a dictionary. ```vimscript :let small = min(dict) ``` -------------------------------- ### Get Maximum Value in Dictionary Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Finds the maximum value among all entries in a dictionary. ```vimscript :let big = max(dict) ``` -------------------------------- ### Basic Exception Handling Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Demonstrates a simple try/catch block to handle exceptions thrown by a function. It shows how to catch specific patterns or all exceptions. ```vim :function! Foo() : throw "foo" :endfunction : :function! Bar() : try : call Foo() : catch /foo/ : echo "Caught foo, throw bar" : throw "bar" : endtry :endfunction : try : call Bar() :catch /.*/ : echo "Caught" v:exception :endtry ``` -------------------------------- ### Generate Grammar Crate Files Source: https://github.com/bearcove/arborium/blob/main/DEVELOP.md Run this command after creating a new grammar definition to generate the necessary crate files. ```bash cargo xtask gen ``` -------------------------------- ### Get Numbered Function Reference Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Retrieves the Funcref for a numbered function, useful for debugging. ```vimscript :function g:42 ``` -------------------------------- ### Map Dictionary Values Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Applies a transformation to each value in a dictionary. The example prepends '>> ' to each value. ```vimscript :call map(dict, '>> " .. v:val') ``` -------------------------------- ### Catching Vim Interrupt Exception Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Example of a try block that catches a Vim interrupt exception. ```vimscript try | sleep 100 | catch /^Vim:Interrupt$/ | endtry ``` -------------------------------- ### Highlight with Explicit Language and HTML Output Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-cli/README.md Shows how to explicitly specify the language for highlighting and generate HTML output. ```bash # Highlight with explicit language arborium --lang javascript "const x = 42;" # Generate HTML output arborium --html index.js ``` -------------------------------- ### Catching Vim Edit Error Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Example of a try block that catches a specific Vim edit error. ```vimscript try | edit | catch /^Vim(edit):E\d\+/ | echo "error" | endtry ``` -------------------------------- ### Initialize Parser Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/README.md Create a new instance of the Tree-sitter parser. ```javascript const parser = new Parser(); ``` -------------------------------- ### Expanding filename with expand() function Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Use the expand() function with '%' to get the current filename. This is different from simply echoing '%'. ```vim :echo expand("%”) ``` -------------------------------- ### Catching Exceptions with Patterns Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Shows how to use try/catch blocks with pattern matching to handle different types of thrown exceptions. Specific patterns should be listed before general ones. ```vimscript :function! Foo(value) : try : throw a:value : catch /^\d\+$/ : echo "Number thrown" : catch /.*/ : echo "String thrown" : endtry :endfunction : :call Foo(0x1267) :call Foo('string') ``` -------------------------------- ### Clone the Repository Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/CONTRIBUTING.md Clone the tree-sitter repository to begin development. Navigate to the web binding directory after cloning. ```sh git clone https://github.com/tree-sitter/tree-sitter cd tree-sitter/lib/binding_web ``` -------------------------------- ### Generate Demo HTML Source: https://github.com/bearcove/arborium/blob/main/README.template.md This command generates the `index.html` file for the WASM demo website. ```bash cargo xtask generate-demo ``` -------------------------------- ### Add Arborium Dependency to Cargo.toml Source: https://github.com/bearcove/arborium/blob/main/EXTERNAL_GRAMMAR_CRATES.md Include this entry in your Cargo.toml to add Arborium as a dependency for in-crate usage examples. ```toml [package] name = "arborium-mylanguage" version = "0.1.0" edition = "2024" rust-version = "1.85" [lib] path = "src/lib.rs" [dependencies] tree-sitter-language = "0.1" [build-dependencies] cc = "1" ``` ```toml arborium = { version = "2", default-features = false } ``` -------------------------------- ### Launch Application with Arguments Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Launches an application with specified arguments using system programs. Intended for GUI applications. User is responsible for argument escaping. ```vimscript dist#vim9#Launch(file: string) ``` ```vimscript vim9script import autoload 'dist/vim9.vim' # Execute 'makeprg' into another xterm window vim9.Launch('xterm ' .. expandcmd(&makeprg)) ``` ```vimscript :call dist#vim9#Launch() ``` ```vimscript :Launch . ``` -------------------------------- ### Add Arborium as a Rust Library Source: https://github.com/bearcove/arborium/blob/main/README.md Install the Arborium crate using Cargo. By default, all permissively licensed grammars are included. ```bash cargo add arborium ``` -------------------------------- ### Load web-tree-sitter with Deno Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-tree-sitter/binding_web/README.md Use the web-tree-sitter module with Deno by importing from npm:web-tree-sitter. ```javascript import { Parser } from "npm:web-tree-sitter"; await Parser.init(); // the library is ready ``` -------------------------------- ### Vimscript: Convert Number to Binary Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Example usage of the `Nr2Bin` function to convert the number 32 to its binary string representation. ```vim :echo Nr2Bin(32) ``` -------------------------------- ### Basic Caddyfile Configuration Source: https://github.com/bearcove/arborium/blob/main/demo/samples/caddy.txt This snippet shows a basic Caddyfile configuration for a website. It sets the site address, the root directory for static files, and enables the static file server. ```caddyfile :80 { # Set this path to your site's directory. root * /usr/share/caddy # Enable the static file server. file_server # Another common task is to set up a reverse proxy: # reverse_proxy localhost:8080 # Or serve a PHP site through php-fpm: # php_fastcgi localhost:9000 } ``` -------------------------------- ### Preview Plugin Grouping Source: https://github.com/bearcove/arborium/blob/main/xtask/README.md Optionally previews how plugins would be grouped for parallel CI builds. Use `-n` to specify the number of groups. ```bash # 2. Preview grouping (optional) cargo xtask plugins groups -n 2 ``` -------------------------------- ### Blob Slicing Examples Source: https://github.com/bearcove/arborium/blob/main/langs/group-sage/vim/def/samples/eval.txt Illustrates slicing a Blob to extract a portion of its bytes. A slice `[:]` creates a copy of the entire Blob. ```vimscript :let b = 0zDEADBEEF :let bs = b[1:2] " 0zADBE :let bs = b[:] " copy of 0zDEADBEEF ``` -------------------------------- ### Highlight with Specific Theme Source: https://github.com/bearcove/arborium/blob/main/crates/arborium-cli/README.md Demonstrates using a specific color theme for ANSI output. ```bash # Use a specific theme arborium --theme dracula script.sh ```