44//!
55//! This module provides traits and types for recognizing the semantic meaning of executed commands
66//! (such as compilers or interpreters) and for formatting their output into structured entries.
7- //!
8- //! # Main Components
9- //!
10- //! - [`Command`]: Enum representing recognized command types.
11- //! - [`Interpreter`]: Trait for recognizing the semantic meaning of an `Execution`.
12- //! - [`Formattable`]: Trait for converting recognized commands into output entries.
13- //! - [`EntryFormat`]: Configuration for formatting output entries.
14- //!
15- //! Implementers of [`Interpreter`] analyze an `Execution` and determine if it matches a known command.
16- //! If recognized, they return a boxed [`Command`] representing the semantic meaning of the execution.
17- //!
18- //! The [`Formattable`] trait allows recognized commands to be transformed into output entries (e.g.,
19- //! for a compilation database), using the provided [`EntryFormat`].
207
218pub mod clang;
229pub mod command;
2310pub mod interpreters;
2411
2512use super :: intercept:: Execution ;
26- use crate :: config:: EntryFormat ;
13+ use crate :: config;
2714use serde:: { Deserialize , Serialize } ;
2815use std:: fmt:: Debug ;
2916
@@ -41,6 +28,17 @@ pub enum Command {
4128 Filtered ( String ) ,
4229}
4330
31+ impl Command {
32+ /// Converts the command into compilation database entries.
33+ pub fn to_entries ( & self , config : & config:: EntryFormat ) -> Vec < clang:: Entry > {
34+ match self {
35+ Command :: Compiler ( cmd) => cmd. to_entries ( config) ,
36+ Command :: Ignored ( _) => vec ! [ ] ,
37+ Command :: Filtered ( _) => vec ! [ ] ,
38+ }
39+ }
40+ }
41+
4442/// Responsible for recognizing the semantic meaning of an executed command.
4543///
4644/// Implementers of this trait analyze an [`Execution`] and determine if it matches
@@ -50,19 +48,3 @@ pub trait Interpreter: Send {
5048 /// An [`Option<Command>`] containing the recognized command, or `None` if not recognized.
5149 fn recognize ( & self , execution : & Execution ) -> Option < Command > ;
5250}
53-
54- /// Trait for types that can be formatted into output entries.
55- pub trait Formattable {
56- /// Converts the command into a list of entries, using the provided format configuration.
57- fn to_entries ( & self , config : & EntryFormat ) -> Vec < clang:: Entry > ;
58- }
59-
60- impl Formattable for Command {
61- fn to_entries ( & self , config : & EntryFormat ) -> Vec < clang:: Entry > {
62- match self {
63- Command :: Compiler ( cmd) => cmd. to_entries ( config) ,
64- Command :: Ignored ( _) => vec ! [ ] ,
65- Command :: Filtered ( _) => vec ! [ ] ,
66- }
67- }
68- }
0 commit comments