@rcs-lang/ast
v2.0.1
Published
Parser-independent AST type definitions for RCL language
Readme
@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
npm install @rcs-lang/astUsage
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 documentAgentDefinition- Defines an RCS agentFlowDefinition- Defines a conversation flowMessagesSection- Container for message definitionsMessageDefinition- Defines a message template
Flow Nodes
StateDefinition- Defines a state in a flowTransitionDefinition- Defines transitions between statesMatchBlock- Pattern matching for user inputActionBlock- Actions to perform in a state
Message Nodes
TextMessage- Simple text messageRichCardMessage- Rich card with media and buttonsCarouselMessage- Carousel of multiple cardsSuggestion- Quick reply or action suggestions
Type Guards
The package provides type guard functions for runtime type checking:
AST.isAgentDefinition(node)
AST.isFlowDefinition(node)
AST.isMessageDefinition(node)
AST.isTextMessage(node)
// ... and moreContributing
See the main repository README for contribution guidelines.
License
MIT
