DragonFire Developer Portal

Dragon Code Parser

Alpha

The Dragon Code Parser processes semantic commands with port-specific handlers, enabling natural language-like interface to the DragonFire system while maintaining machine efficiency.

Dragon Code Parser Architecture
Figure 1: Dragon Code Parser architecture with port-specific handlers

Overview

Dragon Code is a semantic command language designed to provide an intuitive yet powerful interface to the DragonFire system. Its parser translates natural language-like commands into structured operations that are routed to the appropriate port-specific handlers for execution.

Key Features

  • Semantic Commands: Natural language-inspired syntax that follows human thought patterns
  • Port-Based Routing: Automatic routing to geometric port handlers based on operation intent
  • Chainable Operations: Method-chaining syntax for complex operation sequences
  • Type Inference: Smart type detection with contextual parameter handling
  • Port-Specific Semantics: Commands maintain consistent meaning across different contexts

Dragon Code Syntax

Dragon Code follows a command-verb structure with method chaining capabilities:

// Basic syntax:
COMMAND(port).METHOD(parameters).METHOD(parameters)...

// Examples:
GET(210).SELECT("profile").FILTER(lastLogin > "2025-01-01")
CREATE(400).FILE("data.bin").WITH(contents).COMPRESS()
COMPUTE(500).VECTOR([1,2,3]).CROSS([4,5,6])

Command Structure

Component Description Example
Command Primary operation verb GET, CREATE, UPDATE, DELETE, COMPUTE
Port Geometric port number (000-799) 210, 300, 400, 500
Methods Chainable operations on the command SELECT(), FILTER(), FORMAT()
Parameters Arguments to methods Strings, numbers, objects, expressions

Port-Specific Handlers

Each geometric port range has specialized handlers that understand the context and requirements of its domain:

Command Routing

When a Dragon Code command is processed, it follows these steps:

  1. Tokenization: The command is broken into tokens
  2. Parsing: Tokens are converted to a semantic command object
  3. Port Resolution: The command is routed to the appropriate port handler
  4. Validation: The handler validates the command structure and parameters
  5. Execution: The handler processes the command
  6. Response: Results are returned in the requested format

Error Handling

The Dragon Code Parser provides detailed error information when commands cannot be processed:

try {
  const result = await dragonfire.execute(`
    GET(900).FILE("data.txt")
  `);
} catch (error) {
  console.error(error);
  // Output:
  // {
  //   code: "INVALID_PORT",
  //   message: "Port 900 is outside valid range (000-799)",
  //   position: { line: 2, column: 9 },
  //   suggestion: "Use port range 400-499 for file operations"
  // }
}

Chain Operations

Commands can be chained to create complex operation sequences:

// Complex data pipeline example
const result = await dragonfire.execute(`
  GET(210)
    .SELECT("transactions")
    .FILTER(date > "2025-01-01" AND amount > 1000)
    .SORT(date DESC)
    .TRANSFORM(400, item => {
      return {
        id: item.id,
        date: item.date,
        normalizedAmount: item.amount / 100
      };
    })
    .FORMAT("JSON")
`);

// Equivalent to the JavaScript SDK code:
const result = await dragonfire
  .get(210)
  .select("transactions")
  .filter(item => item.date > new Date("2025-01-01") && item.amount > 1000)
  .sort({ field: "date", direction: "desc" })
  .transform(400, item => ({
    id: item.id,
    date: item.date,
    normalizedAmount: item.amount / 100
  }))
  .format("json")
  .execute();

Code Examples

User Data Operations (Port 200-299)

// Get user profile with preferences
const profile = await dragonfire.execute(`
  GET(210)
    .SELECT("profile")
    .INCLUDE(["preferences", "settings"])
    .FORMAT("OBJECT")
`);

// Create a new data record
const newRecord = await dragonfire.execute(`
  CREATE(210)
    .RECORD("contacts")
    .WITH({
      name: "Jane Doe",
      email: "jane@example.com",
      phone: "+1-555-123-4567"
    })
`);

// Update existing data
const updateResult = await dragonfire.execute(`
  UPDATE(210)
    .RECORD("contacts", "id123")
    .SET({ 
      email: "jane.doe@example.com",
      status: "active"
    })
`);

Financial Operations (Port 300-399)

// Check account balance
const balance = await dragonfire.execute(`
  GET(300)
    .BALANCE("accountXYZ")
    .AS("USD")
`);

// Create a purchase transaction
const purchase = await dragonfire.execute(`
  CREATE(300)
    .TRANSACTION("purchase")
    .WITH({
      amount: 129.99,
      currency: "USD",
      items: [
        { id: "item123", quantity: 1, price: 129.99 }
      ],
      paymentMethod: "card456"
    })
`);

AI Knowledge Operations (Port 500-599)

// Perform vector similarity search
const similar = await dragonfire.execute(`
  COMPUTE(500)
    .SIMILARITY(userVector, knowledgeBase)
    .TOP(5)
    .THRESHOLD(0.85)
`);

// Generate text completion
const completion = await dragonfire.execute(`
  GENERATE(500)
    .TEXT()
    .FROM(prompt)
    .MAX_TOKENS(100)
    .TEMPERATURE(0.7)
`);

Advanced Usage Note

While Dragon Code can be used directly as shown in the examples, the DragonFire JavaScript SDK provides native method equivalents that offer the same functionality with the benefits of TypeScript type checking and IDE code completion. Most developers will prefer using the SDK methods, falling back to raw Dragon Code execution for specialized cases.

Next Steps

Continue exploring the DragonFire Semantic Network: