### Parse a Full Bash Script in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-bash/readme.md Illustrates parsing a complete Bash script using the Oak Bash Parser. This example is similar to the quick start but focuses on the script parsing functionality, showing how to handle multi-line scripts. ```rust use oak_bash::{Parser, BashLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#" #!/bin/bash echo "Hello" "#); let result = parser.parse(&source); println!("Parsed Bash script successfully."); ``` -------------------------------- ### Basic Zig Parsing with Oak Zig Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-zig/readme.md Demonstrates the basic usage of the Oak Zig parser to parse a simple Zig source code. It initializes the parser, defines source text, and performs the parsing operation. This is a fundamental example for getting started with the library. ```rust use oak_zig::{Parser, ZigLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r###" const std = @import("std"); pub fn main() void { const message = "Hello, Zig!"; std.debug.print("{s}\n", .{message}); } "###); let result = parser.parse(&source); println!("Parsed Zig successfully."); Ok(()) } ``` -------------------------------- ### Basic Haskell Parsing with Oak Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-haskell/readme.md Demonstrates the basic usage of the Oak Haskell parser. It initializes the parser, creates source text from a Haskell code string, and performs the parsing operation. This is a fundamental example for getting started with the library. ```rust use oak_haskell::{Parser, HaskellLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"\nmain :: IO ()\nmain = putStrLn "Hello, Haskell!"\n\nadd :: Int -> Int -> Int\nadd x y = x + y\n "#); let result = parser.parse(&source); println!("Parsed Haskell successfully."); Ok(()) } ``` -------------------------------- ### Basic SQL Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-sql/readme.md Demonstrates the basic usage of the Oak SQL parser to parse a simple SELECT statement. It initializes the parser, defines the source text, and calls the parse method. This is a fundamental example for getting started with the library. ```rust use oak_sql::{Parser, SqlLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#" SELECT u.id, u.name, p.title FROM users u JOIN posts p ON u.id = p.user_id WHERE u.active = true ORDER BY u.created_at DESC LIMIT 10; "#); let result = parser.parse(&source); println!("Parsed SQL successfully."); Ok(()) } ``` -------------------------------- ### Basic Lean Parsing with Oak Lean Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-lean/readme.md Demonstrates the basic usage of the Oak Lean parser to parse a Lean source code snippet. It initializes the parser, creates source text, and performs the parsing operation. This is a fundamental example for getting started with the library. ```rust use oak_lean::{Parser, LeanLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#" def factorial : ℕ → ℕ | 0 := 1 | (n + 1) := (n + 1) * factorial n theorem factorial_pos (n : ℕ) : factorial n > 0 := begin induction n with n ih, { simp [factorial] }, { simp [factorial, ih, mul_pos] } end "#); let result = parser.parse(&source); println!("Parsed Lean successfully."); Ok(()) } ``` -------------------------------- ### Basic GraphQL Query Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-graphql/readme.md Demonstrates the basic usage of the Oak GraphQL parser to parse a simple GraphQL query. It initializes the parser, defines the source text of the query, and then calls the parse method. This is a fundamental example for getting started with the library. ```rust use oak_graphql::{Parser, GraphQLLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"query GetUser($id: ID!) { user(id: $id) { name email posts { title content } } }"#); let result = parser.parse(&source); println!("Parsed GraphQL successfully."); Ok(()) } ``` -------------------------------- ### Basic F# Parsing with Oak Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-fsharp/readme.md Demonstrates the basic usage of the Oak F# parser to parse a simple F# source code string. It initializes the parser, creates a SourceText object, and calls the parse method. This is a foundational example for getting started. ```rust use oak_fsharp::{Parser, FSharpLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"\ let helloWorld = printfn "Hello, F#!" helloWorld "#); let result = parser.parse(&source); println!("Parsed F# successfully."); Ok(()) } ``` -------------------------------- ### Implement Custom Layout Algorithm in Rust Source: https://github.com/ygg-lang/oaks/blob/master/projects/oak-visualize/readme.md Demonstrates how to implement a custom layout algorithm by defining a struct that implements the `LayoutAlgorithm` trait. This example creates a sine wave pattern for node positions. It requires the `oak_visualize` crate. ```rust use oak_visualize::{LayoutAlgorithm, Position, Node}; struct CustomLayout { spacing: f64, } impl LayoutAlgorithm for CustomLayout { fn layout(&self, nodes: &[Node]) -> Result, LayoutError> { let mut positions = Vec::new(); for (i, node) in nodes.iter().enumerate() { let x = (i as f64) * self.spacing; let y = (i as f64).sin() * 100.0; // Sine wave pattern positions.push(Position::new(x, y)); } Ok(positions) } } ``` -------------------------------- ### Python Code Highlighting to HTML Source: https://github.com/ygg-lang/oaks/blob/master/projects/oak-highlight/readme.md Illustrates highlighting Python code and outputting it as HTML using the Oak highlighter. This example uses the VSCode theme and specifies the HTML output format for web display. ```rust use oak_highlight::{Highlighter, Theme, OutputFormat}; let highlighter = Highlighter::new(); let python_code = r###"import asyncio import aiohttp from typing import List, Optional async def fetch_data(urls: List[str]) -> List[str]: """Fetch data from multiple URLs concurrently.""" async with aiohttp.ClientSession() as session: tasks = [fetch_single(session, url) for url in urls] results = await asyncio.gather(*tasks) return results async def fetch_single(session: aiohttp.ClientSession, url: str) -> Optional[str]: try: async with session.get(url) as response: return await response.text() except aiohttp.ClientError as e: print(f"Error fetching {url}: {e}") return None"###; let highlighted = highlighter.highlight_format( python_code, "python", Theme::VSCode, OutputFormat::Html )?; println!("HTML highlighted Python code:\n{}", highlighted); ``` -------------------------------- ### Document Parsing Example in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-markdown/readme.md Illustrates how to parse a complete Markdown document using the Oak Markdown parser. This example focuses on parsing a document with a main heading and some introductory text, showcasing the parser's ability to handle document structures. ```rust use oak_markdown::{Parser, MarkdownLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("# My Document\n\nThis is a simple document."); let result = parser.parse(&source); println!("Document parsed successfully."); ``` -------------------------------- ### Token-Level GraphQL Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-graphql/readme.md Demonstrates parsing GraphQL at a token level, which can be useful for more granular analysis or custom processing. This example parses a simple query and indicates completion. ```rust use oak_graphql::{Parser, GraphQLLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("query { user { name } }"); let result = parser.parse(&source); println!("Token parsing completed."); ``` -------------------------------- ### Simplified AST Representation Example Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-dockerfile/readme.md This Rust code snippet illustrates a simplified Abstract Syntax Tree (AST) node structure for a Dockerfile 'FROM' instruction. It shows how the command and its arguments are represented. ```rust // Simplified AST representation for: // FROM alpine:latest pex_docker::ast::Node::Instruction { command: "FROM".to_string(), arguments: vec![ "alpine:latest".to_string(), ], } ``` -------------------------------- ### Rust Code Block Example Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-markdown/tests/lexer/basic.markdown Demonstrates a basic 'Hello, world!' program in Rust. This snippet is used to test Rust code block rendering within Markdown. ```rust fn main() { println!("Hello, world!"); } ``` -------------------------------- ### Parse MSIL Assembly Example Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-msil/readme.md Provides a concrete example of parsing an MSIL assembly definition. It demonstrates how to initialize the parser and use `parse_assembly` to obtain an `Assembly` AST, then prints the number of modules and classes found. Requires the `oak_msil` crate. ```rust use oak_msil::{MsilParser, ast::Assembly}; let parser = MsilParser::new(); let msil_code = r#" .assembly Calculator { .ver 1:0:0:0 } .module Calculator.exe .class public Calculator { .method public static int32 Add(int32, int32) cil managed { .maxstack 2 ldarg.0 ldarg.1 add ret } } "#; let assembly = parser.parse_assembly(msil_code)?; println!("Modules: {}", assembly.modules.len()); println!("Classes: {}", assembly.classes.len()); ``` -------------------------------- ### Parse Basic Erlang Module - Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-erlang/readme.md Demonstrates the basic usage of the Oak Erlang parser to parse a simple Erlang module. It initializes the parser, defines source text, and calls the parse method. This is a fundamental example for getting started. ```rust use oak_erlang::{Parser, ErlangLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new( r#"-module(hello). -export([greet/0]). greet() -> io:format(\"Hello, Erlang!\\n\"). "# ); let result = parser.parse(&source); println!("Parsed Erlang successfully."); Ok(()) } ``` -------------------------------- ### Token-Level Parsing with Oak Lean Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-lean/readme.md Demonstrates token-level parsing using the Oak Lean parser. This example shows how to parse a simple Lean definition and confirms the completion of token parsing. ```rust use oak_lean::{Parser, LeanLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("def hello := \"world\""); let result = parser.parse(&source); println!("Token parsing completed."); ``` -------------------------------- ### Rust: Parse Markdown Document Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-scheme/readme.md Demonstrates basic Markdown parsing using the MarkdownParser from the oak-markdown crate. It initializes a parser, defines a Markdown string, and parses it into a document structure, printing the number of blocks found. This is a fundamental example for getting started with the library. ```rust use oak_markdown::MarkdownParser; fn main() -> Result<(), Box> { let parser = MarkdownParser::new(); let markdown = r"# Hello World This is a **bold** statement and this is *italic* text. ## Features - First item - Second item - Third item [Link to documentation](https://docs.rs/oak-markdown)"; let document = parser.parse(markdown)?; println!("Parsed {} blocks", document.blocks.len()); Ok(()) } ``` -------------------------------- ### Rust: Token-Level Coq Parsing Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-coq/readme.md Demonstrates token-level parsing with the Oak Coq Parser. This example shows how to obtain token information from the parse result, which can be useful for more granular analysis or custom processing. ```rust use oak_coq::{Parser, CoqLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("Theorem plus_comm : forall n m : nat, n + m = m + n."); let result = parser.parse(&source); // Token information is available in the parse result ``` -------------------------------- ### Bash Script Example Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-markdown/tests/lexer/basic.markdown A simple Bash script demonstrating a shebang and basic commands like 'echo' and 'ls'. This tests Bash code block rendering. ```bash #!/bin/bash echo "This is a bash script" ls -la ``` -------------------------------- ### Heading Parsing Example in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-markdown/readme.md Shows a specific example of parsing a Markdown heading using the Oak Markdown parser. This snippet focuses on extracting and processing heading elements, demonstrating the parser's capability to identify and structure different Markdown components. ```rust use oak_markdown::{Parser, MarkdownLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("## My Heading\n\nSome content here."); let result = parser.parse(&source); println!("Heading parsed successfully."); ``` -------------------------------- ### Rust Code Highlighting with Different Theme Source: https://github.com/ygg-lang/oaks/blob/master/projects/oak-highlight/readme.md Shows how to highlight Rust code using a different theme (Monokai) with the Oak highlighter. This example focuses on a more complex Rust code snippet involving HashMaps and structs. ```rust use oak_highlight::{Highlighter, Theme}; let highlighter = Highlighter::new(); let rust_code = r###"use std::collections::HashMap; fn process_data(items: Vec<&str>) -> Result, Error> { let mut counts = HashMap::new(); for item in items { *counts.entry(item.to_string()).or_insert(0) += 1; } Ok(counts) } #[derive(Debug)] struct Config { debug: bool, timeout: Duration, }"###; let highlighted = highlighter.highlight(rust_code, "rust", Theme::Monokai)?; println!("Highlighted Rust code:\n{}", highlighted); ``` -------------------------------- ### Token-Level Parsing of Bash in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-bash/readme.md Demonstrates token-level parsing of a Bash command. This example highlights the lexer support within the Oak Bash Parser, allowing access to individual tokens and their properties. ```rust use oak_bash::{Parser, BashLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("echo \"Hello World\""); let result = parser.parse(&source); // Token information is available in the parse result ``` -------------------------------- ### Rust: Parsing a Coq Theorem Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-coq/readme.md Shows how to parse a Coq theorem using the Oak Coq Parser. This example is similar to the basic usage but focuses specifically on parsing a theorem statement and its proof. ```rust use oak_coq::{Parser, CoqLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#"Theorem plus_assoc : forall n m p : nat, n + (m + p) = (n + m) + p. Proof. intros n m p. induction n as [| n' IHn']. - simpl. reflexivity. - simpl. rewrite IHn'. reflexivity. Qed. "#); let result = parser.parse(&source); println!("Parsed Coq theorem successfully."); ``` -------------------------------- ### Token-Level Parsing with Oak C++ Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-cpp/readme.md Demonstrates token-level parsing with the Oak C++ parser. This example shows how to obtain token information from the parsed source code. It requires the `oak_cpp` crate. ```rust use oak_cpp::{Parser, CppLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("int main() { return 0; }"); let result = parser.parse(&source); // Token information is available in the parse result ``` -------------------------------- ### Parsing C# Class Definitions Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-csharp/readme.md Illustrates how to parse C# class definitions, including methods and properties. This example shows the parser's capability to handle structured class syntax. ```rust use oak_csharp::{Parser, CSharpLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#" public class Calculator { public int Add(int a, int b) { return a + b; } public int Subtract(int a, int b) { return a - b; } } "#); let result = parser.parse(&source); println!("Class parsed successfully."); ``` -------------------------------- ### Basic Python Parsing with Oak Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-python/readme.md Demonstrates the basic usage of the Oak Python parser to parse a simple Python script. It initializes the parser, defines source text, and calls the parse method. This is a fundamental example for getting started. ```rust use oak_python::{Parser, PythonLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"\ndef greet(name):\n print(f"Hello, {name}!")\n\ngreet("World")\n "#); let result = parser.parse(&source); println!("Parsed Python successfully."); Ok(()) } ``` -------------------------------- ### Basic Markdown Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-markdown/readme.md Demonstrates the basic usage of the Oak Markdown parser to parse a simple Markdown string. It initializes the parser, creates a SourceText object, and calls the parse method. This is a fundamental example for getting started with the library. ```rust use oak_markdown::{Parser, MarkdownLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new("# Hello, Markdown!\n\nThis is a **paragraph** with *emphasis*.\n\n## Features\n\n- Lists\n- Code blocks\n- And more!\n "); let result = parser.parse(&source); println!("Parsed Markdown successfully."); Ok(()) } ``` -------------------------------- ### Basic Go Program Parsing with Oak Go Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-go/readme.md Demonstrates the basic usage of the Oak Go parser to parse a simple Go program. It initializes the parser, defines source text, and performs the parsing operation. This is a foundational example for understanding how to use the library. ```rust use oak_go::{Parser, GoLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"package main import "fmt" func main() { fmt.Println("Hello, Go!") } "#); let result = parser.parse(&source); println!("Parsed Go successfully."); Ok(()) } ``` -------------------------------- ### Basic Scala Parsing with Oak Scala Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-scala/readme.md Demonstrates the basic usage of the Oak Scala parser to parse a simple Scala object. It initializes the parser, defines source text, and performs the parsing operation. This is a fundamental example for getting started with the library. ```rust use oak_scala::{Parser, ScalaLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#" object HelloWorld { def main(args: Array[String]): Unit = { println("Hello, World!") } }"#); let result = parser.parse(&source); println!("Parsed Scala successfully."); Ok(()) } ``` -------------------------------- ### Token-Level Parsing in Go with Oak Go Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-go/readme.md Demonstrates token-level parsing using the Oak Go parser. This example shows how to parse a simple Go expression and indicates that token information is available in the parse result, useful for detailed analysis. ```rust use oak_go::{Parser, GoLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("x := 42"); let result = parser.parse(&source); // Token information is available in the parse result ``` -------------------------------- ### Parse a WIT Component (Rust) Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-wit-component/readme.md Demonstrates the basic usage of the Oak WIT Component Parser to parse a complete WIT component. It initializes the parser, defines source text for a WIT component, and calls the parse method. This is useful for understanding the fundamental parsing workflow. ```rust use oak_wit_component::{Parser, WitComponentLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r##" package example:calculator; interface calculator { add: func(a: f32, b: f32) -> f32; subtract: func(a: f32, b: f32) -> f32; } world calculator-world { import calculator; } "##); let result = parser.parse(&source); println!("Parsed WIT Component successfully."); Ok(()) } ``` -------------------------------- ### Parsing a WAT Module in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-wat/readme.md Illustrates how to parse a complete WebAssembly module definition using the Oak WAT parser. It shows the setup with `Parser`, `SourceText`, and the subsequent parsing call. This is useful for validating module structures. ```rust use oak_wat::{Parser, WatLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#"( module (func $multiply (param $a i32) (param $b i32) (result i32)) local.get $a local.get $b i32.mul ) (export "multiply" (func $multiply)) )"#); let result = parser.parse(&source); println!("Module parsed successfully."); ``` -------------------------------- ### Basic Ruby Parsing with Oak Ruby Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-ruby/readme.md Demonstrates the basic usage of the Oak Ruby parser to parse a simple Ruby source string. It initializes the parser, creates a SourceText object, and calls the parse method. This is a fundamental example for getting started with the library. ```rust use oak_ruby::{Parser, RubyLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"puts "Hello, World!" name = "Ruby" puts "Welcome to #{name}!" "#); let result = parser.parse(&source); println!("Parsed Ruby successfully."); Ok(()) } ``` -------------------------------- ### Basic Pascal Program Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-pascal/readme.md Demonstrates the basic usage of the Oak Pascal parser to parse a simple 'Hello, World!' Pascal program. It initializes the parser, provides source text, and executes the parsing operation. ```rust use oak_pascal::{Parser, PascalLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"\nprogram HelloWorld;\nbegin\n writeln('Hello, World!');\nend.\n "#); let result = parser.parse(&source); println!("Parsed Pascal successfully."); Ok(()) } ``` -------------------------------- ### Basic MATLAB Parsing with Oak MATLAB Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-matlab/readme.md Demonstrates the basic usage of the Oak MATLAB parser to parse a simple MATLAB script. It initializes the parser, creates source text from a string, and then parses it. This example is suitable for getting started with the library. ```rust use oak_matlab::{Parser, MatlabLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"function result = add(a, b) result = a + b; end disp('Hello, MATLAB!'); "#); let result = parser.parse(&source); println!("Parsed MATLAB successfully."); Ok(()) } ``` -------------------------------- ### Basic Wolfram Language Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-wolfram/readme.md Demonstrates the basic usage of the Oak Wolfram parser to parse a simple Wolfram Language source text. It initializes the parser, creates a SourceText object, and calls the parse method. This is a fundamental example for getting started with the library. ```rust use oak_wolfram::{Parser, WolframLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new( r#"f[x_] := x^2 + 2*x + 1 Plot[f[x], {x, -10, 10}]"# ); let result = parser.parse(&source); println!("Parsed Wolfram successfully."); Ok(()) } ``` -------------------------------- ### Create Custom Themes in Rust Source: https://github.com/ygg-lang/oaks/blob/master/projects/oak-highlight/readme.md Demonstrates how to create and apply a custom color theme for syntax highlighting using the Oak Highlight library in Rust. It involves defining colors for background, foreground, and specific token styles. ```rust use oak_highlight::{Highlighter, Theme, TokenStyle, Color}; let mut highlighter = Highlighter::new(); // Create a custom theme let custom_theme = Theme::Custom { name: "MyTheme".to_string(), background: Color::Rgb(40, 42, 54), foreground: Color::Rgb(248, 248, 242), styles: vec![ (TokenStyle::Keyword, Color::Rgb(255, 121, 198)), (TokenStyle::String, Color::Rgb(241, 250, 140)), (TokenStyle::Comment, Color::Rgb(98, 114, 164)), (TokenStyle::Function, Color::Rgb(80, 250, 123)), (TokenStyle::Number, Color::Rgb(189, 147, 249)), ] }; let code = "fn main() { println!(\"Hello\"); }"; let highlighted = highlighter.highlight(code, "rust", custom_theme)?; ``` -------------------------------- ### Rust: Basic Julia Code Parsing Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-julia/readme.md Demonstrates the basic usage of the Oak Julia parser to parse a simple Julia function and print its output. It initializes the parser, defines source text, and calls the parse method. This is a fundamental example for getting started with parsing Julia code. ```rust use oak_julia::{Parser, JuliaLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"\nfunction fibonacci(n)\n if n <= 1\n return n\n else\n return fibonacci(n-1) + fibonacci(n-2)\n end\nend\n\nprintln(fibonacci(10))\n "#); let result = parser.parse(&source); println!("Parsed Julia successfully."); Ok(()) } ``` -------------------------------- ### Parse Vampire Problem with AST Generation Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-vampire/readme.md This example shows how to parse a Vampire problem and get the number of tokens generated. It utilizes VampireLexer and VampireLanguage from the oak-vampire crate, along with SourceText from oak-core. ```rust use oak_vampire::{VampireLexer, VampireLanguage, ast::ValkyrieModule}; use oak_core::{Lexer, SourceText}; let language = VampireLanguage::default(); let lexer = VampireLexer::new(&language); let vampire_code = r#" fof(commutativity, axiom, ( ! [X, Y] : ( X + Y = Y + X ) )). fof(associativity, axiom, ( ! [X, Y, Z] : ( (X + Y) + Z = X + (Y + Z) ) )). fof(goal, conjecture, ( ! [A, B, C] : ( A + (B + C) = (C + A) + B ) )). "#; let source = SourceText::new(vampire_code); let output = lexer.lex(&source); println!("Tokens: {}", output.result.map_or(0, |tokens| tokens.len())); ``` -------------------------------- ### Basic Fortran Program Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-fortran/readme.md Demonstrates the basic usage of the Oak Fortran parser to parse a simple 'Hello, Fortran!' program. It initializes the parser, creates source text, and performs the parsing operation. Dependencies include the 'oak_fortran' crate. ```rust use oak_fortran::{Parser, FortranLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"\nprogram hello\n print *, \"Hello, Fortran!\"\nend program hello\n "#); let result = parser.parse(&source); println!("Parsed Fortran successfully."); Ok(()) } ``` -------------------------------- ### Handlebars Subexpression Syntax Example - Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-handlebars/readme.md Shows the syntax for Handlebars subexpressions, which allow for nested function calls or complex expressions within tags. This example includes examples of using subexpressions with 'filter', 'and', and 'gt' helpers. It focuses on the template source code. ```rust let source = r#" {{#each (filter posts "published")}}
{{title}}
{{/each}} {{#if (and user.isAdmin (gt posts.length 0))}}
Admin controls here
{{/if}} "#; ``` -------------------------------- ### Parse Nginx Configuration with Oak Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-nginx/readme.md This Rust code snippet demonstrates how to use the Oak parsing framework and the oak-nginx library to parse a sample Nginx configuration string. It initializes a parser and the Nginx language, then attempts to parse the configuration. The output will indicate success with the generated AST or failure with a parse error. ```rust use oak::Parser; use oak_nginx::NginxLanguage; fn main() { let config = r#" server { listen 80; server_name example.com www.example.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /static { root /var/www/html; expires 1d; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; } "#; let mut parser = Parser::new(); let language = NginxLanguage::new(); match parser.parse(&config, &language) { Ok(ast) => { println!("Successfully parsed Nginx configuration!"); println!("AST: {:#?}", ast); } Err(error) => { eprintln!("Parse error: {}", error); } } } ``` -------------------------------- ### Token-Level Java Parsing with Oak Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-java/readme.md Demonstrates parsing Java code at the token level. This example parses a simple variable declaration statement. ```rust use oak_java::{Parser, JavaLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("int x = 42;"); let result = parser.parse(&source); println!("Token parsing completed."); ``` -------------------------------- ### JavaScript Function Example Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-markdown/tests/lexer/basic.markdown Illustrates a simple JavaScript function that greets a user by name. This snippet tests JavaScript code block rendering. ```javascript function greet(name) { return `Hello, ${name}!`; } ``` -------------------------------- ### Parsing Go Functions with Oak Go Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-go/readme.md Illustrates how to use the Oak Go parser to specifically parse Go function definitions. This example focuses on parsing a function signature and its body, showcasing the parser's ability to handle function constructs. ```rust use oak_go::{Parser, GoLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#"func add(a, b int) int { return a + b }"#); let result = parser.parse(&source); println!("Function parsed successfully."); ``` -------------------------------- ### Parsing a Simple AsciiDoc Document in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-ascii-doc/readme.md Shows how to parse a minimal AsciiDoc document with a title. This example focuses on the core document parsing functionality. ```rust use oak_ascii_doc::{Parser, AsciiDocLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#" = My Title A simple document. "#); let result = parser.parse(&source); println!("Parsed AsciiDoc document successfully."); ``` -------------------------------- ### Parse PHP Function Definition Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-php/readme.md Illustrates how to parse PHP code containing a function definition. This example shows the parser handling function declarations and their bodies. ```rust use oak_php::{Parser, PhpLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#" "#); let result = parser.parse(&source); println!("Function parsed successfully."); ``` -------------------------------- ### Rust: Basic Coq Theorem Parsing Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-coq/readme.md Demonstrates the basic usage of the Oak Coq Parser to parse a simple Coq theorem. It initializes the parser, creates source text from a string, and calls the parse method. This example requires the 'oak_coq' crate. ```rust use oak_coq::{Parser, CoqLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"Theorem plus_comm : forall n m : nat, n + m = m + n. Proof. intros n m. induction n as [| n' IHn']. - simpl. reflexivity. - simpl. rewrite IHn'. reflexivity. Qed. "#); let result = parser.parse(&source); println!("Parsed Coq theorem successfully."); Ok(()) } ``` -------------------------------- ### Python Fibonacci Function Example Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-markdown/tests/lexer/basic.markdown Provides a recursive Python function to calculate Fibonacci numbers. This snippet is for testing Python code block rendering. ```python def fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2) ``` -------------------------------- ### Parse Complex Nginx Configuration with Oak Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-nginx/readme.md Demonstrates parsing a complex Nginx configuration string using the oak parser and NginxLanguage. It shows how to initialize the parser and language, handle successful parsing by printing a message, and report errors with line numbers and messages. ```rust use oak::Parser; use oak_nginx::NginxLanguage; fn main() { let complex_config = r#" user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; use epoll; multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; gzip on; gzip_vary on; gzip_min_length 1000; gzip_types text/plain text/css application/json application/javascript; upstream backend { server 127.0.0.1:8080 weight=3; server 127.0.0.1:8081 weight=2; server 127.0.0.1:8082 weight=1; keepalive 32; } server { listen 80; server_name api.example.com; location / { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } } } "#; let mut parser = Parser::new(); let language = NginxLanguage::new(); match parser.parse(&complex_config, &language) { Ok(ast) => { println!("Successfully parsed complex Nginx configuration!"); // Process the AST for configuration validation or transformation } Err(error) => { eprintln!("Parse error at line {}: {}", error.line(), error.message()); } } } ``` -------------------------------- ### Basic WAT Parsing in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-wat/readme.md Demonstrates the fundamental usage of the Oak WAT parser to parse a simple WebAssembly module. It initializes the parser, defines the source WAT text, and performs the parsing operation. This example requires the 'oak-wat' crate. ```rust use oak_wat::{Parser, WatLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"( module (func $add (param $a i32) (param $b i32) (result i32)) local.get $a local.get $b i32.add ) (export "add" (func $add)) )"#); let result = parser.parse(&source); println!("Parsed WAT successfully."); Ok(()) } ``` -------------------------------- ### Parsing Java Classes with Oak Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-java/readme.md Illustrates parsing a Java class definition, including fields and constructor. This example parses a 'Person' class with name and age attributes. ```rust use oak_java::{Parser, JavaLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#"\npublic class Person {\n private String name;\n private int age;\n \n public Person(String name, int age) {\n this.name = name;\n this.age = age;\n }\n \n public String getName() {\n return name;\n }\n \n public int getAge() {\n return age;\n }\n}\n"#); let result = parser.parse(&source); println!("Class parsed successfully."); ``` -------------------------------- ### JavaScript Code Highlighting with Dracula Theme Source: https://github.com/ygg-lang/oaks/blob/master/projects/oak-highlight/readme.md Demonstrates highlighting JavaScript code using the Oak highlighter with the Dracula theme. This example showcases a JavaScript class definition for an API client. ```rust use oak_highlight::{Highlighter, Theme}; let highlighter = Highlighter::new(); let js_code = r###"class ApiClient { constructor(baseURL) { this.baseURL = baseURL; this.headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' }; } async get(endpoint) { const response = await fetch(`${this.baseURL}${endpoint}`, { method: 'GET', headers: this.headers }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return await response.json(); } async post(endpoint, data) { return fetch(`${this.baseURL}${endpoint}`, { method: 'POST', headers: this.headers, body: JSON.stringify(data) }); } }"###; let highlighted = highlighter.highlight(js_code, "javascript", Theme::Dracula)?; println!("Highlighted JavaScript code:\n{}", highlighted); ``` -------------------------------- ### Parsing Zig Functions with Oak Zig Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-zig/readme.md Illustrates how to parse Zig functions using the Oak Zig parser. This example shows parsing a function definition and its usage within another function. It highlights the parser's capability to understand function syntax and structure. ```rust use oak_zig::{Parser, ZigLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r###" pub fn add(a: i32, b: i32) i32 { return a + b; } pub fn main() void { const result = add(5, 3); std.debug.print("Result: {}\n", .{result}); } "###); let result = parser.parse(&source); println!("Function parsed successfully."); ``` -------------------------------- ### Error Handling in Parsing - Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-typescript/readme.md Illustrates how to handle parsing errors in TypeScript code. This example shows how to check the result of a parse operation for errors and print diagnostic information. ```rust use oak_typescript::{Parser, TypeScriptLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#"\ninterface User {\n name: string\n age: number;\n}\n"#); let result = parser.parse(&source); if let Err(e) = result.result { println!("Parse error: {:?}", e); } ``` -------------------------------- ### Token-Level Parsing - Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-typescript/readme.md Shows how to perform token-level parsing of TypeScript code. This example demonstrates obtaining token information from the parse result, useful for detailed code analysis. ```rust use oak_typescript::{Parser, TypeScriptLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("const x: number = 42;"); let result = parser.parse(&source); // Token information is available in the parse result ``` -------------------------------- ### Parsing a Rust Struct with Oak Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-rust/readme.md Illustrates parsing a Rust struct definition using the Oak Rust parser. This example focuses on parsing struct fields and their types. ```rust use oak_rust::{Parser, RustLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new(r#" struct Point { x: f64, y: f64, } "#); let result = parser.parse(&source); println!("Parsed Rust struct successfully."); ``` -------------------------------- ### Basic Swift Parsing with Oak Swift Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-swift/readme.md Demonstrates the basic usage of the Oak Swift parser to parse a simple Swift code snippet. It initializes the parser, defines source text, and performs the parsing operation. This is a foundational example for understanding the parser's core functionality. ```rust use oak_swift::{Parser, SwiftLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#"\nfunc hello() {\n print(\"Hello, World!\")\n}\n\nhello()\n "#); let result = parser.parse(&source); println!(\"Parsed Swift successfully."); Ok(()) } ``` -------------------------------- ### Token-Level Parsing in Kotlin with Oak Kotlin Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-kotlin/readme.md Demonstrates token-level parsing of Kotlin code using the Oak Kotlin parser. This example parses a simple variable assignment statement. ```rust use oak_kotlin::{Parser, KotlinLanguage, SourceText}; let parser = Parser::new(); let source = SourceText::new("val x = 42"); let result = parser.parse(&source); println!("Token parsing completed."); ``` -------------------------------- ### Basic C Program Parsing with Oak C Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-c/readme.md Demonstrates the basic usage of the Oak C parser to parse a simple C program. It initializes the parser, defines source text, and performs the parsing operation. No external dependencies are required beyond the `oak_c` crate. ```rust use oak_c::{Parser, CLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#" #include int main() { printf("Hello, World!\n"); return 0; } "#); let result = parser.parse(&source); println!("Parsed C program successfully."); Ok(()) } ``` -------------------------------- ### Batch Process Files for Highlighting in Rust Source: https://github.com/ygg-lang/oaks/blob/master/projects/oak-highlight/readme.md Illustrates how to efficiently highlight multiple code files simultaneously using the BatchProcessor in Oak Highlight. This is useful for processing entire projects or directories. ```rust use oak_highlight::{Highlighter, BatchProcessor}; use std::collections::HashMap; let highlighter = Highlighter::new(); let mut processor = BatchProcessor::new(highlighter); let mut files = HashMap::new(); files.insert("main.rs", "fn main() { println!(\"Hello\"); }"); files.insert("script.py", "print('Hello from Python')"); files.insert("app.js", "console.log('Hello from JavaScript');"); let results = processor.highlight_batch(files, Theme::VSCode)?; for (filename, highlighted) in results { println!("Highlighted {}:\n{}", filename, highlighted); } ``` -------------------------------- ### Parse a Basic Bash Script in Rust Source: https://github.com/ygg-lang/oaks/blob/master/examples/oak-bash/readme.md Demonstrates the basic usage of the Oak Bash Parser in Rust. It initializes the parser, defines source text for a Bash script, and then parses it. This example shows the fundamental steps for script analysis. ```rust use oak_bash::{Parser, BashLanguage, SourceText}; fn main() -> Result<(), Box> { let parser = Parser::new(); let source = SourceText::new(r#" #!/bin/bash NAME="World" echo "Hello, $NAME!" if [ "$NAME" == "World" ]; then echo "It's a small world." fi "#); let result = parser.parse(&source); println!("Parsed Bash script successfully."); Ok(()) } ```