Skip to content

Latest commit

 

History

History
388 lines (312 loc) · 10.3 KB

PARSER_ROADMAP.md

File metadata and controls

388 lines (312 loc) · 10.3 KB

Arc Parser Implementation Roadmap v2.0

Updated to reflect current implementation state and Arc language specification v0.3.0.

✅ Currently Implemented (Parser Working)

Core Language Foundation

  • Lexer: Complete token support for all Arc keywords and operators
  • Function declarations: func name(params) -> Type { body }
  • Variable declarations: let, mut, const with type inference
  • Module system: mod and use declarations with :: scope resolution
  • All operators: Arithmetic, comparison, logical, bitwise, assignment
  • Special Arc operators: Pipeline (|>, ~>, <|), null coalescing (??), force unwrap (!!), spaceship (<=>)
  • Control flow: if/elif/else, while, for, match, defer
  • Basic expressions: Literals, identifiers, function calls, field access, array indexing
  • Semicolon-less syntax: Statement termination via newlines/braces
  • Error handling: Comprehensive error reporting and recovery
  • Memory management: Arena allocator for AST nodes

Expression System

  • Precedence climbing: Full operator precedence with all Arc operators
  • Binary/unary operators: Complete mapping from tokens to AST
  • Function calls: func(args) with argument parsing
  • Field access: obj.field syntax
  • Array indexing: array[index] syntax
  • Scope resolution: module::item syntax

Infrastructure

  • AST node types: Comprehensive node definitions for all language features
  • Source tracking: Enhanced source location and diagnostic info
  • Test framework: Basic lexer tests updated for new tokens

❌ Missing Implementation (High Priority)

1. Type System Declarations

Status: AST nodes defined, parsing functions missing

Struct Definitions

type Point = struct {
    x: f32
    y: f32
    
    func distance(self) -> f32 => sqrt(self.x² + self.y²)
}

Needs: parse_struct_declaration(), struct field parsing, method parsing

Enum Definitions

type Result<T, E> = enum {
    ok(T)
    err(E)
}

type Message = enum {
    Text(str)
    Image { url: str, width: i32, height: i32 }
}

Needs: parse_enum_declaration(), variant parsing, associated data

Type Aliases

type UserId = u64
type Handler = func(Event) -> Response

Needs: parse_type_alias_declaration()

Interface & Implementation

interface Display {
    func show(self) -> str
}

impl Display for Point {
    func show(self) -> str => format!("({}, {})", self.x, self.y)
}

Needs: parse_interface_declaration(), parse_impl_declaration()

2. Advanced Expressions

Status: AST nodes defined, parsing missing

Array Literals

let numbers = [1, 2, 3, 4, 5]
let matrix = [[1,0,0], [0,1,0], [0,0,1]]

Needs: parse_array_literal()

Struct Literals

let point = Point{x: 1.0, y: 2.0}
let person = Person{name: "Alice", age, email: none}

Needs: parse_struct_literal()

Lambda Expressions

let add = |a, b| => a + b
let processor = |data| {
    validate(data)
    return transform(data)
}

Needs: parse_lambda_expression()

Range Expressions

for i in 0..10 { }
for item in items[1..5] { }

Needs: parse_range_expression()

3. Pattern Matching & Destructuring

Status: Not implemented

Destructuring Assignments

let (x, y) = get_coordinates()
let Point{x, y} = point
let [first, ..rest] = array

Needs: Pattern parsing system, destructuring in variable declarations

Advanced Match Patterns

match value {
    Point{x: 0, y} => handle_y_axis(y)
    Point{x, y} when x > 0 => handle_positive(x, y)
    [first, ..rest] => handle_array(first, rest)
    _ => handle_default()
}

Needs: Complete pattern matching system beyond expressions

4. Memory Management Features

Status: Types defined, parsing missing

Pointer Types

let owned: own<Data> = own.new(data)
let borrowed: ref<Data> = ref.to(owned)
let mutable: mut<Data> = mut.to(owned)

Needs: Pointer type parsing in type system

Array and Slice Types

let fixed: [i32; 10] = [0; 10]
let slice: [i32] = fixed[2..8]
let dynamic: Vec<i32> = vec![1, 2, 3]

Needs: Array type parsing, slice syntax

⚠️ Advanced Features (Medium Priority)

5. Arc's Distinctive Features

Status: Not implemented, Arc-specific

Context System

context Logger {
    level: LogLevel
    output: OutputStream
}

func save_user(user: User) using Logger, Database {
    logger.info("Saving user: {}", user.name)
    database.save(user)
}

with Logger(level: .Info, output: stdout) {
    save_user(user)
}

Needs: Context parsing, using clauses, with blocks

Phantom Resources

phantom type FileDescriptor
phantom type DatabaseConnection

func open_file(path: str) -> grant<FileDescriptor> { }
func close_file(fd: revoke<FileDescriptor>) { }

Needs: Phantom type parsing, grant/revoke system

6. Error Handling & Resource Management

Status: Basic defer implemented, advanced features missing

Try/Catch System

func divide(a: f64, b: f64) -> Result<f64, MathError> {
    guard b != 0.0 else throw MathError.DivisionByZero
    return ok(a / b)
}

let result = try divide(10.0, 2.0)
let value = divide(10.0, 2.0)?  // Error propagation

Needs: try, catch, throw, ? operator, guard statements

Advanced Resource Management

func process_file(path: str) -> Result<void, Error> {
    let file = try open_file(path)
    defer file.close()  // ✅ Already implemented
    
    let buffer = try allocate(1024)
    defer deallocate(buffer)
    
    return process_data(file, buffer)
}

Needs: Resource tracking, automatic cleanup

7. Async Programming

Status: Tokens exist, parsing not implemented

Async Functions & Pipeline

async func fetch_data(url: str) -> Result<Data, Error> {
    let response = try http_get(url).await
    return ok(parse_data(response))
}

let result = data
    |> validate(_)
    ~> process_async(_)  
    ~> send_async(_)
    await

Needs: async/await parsing, async pipeline operators

8. Attribute System

Status: Not implemented

Attributes

@@inline
func fast_function() { }

@@derive(Debug, Clone, PartialEq)
type Point = struct { x: f32, y: f32 }

@@test
func test_addition() {
    assert_eq!(add(2, 3), 5)
}

Needs: @@ attribute parsing, attribute application

🔮 Future Features (Low Priority)

9. Compile-time Programming

comptime {
    const SIZE = 1024
    static_assert(SIZE > 0, "Size must be positive")
}

func generic_function<T: Constraint>(value: T) -> T {
    return value
}

Needs: comptime blocks, static assertions, generics

10. Advanced Type System

// Type-level programming
type If<C, T, F> = comptime {
    if C then T else F
}

// Higher-kinded types
type Functor<F<_>> = interface {
    func map<A, B>(fa: F<A>, f: func(A) -> B) -> F<B>
}

Needs: Advanced type system features

11. Macro System

macro define_getter($field: ident, $type: type) {
    func get_$field(self) -> $type {
        return self.$field
    }
}

define_getter!(name, str)  // Expands to get_name() method

Needs: Macro definition and expansion system

🎯 Implementation Roadmap

Phase 1: Complete Core Language (Next 2-4 weeks)

Goal: Make Arc parser capable of parsing real programs

  1. Type declarations (struct, enum, type, interface, impl)

    • These are fundamental for any serious program
    • AST nodes already defined, need parsing functions
    • Should be straightforward to implement
  2. Expression literals (arrays, structs, lambdas, ranges)

    • Essential for data manipulation
    • Required for practical programming
  3. Pattern matching and destructuring

    • Core feature that makes Arc distinctive
    • Required for ergonomic data handling

Phase 2: Arc's Distinctive Features (1-2 months)

Goal: Implement what makes Arc unique

  1. Context system (context, using, with)

    • Arc's killer feature for dependency injection
    • Unique value proposition
  2. Advanced error handling (try, catch, throw, ?, guard)

    • Modern error handling approaches
    • Critical for system programming
  3. Phantom resources and memory safety

    • phantom types, grant/revoke
    • Advanced safety guarantees

Phase 3: Production Features (2-3 months)

Goal: Make Arc production-ready

  1. Async programming (async/await, async pipelines)

    • Essential for modern system programming
    • Performance-critical feature
  2. Attribute system (@@derive, @@inline, @@test)

    • Metaprogramming foundation
    • Developer experience enhancement
  3. Advanced type features (generics, constraints)

    • Type safety and reusability
    • Performance optimizations

Phase 4: Advanced Features (Future)

Goal: Research and experimental features

  1. Compile-time programming (comptime, type-level programming)
  2. Macro system (code generation)
  3. Advanced memory management (custom allocators)

🧪 Ready for Semantic Analysis?

YES! The parser is now ready for the next phase:

Current Parser Capabilities

  • ✅ Complete lexical analysis with all Arc tokens
  • ✅ Full expression parsing with correct precedence
  • ✅ Basic declarations (functions, variables, modules)
  • ✅ Control flow (if/elif/else, loops, match, defer)
  • ✅ Error recovery and comprehensive diagnostics
  • ✅ Semicolon-less syntax with proper statement termination

Ready for LLVM Pipeline

The current parser produces a complete AST that can be consumed by:

  1. Semantic Analyzer

    • Type checking
    • Symbol resolution
    • Borrow checking
    • Context validation
  2. LLVM IR Generation

    • Code generation for basic language features
    • Optimization passes
    • Target-specific code generation
  3. Incremental Feature Addition

    • Advanced features can be added to the parser
    • Semantic analysis can be extended accordingly
    • No architectural changes needed

Next Steps

  1. Implement semantic analysis for current features
  2. Set up LLVM backend for code generation
  3. Add advanced parser features incrementally
  4. Optimize and tune the complete pipeline

The parser foundation is solid and production-ready for the core Arc language! 🚀