open-index/open-npm huggingface dataset:
npm package: @rcs-lang/ast
Description: Parser-independent AST type definitions for RCL language
Latest version: 2.0.1

# @rcs-lang/ast

Parser-independent AST (Abstract Syntax Tree) type definitions for the RCL (Rich Communication Language).

## Overview

This package provides TypeScript type definitions for the RCL Abstract Syntax Tree. It serves as a shared contract between the parser and compiler packages, ensuring type safety and consistency across the RCL toolchain.

## Installation

```bash
npm install @rcs-lang/ast
```

## Usage

```typescript
import * as AST from '@rcs-lang/ast';

// Example: Type-safe AST node creation
const agentNode: AST.AgentDefinition = {
  type: 'AgentDefinition',
  name: 'MyAgent',
  displayName: 'My Agent',
  sections: []
};

// Example: AST traversal with type guards
function visitNode(node: AST.ASTNode) {
  if (AST.isAgentDefinition(node)) {
    console.log('Found agent:', node.name);
  } else if (AST.isFlowDefinition(node)) {
    console.log('Found flow:', node.name);
  }
}
```

## AST Structure

The RCL AST follows a hierarchical structure:

```
RclFile
├── AgentDefinition
│   ├── ConfigSection
│   ├── DefaultsSection
│   └── FlowDefinition[]
└── MessagesSection
    └── MessageDefinition[]
```

## Key Types

### Core Nodes
- `RclFile` - Root node of an RCL document
- `AgentDefinition` - Defines an RCS agent
- `FlowDefinition` - Defines a conversation flow
- `MessagesSection` - Container for message definitions
- `MessageDefinition` - Defines a message template

### Flow Nodes
- `StateDefinition` - Defines a state in a flow
- `TransitionDefinition` - Defines transitions between states
- `MatchBlock` - Pattern matching for user input
- `ActionBlock` - Actions to perform in a state

### Message Nodes
- `TextMessage` - Simple text message
- `RichCardMessage` - Rich card with media and buttons
- `CarouselMessage` - Carousel of multiple cards
- `Suggestion` - Quick reply or action suggestions

## Type Guards

The package provides type guard functions for runtime type checking:

```typescript
AST.isAgentDefinition(node)
AST.isFlowDefinition(node)
AST.isMessageDefinition(node)
AST.isTextMessage(node)
// ... and more
```

## Contributing

See the main repository README for contribution guidelines.

## License

MIT
npm package: @rcs-lang/parser
Description: ANTLR grammar for RCL
Latest version: 2.0.1

# ANTLR Parser for RCL

This package contains the ANTLR4 grammar and parser for the RCL language.

## Building

The ANTLR parser requires Java to generate the TypeScript parser from the grammar files.

### Prerequisites

- Java 17 or later must be installed
- Run `./install-java.sh` for installation instructions

### Build Process

```bash
# Install dependencies
bun install

# Generate parser and build TypeScript
bun run build
```

This will:
1. Generate TypeScript parser files from the ANTLR grammar
2. Fix import paths in the generated files
3. Compile TypeScript to JavaScript

## Development

### Grammar Files

- `src/RclLexer.g4` - Lexer grammar (tokenization rules)
- `src/RclParser.g4` - Parser grammar (syntax rules)
- `src/RclLexerBase.ts` - Base class for lexer with Python-like indentation support

### Generated Files

The `src/generated/` directory contains the generated parser files. These are created by ANTLR and should not be edited manually.

## Using Pre-built Parser

If you cannot install Java, you can:

1. Ask someone with Java to run `bun run build` and commit the generated files
2. Use the pre-built parser from a CI/CD system
3. Use a Docker container with Java pre-installed

## Testing

```bash
bun test
```

Tests include:
- Grammar validation
- Parser functionality
- Context variable support