Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [ADR-0006: Dynamic Query Execution](docs/adr/ADR-0006-dynamic-query-execution.md)
- [ADR-0007: Type Metadata Format](docs/adr/ADR-0007-type-metadata-format.md)
- [ADR-0008: Tree Navigation](docs/adr/ADR-0008-tree-navigation.md)
- [ADR-0009: Type System](docs/adr/ADR-0009-type-system.md)
- **Template**:

```markdown
Expand Down
12 changes: 12 additions & 0 deletions crates/plotnik-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,16 @@ pub struct OutputArgs {
/// Show inferred cardinalities
#[arg(long)]
pub cardinalities: bool,

/// Show compiled graph
#[arg(long)]
pub graph: bool,

/// Show unoptimized graph (before epsilon elimination)
#[arg(long)]
pub graph_raw: bool,

/// Show inferred types
#[arg(long)]
pub types: bool,
}
25 changes: 24 additions & 1 deletion crates/plotnik-cli/src/commands/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub struct DebugArgs {
pub cst: bool,
pub spans: bool,
pub cardinalities: bool,
pub graph: bool,
pub graph_raw: bool,
pub types: bool,
pub color: bool,
}

Expand Down Expand Up @@ -51,7 +54,7 @@ pub fn run(args: DebugArgs) {
q.link(&lang);
}

let show_query = has_query_input && !args.symbols;
let show_query = has_query_input && !args.symbols && !args.graph && !args.types;
let show_source = has_source_input;
let show_headers = (show_query || args.symbols) && show_source;

Expand Down Expand Up @@ -85,6 +88,26 @@ pub fn run(args: DebugArgs) {
);
}

// Build graph if needed for --graph, --graph-raw, or --types
if (args.graph || args.graph_raw || args.types)
&& let Some(q) = query.take()
{
let (q, pre_opt_dump) = q.build_graph_with_pre_opt_dump();
if args.graph_raw {
println!("=== GRAPH (raw) ===");
print!("{}", pre_opt_dump);
}
if args.graph {
println!("=== GRAPH ===");
print!("{}", q.graph().dump_live(q.dead_nodes()));
}
if args.types {
println!("=== TYPES ===");
print!("{}", q.type_info().dump());
}
return;
}

if show_source {
let resolved_lang = resolve_lang(&args.lang, &args.source_text, &args.source_file);
let source_code = load_source(&args.source_text, &args.source_file);
Expand Down
3 changes: 3 additions & 0 deletions crates/plotnik-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ fn main() {
cst: output.cst,
spans: output.spans,
cardinalities: output.cardinalities,
graph: output.graph,
graph_raw: output.graph_raw,
types: output.types,
color: output.color.should_colorize(),
});
}
Expand Down
18 changes: 17 additions & 1 deletion crates/plotnik-lib/src/diagnostics/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ pub enum DiagnosticKind {
DirectRecursion,
FieldSequenceValue,

// Type inference errors
IncompatibleTypes,
MultiCaptureQuantifierNoName,
UnusedBranchLabels,

// Link pass - grammar validation
UnknownNodeType,
UnknownField,
Expand All @@ -75,7 +80,10 @@ pub enum DiagnosticKind {
impl DiagnosticKind {
/// Default severity for this kind. Can be overridden by policy.
pub fn default_severity(&self) -> Severity {
Severity::Error
match self {
Self::UnusedBranchLabels => Severity::Warning,
_ => Severity::Error,
}
}

/// Whether this kind suppresses `other` when spans overlap.
Expand Down Expand Up @@ -166,6 +174,13 @@ impl DiagnosticKind {
Self::DirectRecursion => "infinite recursion: cycle consumes no input",
Self::FieldSequenceValue => "field must match exactly one node",

// Type inference
Self::IncompatibleTypes => "incompatible types in alternation branches",
Self::MultiCaptureQuantifierNoName => {
"quantified expression with multiple captures requires `@name`"
}
Self::UnusedBranchLabels => "branch labels have no effect without capture",

// Link pass - grammar validation
Self::UnknownNodeType => "unknown node type",
Self::UnknownField => "unknown field",
Expand All @@ -192,6 +207,7 @@ impl DiagnosticKind {
// Semantic errors with name context
Self::DuplicateDefinition => "`{}` is already defined".to_string(),
Self::UndefinedReference => "`{}` is not defined".to_string(),
Self::IncompatibleTypes => "incompatible types: {}".to_string(),

// Link pass errors with context
Self::UnknownNodeType => "`{}` is not a valid node type".to_string(),
Expand Down
14 changes: 0 additions & 14 deletions crates/plotnik-lib/src/infer/emit/mod.rs

This file was deleted.

247 changes: 0 additions & 247 deletions crates/plotnik-lib/src/infer/emit/rust.rs

This file was deleted.

Loading