Expand description
Legalis-DSL: Domain Specific Language for legal document parsing.
This crate provides parsing and AST representation for legal documents, enabling structured representation of statutes and legal rules.
§Grammar
STATUTE ::= "STATUTE" ID ":" TITLE "{" BODY "}"
BODY ::= (METADATA | DEFAULT | WHEN | THEN | DISCRETION | EXCEPTION | AMENDMENT | SUPERSEDES)*
METADATA ::= EFFECTIVE_DATE | EXPIRY_DATE | JURISDICTION | VERSION
EFFECTIVE_DATE ::= ("EFFECTIVE_DATE" | "EFFECTIVE") DATE
EXPIRY_DATE ::= ("EXPIRY_DATE" | "EXPIRY" | "EXPIRES") DATE
JURISDICTION ::= "JURISDICTION" (STRING | IDENT)
VERSION ::= "VERSION" NUMBER
DATE ::= YYYY "-" MM "-" DD | STRING
DEFAULT ::= "DEFAULT" IDENT ("=" | ":") VALUE
WHEN ::= "WHEN" CONDITION
CONDITION ::= OR_EXPR
OR_EXPR ::= AND_EXPR ("OR" AND_EXPR)*
AND_EXPR ::= UNARY_EXPR ("AND" UNARY_EXPR)*
UNARY_EXPR ::= "NOT" UNARY_EXPR | "(" CONDITION ")" | PRIMARY_COND
PRIMARY_COND ::= FIELD_COND | "HAS" IDENT | IDENT
FIELD_COND ::= FIELD (COMPARISON_OP VALUE | "BETWEEN" VALUE "AND" VALUE | "IN" VALUE_LIST | "LIKE" PATTERN)
FIELD ::= "AGE" | "INCOME" | IDENT
VALUE_LIST ::= "(" VALUE ("," VALUE)* ")" | VALUE ("," VALUE)*
THEN ::= "THEN" EFFECT
EFFECT ::= ("GRANT" | "REVOKE" | "OBLIGATION" | "PROHIBITION") STRING
DISCRETION ::= "DISCRETION" STRING
EXCEPTION ::= "EXCEPTION" ["WHEN" CONDITION] STRING
AMENDMENT ::= "AMENDMENT" IDENT ["VERSION" NUMBER] ["EFFECTIVE_DATE" DATE] STRING
SUPERSEDES ::= "SUPERSEDES" IDENT ("," IDENT)*§Comments
The DSL supports both line comments (//) and block comments (/* */).
§Example
STATUTE adult-voting: "Adult Voting Rights" {
JURISDICTION "US-CA"
VERSION 2
EFFECTIVE_DATE 2024-01-01
EXPIRY_DATE 2030-12-31
DEFAULT status "pending"
WHEN AGE BETWEEN 18 AND 120 AND HAS citizen
THEN GRANT "Right to vote"
EXCEPTION WHEN AGE < 18 AND HAS guardian_consent "Minors with parental consent"
DISCRETION "Consider residency requirements"
}§Advanced Features
The DSL supports advanced condition operators:
BETWEEN: Range checking (e.g.,AGE BETWEEN 18 AND 65)IN: Set membership (e.g.,AGE IN (18, 21, 25))LIKE: Pattern matching (e.g.,INCOME LIKE "consulting%")DEFAULT: Default values for attributes (e.g.,DEFAULT status "pending")EXCEPTION: Exception clauses (e.g.,EXCEPTION WHEN condition "description")AMENDMENT: Version tracking (e.g.,AMENDMENT old-law VERSION 2 "Updated rules")SUPERSEDES: Replacing old statutes (e.g.,SUPERSEDES old-law, legacy-law)
Re-exports§
pub use autofix::AutoFixer;pub use autofix::Fix;pub use autofix::FixCategory;pub use autofix::FixPattern;pub use autofix::FixReport;pub use cache::CacheKey;pub use cache::CacheStats;pub use cache::CachingParser;pub use cache::ParseCache;pub use codegen::CSharpGenerator;pub use codegen::CodeGenerator;pub use codegen::GoGenerator;pub use codegen::JavaGenerator;pub use codegen::PrologGenerator;pub use codegen::PythonGenerator;pub use codegen::RustGenerator;pub use codegen::SqlGenerator;pub use codegen::TypeScriptGenerator;pub use completion::CompletionCategory;pub use completion::CompletionContext;pub use completion::CompletionItem;pub use completion::CompletionProvider;pub use compliance::ComplianceMatrix;pub use compliance::ComplianceStats;pub use consistency::ConsistencyChecker;pub use consistency::ConsistencyIssue;pub use dataflow::DataFlowAnalyzer;pub use dataflow::DataFlowIssue;pub use dataflow::DataFlowState;pub use diff::Change;pub use diff::DocumentDiff;pub use diff::StatuteDiff;pub use docgen::DocGenerator;pub use docgen::LaTeXGenerator;pub use docgen::MarkdownGenerator;pub use error_explainer::ErrorExplainer;pub use error_explainer::ErrorExplanation;pub use error_explainer::ErrorSeverity;pub use grammar_doc::GrammarRule;pub use grammar_doc::GrammarSpec;pub use grammar_doc::legalis_grammar;pub use graph::DependencyGraph;pub use graph::GraphFormat;pub use graph::GraphOptions;pub use graph::generate_dot_graph;pub use graph::generate_mermaid_graph;pub use heredoc::HeredocError;pub use heredoc::HeredocParser;pub use heredoc::HeredocResult;pub use heredoc::HeredocType;pub use heredoc::parse_heredoc;pub use htmlgen::HtmlGenerator;pub use htmlgen::HtmlTheme;pub use import_resolver::ImportResolver;pub use import_resolver::detect_circular_imports;pub use import_resolver::validate_import_paths;pub use incremental::IncrementalParser;pub use incremental::TextEdit;pub use interpolation::InterpolationError;pub use interpolation::InterpolationEvaluator;pub use interpolation::InterpolationParser;pub use interpolation::Token as InterpolationToken;pub use interpolation::extract_variables;pub use interpolation::interpolate;pub use metadata::AmendmentAuditTrail;pub use metadata::AuditEntry;pub use metadata::EntityRelationships;pub use metadata::JurisdictionHierarchy;pub use metadata::VersionEntry;pub use metadata::VersionHistory;pub use module_system::ExportNode;pub use module_system::ImportKind;pub use module_system::NamespaceNode;pub use module_system::Visibility;pub use multilang::DslLanguage;pub use multilang::KeywordMapping;pub use multilang::LanguageExamples;pub use multilang::MultiLangTranslator;pub use mutation::Mutation;pub use mutation::MutationOperator;pub use mutation::MutationReport;pub use mutation::MutationResult;pub use mutation::MutationType;pub use nl_to_dsl::CommonTemplates;pub use nl_to_dsl::NLPattern;pub use nl_to_dsl::NLTranslator;pub use nl_to_dsl::TranslationResult;pub use nl_to_dsl::TranslatorBuilder;pub use nlgen::Language;pub use nlgen::NLConfig;pub use nlgen::NLGenerator;pub use nlgen::Verbosity;pub use numeric::NumericError;pub use numeric::NumericParser;pub use numeric::NumericValue;pub use numeric::parse_numeric;pub use profiler::ParseProfiler;pub use profiler::ProfileComparison;pub use profiler::ProfileReport;pub use profiler::Profiler;pub use query::ConditionSearch;pub use query::StatuteQuery;pub use search_index::IndexStats;pub use search_index::SearchIndex;pub use search_index::SearchResult;pub use search_index::StatuteMetadata;pub use statistics::ComplexityMetrics;pub use statistics::DependencyAnalysis;pub use statistics::DocumentStatistics;pub use statistics::analyze_complexity;pub use taint::TaintAnalyzer;pub use taint::TaintCategory;pub use taint::TaintConfig;pub use taint::TaintInfo;pub use taint::TaintReport;pub use templates::StatuteTemplate;pub use templates::TemplateBuilder;pub use templates::TemplateLibrary;pub use transform::ConditionTransform;pub use transform::DeduplicateStatutes;pub use transform::DocumentTransform;pub use transform::NormalizeIds;pub use transform::RemoveEmptyStatutes;pub use transform::SimplifyConditions;pub use transform::SortByDependencies;pub use transform::StatuteTransform;pub use transform::TransformPipeline;pub use tree_view::TreeFormatter;pub use type_checker::Type;pub use type_checker::TypeChecker;pub use type_checker::TypeContext;pub use type_checker::TypeError;pub use validation::CompletenessChecker;pub use validation::SemanticValidator;pub use validation::ValidationContext;pub use validation::ValidationError;pub use watch::FileWatcher;pub use watch::ValidationResult;pub use watch::WatchConfig;
Modules§
- autofix
- Auto-fix suggestions for common DSL errors and anti-patterns
- cache
- Parse result caching for the Legalis DSL.
- codegen
- Code generation framework for translating legal statutes to other languages.
- completion
- Completion suggestions for Legalis DSL
- compliance
- Compliance matrix generation for regulatory analysis.
- consistency
- Consistency checking across related statutes.
- dataflow
- Data flow analysis for statute dependencies.
- diff
- Statute comparison and diff utilities.
- docgen
- Documentation generation from legal document AST.
- error_
explainer - Semantic Error Explainer for Legalis DSL
- error_
recovery - Error recovery mechanisms for robust parsing (v0.1.6).
- grammar_
doc - Grammar documentation generator for the Legalis DSL.
- graph
- Graph generation for statute dependencies and relationships.
- heredoc
- Heredoc (Here Document) syntax support for multi-line strings.
- htmlgen
- HTML documentation generator for legal documents.
- import_
resolver - Import path resolution and validation.
- incremental
- Incremental parsing support for the Legalis DSL.
- interpolation
- String interpolation support for effect descriptions and other text fields.
- lsp
- Language Server Protocol (LSP) implementation for Legalis DSL.
- macros
- Macro system for Legalis DSL (v0.1.5).
- metadata
- Metadata extraction utilities for legal documents.
- module_
system - Module system support for Legalis DSL (v0.1.4).
- multilang
- Multi-Language DSL Support
- mutation
- Mutation Testing Framework for Legalis DSL
- nl_
to_ dsl - Natural Language to DSL Translation
- nlgen
- Natural Language Generator for Legal DSL
- numeric
- Numeric literal parsing with support for various formats.
- optimizer
- AST optimization passes for Legalis DSL (v0.1.8).
- profiler
- Performance profiling utilities for parsing and analysis.
- query
- Query API for filtering and searching legal documents.
- search_
index - Search index generation for legal documents.
- statistics
- Statistics and metrics for legal document analysis.
- taint
- Taint analysis for tracking security-sensitive attributes in legal documents.
- templates
- Statute template system for parameterized statute generation.
- transform
- AST transformation pipeline for composable statute transformations.
- tree_
view - Tree-view formatter for visualizing statute structure.
- type_
checker - Type inference and checking for condition values.
- validation
- Semantic validation for Legal DSL documents.
- watch
- Watch mode for continuous validation of legal documents.
Structs§
- Amendment
Node - AST node for an amendment clause.
- Constraint
Node - AST node for a constraint clause.
- Default
Node - AST node for default value declarations.
- Delegate
Node - AST node for a delegate clause.
- DslPrinter
- Pretty-printer for Legal DSL.
- Effect
Node - AST node for effects.
- Exception
Node - AST node for an exception clause.
- Import
Node - AST node for an import declaration.
- Legal
Document - AST node for a complete legal document.
- Legal
DslParser - A simple DSL parser for legal rules.
- Parse
Result - A partial parse result that contains both parsed content and errors. This is used for error recovery, allowing the parser to continue parsing and collect multiple errors instead of failing at the first one.
- Printer
Config - Configuration for the pretty-printer.
- Scope
Node - AST node for a scope clause.
- Source
Location - Source location for error reporting.
- Source
Span - Source span representing a range in the source code. Useful for IDE integration and error highlighting.
- Spanned
Token - Token with source location information.
- Statute
Node - AST node for a statute definition.
Enums§
- Condition
Node - AST node for conditions.
- Condition
Value - Values that can appear in conditions.
- DslError
- Errors that can occur during DSL parsing.
- DslWarning
- Warnings that can be emitted during DSL parsing.
- SetExpression
- Set expressions for set operations.
- Statute
Change - Represents a specific change in a statute.
- Temporal
Field - Temporal field types for date/time conditions
- Token
- Token types for the legal DSL lexer.
Traits§
- AstVisitor
- Visitor pattern for traversing AST nodes.
- ToCore
- Trait for converting AST nodes to core types.
Functions§
- format_
document - Formats a LegalDocument AST back to DSL string.
- format_
statute - Formats a statute to DSL string using default configuration.
- format_
statutes - Formats multiple statutes to DSL string using default configuration.
- from_
json - Deserializes a LegalDocument AST from JSON string.
- from_
toml - Deserializes a LegalDocument AST from TOML string.
- from_
yaml - Deserializes a LegalDocument AST from YAML string.
- statute_
from_ json - Deserializes a StatuteNode AST from JSON string.
- statute_
from_ toml - Deserializes a StatuteNode AST from TOML string.
- statute_
from_ yaml - Deserializes a StatuteNode AST from YAML string.
- statute_
to_ json - Serializes a StatuteNode AST to JSON string.
- statute_
to_ toml - Serializes a StatuteNode AST to TOML string.
- statute_
to_ yaml - Serializes a StatuteNode AST to YAML string.
- suggest_
keyword - Finds the closest match from a list of valid keywords. Returns None if no close match is found.
- to_json
- Serializes a LegalDocument AST to JSON string.
- to_toml
- Serializes a LegalDocument AST to TOML string.
- to_yaml
- Serializes a LegalDocument AST to YAML string.
Type Aliases§
- DslResult
- Result type for DSL operations.