Skip to main content

strux_pr 0.1.0 copy "strux_pr: ^0.1.0" to clipboard
strux_pr: ^0.1.0 copied to clipboard

A structural precedence engine for Dart and Flutter. Resolves state ambiguity using compile-time DAG resolution.

example/strux_pr_example.dart

import 'package:strux_pr/strux_pr.dart';

part 'strux_pr_example.g.dart';

@PrecedenceEngine()
class PaymentProcessor implements PrecedenceRuleContainer<String> {
  @Rule(id: 'base_card_payment')
  String processStandardCard() {
    return 'Processed Standard Card Payment';
  }

  @Rule(
    id: 'bounds_check',
    subscope: 'base_card_payment',
  )
  String processLimitViolation() {
    return 'Payment Denied: Exceeds allowed limit';
  }

  @Rule(
    id: 'emergency_system_override',
    overrideTarget: 'bounds_check',
  )
  String processEmergencyHalt() {
    return 'Emergency Stop: All transactions suspended';
  }

  @override
  bool canExecuteRule(String ruleId, String context) {
    if (ruleId == 'emergency_system_override') {
      return context == 'SYSTEM_EMERGENCY';
    }
    if (ruleId == 'bounds_check') {
      return context == 'EXCEEDS_LIMIT';
    }
    return true;
  }
}

void main() {
  final processor = PaymentProcessor();

  // 1. Normal context: Evaluates base_card_payment
  print('Context: NORMAL -> ${processor.dispatchRule("NORMAL")}');
  // Output: Context: NORMAL -> Processed Standard Card Payment

  // 2. Exceeds Limit context: Evaluates bounds_check (subscope takes priority)
  print('Context: EXCEEDS_LIMIT -> ${processor.dispatchRule("EXCEEDS_LIMIT")}');
  // Output: Context: EXCEEDS_LIMIT -> Payment Denied: Exceeds allowed limit

  // 3. Emergency context: Evaluates emergency_system_override (overrideTarget takes priority over bounds_check)
  print(
      'Context: SYSTEM_EMERGENCY -> ${processor.dispatchRule("SYSTEM_EMERGENCY")}');
  // Output: Context: SYSTEM_EMERGENCY -> Emergency Stop: All transactions suspended
}
0
likes
0
points
1.74k
downloads

Publisher

unverified uploader

Weekly Downloads

A structural precedence engine for Dart and Flutter. Resolves state ambiguity using compile-time DAG resolution.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, meta, source_gen

More

Packages that depend on strux_pr