Commit graph

21 commits

Author SHA1 Message Date
Yuya Nishihara
9065b94dc1 templater: implement list methods for unformattable property 2023-03-24 12:17:38 +09:00
Yuya Nishihara
a0be6a5a11 templater: add support for unformattable property
A property of Commit type won't have a default format.
2023-03-24 12:17:38 +09:00
Yuya Nishihara
3124444d24 templater: add list.map(|x| ...) operation
This involves a little hack to insert a lambda parameter 'x' to be used at
keyword position. If the template language were dynamically typed (and were
interpreted), .map() implementation would be simpler. I considered that, but
interpreter version has its own warts (late error reporting, uneasy to cache
static object, etc.), and I don't think the current template engine is
complex enough to rewrite from scratch.

.map() returns template, which can't be join()-ed. This will be fixed later.
2023-03-18 12:04:00 +09:00
Yuya Nishihara
20a75947fe templater: add stub BuildContext object, pass it around build_() functions
A lambda parameter will be added there just like "locals" of expand_aliases().
2023-03-18 12:04:00 +09:00
Yuya Nishihara
23bed2731c templater: extract evaluation interface and build_() functions to new module
I'm thinking of rewriting the evaluation part as a simple interpreter. It
will increase the runtime cost (about a few microseconds per entry I suppose),
but will greatly reduce the complexity of generic property function chaining.

The extracted template_builder module is the part I'm going to reimplement.
2023-03-13 11:45:17 +09:00
Yuya Nishihara
91d309a93c templater: extract little helper that parses text and expands aliases
The caller doesn't have to care about alias expansion.
2023-03-13 11:45:17 +09:00
Yuya Nishihara
82604eda02 cli: extract complete_newline() to text_util module
I'll add more text formatting functions there.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
6af265a388 templater: move Box::new() wrapping to language.wrap_() functions
Now all callers do wrap_<type>(Box::new(...)), so its responsibility can be
moved to the callee without extra boxing.
2023-03-08 16:14:24 +09:00
Yuya Nishihara
96f4d8798c templater: remove redundant TemplateProperty wrapping from method chaining
TemplateFunction takes a property and a function to apply to the property
value. That's exactly what a method call does.
2023-03-08 16:14:24 +09:00
Yuya Nishihara
4984e611f4 templater: add "parent_commit_ids" keyword
A list type isn't so useful without a map operation, but List<CommitId>
is at least printable. Maybe we can experiment with it to craft a map
operation.

If a map operation is introduced, this keyword might be replaced with
"parents.map(|commit| commit.commit_id)", where parents is of List<Commit>
type, and the .map() method will probably return List<Template>.
2023-03-07 11:33:15 +09:00
Yuya Nishihara
558aa15e6e templater: remove Template::has_content() superseded by FormatRecorder 2023-03-04 12:10:53 +09:00
Ilya Grigoriev
00b18bcd18 templater: Upper and lowercase ids and strings 2023-02-21 22:50:27 -08:00
Yuya Nishihara
da3c1d2286 templater: extract helpers to build expression of specific types 2023-02-20 18:20:41 +09:00
Yuya Nishihara
c2e0ebca12 templater: implement .into_template() helper on formattable property
So that I can blindly write property.into_template() to convert any property
type to template.
2023-02-20 18:20:41 +09:00
Yuya Nishihara
854a3e64fa templater: split IntoTemplate trait
The next commit will implement .into_template() on Box<dyn TemplateProperty>,
so I want a trait for this particular method.
2023-02-20 18:20:41 +09:00
Yuya Nishihara
a3efb74cfc commit_templater: make commit/change_id typed again
This basically undoes d6c6cdb45c "templater: store type-erased version of
commit/change id." Since they are looked up differently, they should preserve
the original types.
2023-02-20 13:41:44 +09:00
Yuya Nishihara
4f9e75c7d1 templater: use macro to implement property kind wrappers 2023-02-19 16:18:39 +09:00
Yuya Nishihara
aaae90a599 commit_templater: turn property structs into functions 2023-02-19 16:18:39 +09:00
Yuya Nishihara
cf1b609de2 commit_templater: rename 'repo lifetime for clarity
FWIW, I'm thinking of making the repo parameter generic over Arc<ReadonlyRepo>
and &MutableRepo. It will allow us cache a parsed commit_summary template.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
c5ddd14c13 commit_templater: extract runtime objects from templater.rs
This should reduce future merge conflicts around use statements.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
c396b4cecf commit_templater: extract parsing functions from template_parser.rs
parse_commit_template() is renamed to commit_templater::parse().
2023-02-19 16:18:39 +09:00