Skip to main content

Crate oak_actionscript

Crate oak_actionscript 

Source
Expand description

ยง๐Ÿ› ๏ธ ActionScript Parser Developer Guide

This guide is designed to help you quickly get started with developing and integrating oak-actionscript.

ยง๐Ÿšฆ Quick Start

ยงBasic Parsing Example

The following is a standard workflow for parsing an ActionScript class featuring metadata and E4X:

use oak_actionscript::{Parser, SourceText};

fn main() {
    // 1. Prepare source code
    let code = r#"
        package com.example {
            [Bindable]
            public class User {
                public var name:String;
                
                public function toXML():XML {
                    return <user name={name}/>;
                }
            }
        }
    "#;
    let source = SourceText::new(code);

    // 2. Initialize parser
    let parser = Parser::new();

    // 3. Execute parsing
    let result = parser.parse(&source);

    // 4. Handle results
    if result.is_success() {
        println!("Parsing successful! AST node count: {}", result.node_count());
    } else {
        eprintln!("Errors found during parsing.");
    }
}

ยง๐Ÿ” Core API Usage

ยง1. Syntax Tree Traversal

After a successful parse, you can use the built-in visitor pattern or manually traverse the Green/Red Tree to extract ActionScript-specific constructs like metadata tags ([Bindable]), E4X XML literals, or complex package/class hierarchies.

ยง2. Incremental Parsing

No need to re-parse the entire source file when small changes occur:

// Assuming you have an old parse result 'old_result' and new source text 'new_source'
let new_result = parser.reparse(&new_source, &old_result);

ยง3. Diagnostics

oak-actionscript provides rich error contexts specifically tailored for AS3 developers, handling legacy Flex/Flash syntax quirks:

for diag in result.diagnostics() {
    println!("[{}:{}] {}", diag.line, diag.column, diag.message);
}

ยง๐Ÿ—๏ธ Architecture Overview

  • Lexer: Tokenizes ActionScript source text into a stream of tokens, including support for metadata brackets and E4X XML tokens.
  • Parser: Syntax analyzer based on the Pratt parsing algorithm to handle complex AS3 expression precedence and E4X syntax integration.
  • AST: A strongly-typed syntax abstraction layer designed for high-performance AS3 analysis tools and migration engines.

ยง๐Ÿ”— Advanced Resources

  • Full Examples: Check the examples/ folder in the project root.
  • API Documentation: Run cargo doc --open for detailed type definitions.
  • Test Cases: See tests/ for handling of various AS3/Flex edge cases. Actionscript support for the Oak language framework.

Re-exportsยง

pub use crate::ast::ActionScriptRoot;
pub use crate::lexer::ActionScriptLexer;
pub use crate::lexer::ActionScriptTokenType;
pub use crate::parser::ActionScriptElementType;
pub use crate::parser::ActionScriptParser;
pub use crate::lsp::formatter::ActionScriptFormatter;
pub use crate::lsp::highlighter::ActionScriptHighlighter;
pub use crate::lsp::ActionScriptLanguageService;
pub use crate::mcp::serve_actionscript_mcp;

Modulesยง

ast
ActionScript AST (Abstract Syntax Tree)
lexer
ActionScript Lexer
lsp
ActionScript Language Support (LSP)
mcp
ActionScript MCP Server
parser

Structsยง

ActionScriptBuilder
ActionScript ่ฏญ่จ€็š„ AST ๆž„ๅปบๅ™จ
ActionScriptLanguage
ActionScript ่ฏญ่จ€้…็ฝฎๅ’Œๅ…ƒๆ•ฐๆฎใ€‚