forked from mirrors/jj
cli: switch "debug template" command to new AST
This should be more readable than raw pest tree.
This commit is contained in:
parent
677ac54855
commit
81c8543621
2 changed files with 6 additions and 10 deletions
|
@ -42,7 +42,6 @@ use jujutsu_lib::tree::{merge_trees, Tree};
|
||||||
use jujutsu_lib::workspace::{Workspace, WorkspaceLoader};
|
use jujutsu_lib::workspace::{Workspace, WorkspaceLoader};
|
||||||
use jujutsu_lib::{conflicts, file_util, revset};
|
use jujutsu_lib::{conflicts, file_util, revset};
|
||||||
use maplit::{hashmap, hashset};
|
use maplit::{hashmap, hashset};
|
||||||
use pest::Parser;
|
|
||||||
|
|
||||||
use crate::cli_util::{
|
use crate::cli_util::{
|
||||||
self, check_stale_working_copy, print_checkout_stats, resolve_multiple_nonempty_revsets,
|
self, check_stale_working_copy, print_checkout_stats, resolve_multiple_nonempty_revsets,
|
||||||
|
@ -54,7 +53,7 @@ use crate::config::{config_path, AnnotatedValue, ConfigSource};
|
||||||
use crate::diff_util::{self, DiffFormat, DiffFormatArgs};
|
use crate::diff_util::{self, DiffFormat, DiffFormatArgs};
|
||||||
use crate::formatter::{Formatter, PlainTextFormatter};
|
use crate::formatter::{Formatter, PlainTextFormatter};
|
||||||
use crate::graphlog::{get_graphlog, Edge};
|
use crate::graphlog::{get_graphlog, Edge};
|
||||||
use crate::template_parser::TemplateParser;
|
use crate::template_parser;
|
||||||
use crate::ui::Ui;
|
use crate::ui::Ui;
|
||||||
|
|
||||||
#[derive(clap::Parser, Clone, Debug)]
|
#[derive(clap::Parser, Clone, Debug)]
|
||||||
|
@ -3103,11 +3102,8 @@ fn cmd_debug(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DebugCommands::Template(template_matches) => {
|
DebugCommands::Template(template_matches) => {
|
||||||
let parse = TemplateParser::parse(
|
let node = template_parser::parse_template(&template_matches.template)?;
|
||||||
crate::template_parser::Rule::program,
|
writeln!(ui, "{node:#?}")?;
|
||||||
&template_matches.template,
|
|
||||||
);
|
|
||||||
writeln!(ui, "{parse:#?}")?;
|
|
||||||
}
|
}
|
||||||
DebugCommands::Index(_index_matches) => {
|
DebugCommands::Index(_index_matches) => {
|
||||||
let workspace_command = command.workspace_helper(ui)?;
|
let workspace_command = command.workspace_helper(ui)?;
|
||||||
|
|
|
@ -37,7 +37,7 @@ use crate::{cli_util, time_util};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[grammar = "template.pest"]
|
#[grammar = "template.pest"]
|
||||||
pub struct TemplateParser;
|
struct TemplateParser;
|
||||||
|
|
||||||
type TemplateParseResult<T> = Result<T, TemplateParseError>;
|
type TemplateParseResult<T> = Result<T, TemplateParseError>;
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ impl error::Error for TemplateParseError {
|
||||||
|
|
||||||
/// AST node without type or name checking.
|
/// AST node without type or name checking.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
struct ExpressionNode<'i> {
|
pub struct ExpressionNode<'i> {
|
||||||
kind: ExpressionKind<'i>,
|
kind: ExpressionKind<'i>,
|
||||||
span: pest::Span<'i>,
|
span: pest::Span<'i>,
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ fn parse_template_node(pair: Pair<Rule>) -> TemplateParseResult<ExpressionNode>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses text into AST nodes. No type/name checking is made at this stage.
|
/// Parses text into AST nodes. No type/name checking is made at this stage.
|
||||||
fn parse_template(template_text: &str) -> TemplateParseResult<ExpressionNode> {
|
pub fn parse_template(template_text: &str) -> TemplateParseResult<ExpressionNode> {
|
||||||
let mut pairs: Pairs<Rule> = TemplateParser::parse(Rule::program, template_text)?;
|
let mut pairs: Pairs<Rule> = TemplateParser::parse(Rule::program, template_text)?;
|
||||||
let first_pair = pairs.next().unwrap();
|
let first_pair = pairs.next().unwrap();
|
||||||
if first_pair.as_rule() == Rule::EOI {
|
if first_pair.as_rule() == Rule::EOI {
|
||||||
|
|
Loading…
Reference in a new issue