sdc_parser/
sdc.rs

1use crate::object::*;
2use crate::util::*;
3use combine::char::{char, space, string};
4use combine::error::{ParseError, StreamError};
5use combine::parser::Parser;
6use combine::{
7    attempt, choice, look_ahead, many, many1, none_of, optional, parser, token, Stream, StreamOnce,
8};
9use std::fmt;
10
11type AndThenError<I> = <<I as StreamOnce>::Error as ParseError<
12    <I as StreamOnce>::Item,
13    <I as StreamOnce>::Range,
14    <I as StreamOnce>::Position,
15>>::StreamError;
16
17// -----------------------------------------------------------------------------
18
19/// A type representing sdc
20#[derive(Clone, Debug, Default, PartialEq)]
21pub struct Sdc {
22    pub commands: Vec<Command>,
23}
24
25// -----------------------------------------------------------------------------
26
27/// Enumeration on sdc command
28#[derive(Clone, Debug, PartialEq)]
29pub enum Command {
30    LineBreak,
31    Comment(String),
32    CreateClock(CreateClock),
33    CreateGeneratedClock(CreateGeneratedClock),
34    CreateVoltageArea(CreateVoltageArea),
35    CurrentInstance(CurrentInstance),
36    GroupPath(GroupPath),
37    Set(Set),
38    SetCaseAnalysis(SetCaseAnalysis),
39    SetClockGatingCheck(SetClockGatingCheck),
40    SetClockGroups(SetClockGroups),
41    SetClockLatency(SetClockLatency),
42    SetClockSense(SetClockSense),
43    SetClockTransition(SetClockTransition),
44    SetClockUncertainty(SetClockUncertainty),
45    SetDataCheck(SetDataCheck),
46    SetDisableTiming(SetDisableTiming),
47    SetDrive(SetDrive),
48    SetDrivingCell(SetDrivingCell),
49    SetFalsePath(SetFalsePath),
50    SetFanoutLoad(SetFanoutLoad),
51    SetIdealLatency(SetIdealLatency),
52    SetIdealNetwork(SetIdealNetwork),
53    SetIdealTransition(SetIdealTransition),
54    SetInputDelay(SetInputDelay),
55    SetInputTransition(SetInputTransition),
56    SetLevelShifterStrategy(SetLevelShifterStrategy),
57    SetLevelShifterThreshold(SetLevelShifterThreshold),
58    SetLoad(SetLoad),
59    SetLogicDc(SetLogicDc),
60    SetLogicOne(SetLogicOne),
61    SetLogicZero(SetLogicZero),
62    SetMaxArea(SetMaxArea),
63    SetMaxCapacitance(SetMaxCapacitance),
64    SetMaxDelay(SetMaxDelay),
65    SetMaxDynamicPower(SetMaxDynamicPower),
66    SetMaxFanout(SetMaxFanout),
67    SetMaxLeakagePower(SetMaxLeakagePower),
68    SetMaxTimeBorrow(SetMaxTimeBorrow),
69    SetMaxTransition(SetMaxTransition),
70    SetMinCapacitance(SetMinCapacitance),
71    SetMinDelay(SetMinDelay),
72    SetMinPorosity(SetMinPorosity),
73    SetMinPulseWidth(SetMinPulseWidth),
74    SetMulticyclePath(SetMulticyclePath),
75    SetOperatingConditions(SetOperatingConditions),
76    SetOutputDelay(SetOutputDelay),
77    SetPortFanoutNumber(SetPortFanoutNumber),
78    SetPropagatedClock(SetPropagatedClock),
79    SetResistance(SetResistance),
80    SetSense(SetSense),
81    SetTimingDerate(SetTimingDerate),
82    SetUnits(SetUnits),
83    SetSdcVersion(SetSdcVersion),
84    SetVoltage(SetVoltage),
85    SetWireLoadMinBlockSize(SetWireLoadMinBlockSize),
86    SetWireLoadMode(SetWireLoadMode),
87    SetWireLoadModel(SetWireLoadModel),
88    SetWireLoadSelectionGroup(SetWireLoadSelectionGroup),
89    /// Any unknown command including vendor extensions
90    Unknown(String),
91    Whitespace,
92}
93
94impl fmt::Display for Command {
95    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96        match self {
97            Command::LineBreak => write!(f, "\n"),
98            Command::Comment(x) => write!(f, "#{}", x),
99            Command::CreateClock(x) => write!(f, "{}", x),
100            Command::CreateGeneratedClock(x) => write!(f, "{}", x),
101            Command::CreateVoltageArea(x) => write!(f, "{}", x),
102            Command::CurrentInstance(x) => write!(f, "{}", x),
103            Command::GroupPath(x) => write!(f, "{}", x),
104            Command::Set(x) => write!(f, "{}", x),
105            Command::SetCaseAnalysis(x) => write!(f, "{}", x),
106            Command::SetClockGatingCheck(x) => write!(f, "{}", x),
107            Command::SetClockGroups(x) => write!(f, "{}", x),
108            Command::SetClockLatency(x) => write!(f, "{}", x),
109            Command::SetClockSense(x) => write!(f, "{}", x),
110            Command::SetClockTransition(x) => write!(f, "{}", x),
111            Command::SetClockUncertainty(x) => write!(f, "{}", x),
112            Command::SetDataCheck(x) => write!(f, "{}", x),
113            Command::SetDisableTiming(x) => write!(f, "{}", x),
114            Command::SetDrive(x) => write!(f, "{}", x),
115            Command::SetDrivingCell(x) => write!(f, "{}", x),
116            Command::SetFalsePath(x) => write!(f, "{}", x),
117            Command::SetFanoutLoad(x) => write!(f, "{}", x),
118            Command::SetIdealLatency(x) => write!(f, "{}", x),
119            Command::SetIdealNetwork(x) => write!(f, "{}", x),
120            Command::SetIdealTransition(x) => write!(f, "{}", x),
121            Command::SetInputDelay(x) => write!(f, "{}", x),
122            Command::SetInputTransition(x) => write!(f, "{}", x),
123            Command::SetLevelShifterStrategy(x) => write!(f, "{}", x),
124            Command::SetLevelShifterThreshold(x) => write!(f, "{}", x),
125            Command::SetLoad(x) => write!(f, "{}", x),
126            Command::SetLogicDc(x) => write!(f, "{}", x),
127            Command::SetLogicOne(x) => write!(f, "{}", x),
128            Command::SetLogicZero(x) => write!(f, "{}", x),
129            Command::SetMaxArea(x) => write!(f, "{}", x),
130            Command::SetMaxCapacitance(x) => write!(f, "{}", x),
131            Command::SetMaxDelay(x) => write!(f, "{}", x),
132            Command::SetMaxDynamicPower(x) => write!(f, "{}", x),
133            Command::SetMaxFanout(x) => write!(f, "{}", x),
134            Command::SetMaxLeakagePower(x) => write!(f, "{}", x),
135            Command::SetMaxTimeBorrow(x) => write!(f, "{}", x),
136            Command::SetMaxTransition(x) => write!(f, "{}", x),
137            Command::SetMinCapacitance(x) => write!(f, "{}", x),
138            Command::SetMinDelay(x) => write!(f, "{}", x),
139            Command::SetMinPorosity(x) => write!(f, "{}", x),
140            Command::SetMinPulseWidth(x) => write!(f, "{}", x),
141            Command::SetMulticyclePath(x) => write!(f, "{}", x),
142            Command::SetOperatingConditions(x) => write!(f, "{}", x),
143            Command::SetOutputDelay(x) => write!(f, "{}", x),
144            Command::SetPortFanoutNumber(x) => write!(f, "{}", x),
145            Command::SetPropagatedClock(x) => write!(f, "{}", x),
146            Command::SetResistance(x) => write!(f, "{}", x),
147            Command::SetSense(x) => write!(f, "{}", x),
148            Command::SetTimingDerate(x) => write!(f, "{}", x),
149            Command::SetUnits(x) => write!(f, "{}", x),
150            Command::SetSdcVersion(x) => write!(f, "{}", x),
151            Command::SetVoltage(x) => write!(f, "{}", x),
152            Command::SetWireLoadMinBlockSize(x) => write!(f, "{}", x),
153            Command::SetWireLoadMode(x) => write!(f, "{}", x),
154            Command::SetWireLoadModel(x) => write!(f, "{}", x),
155            Command::SetWireLoadSelectionGroup(x) => write!(f, "{}", x),
156            Command::Unknown(x) => write!(f, "{}", x),
157            Command::Whitespace => write!(f, " "),
158        }
159    }
160}
161
162// -----------------------------------------------------------------------------
163
164enum CommandArg {
165    Add,
166    AddDelay,
167    AllowPaths,
168    AnalysisType(String),
169    Asynchronous,
170    CaseValue(CaseValue),
171    Capacitance(UnitValue),
172    CellCheck,
173    CellDelay,
174    ClockObj(Object),
175    Clock,
176    ClockFall,
177    ClockLeaf,
178    ClockPath,
179    Clocks(Object),
180    Combinational,
181    Comment(String),
182    Coordinate(Vec<f64>),
183    Current(UnitValue),
184    Data,
185    DataPath,
186    Default,
187    DivideBy(f64),
188    DontScale,
189    DutyCycle(f64),
190    Dynamic,
191    Early,
192    EdgeShift(Vec<f64>),
193    Edges(Vec<f64>),
194    End,
195    Fall,
196    FallFrom(Object),
197    FallThrough(Object),
198    FallTo(Object),
199    From(Object),
200    FromPin(Object),
201    Group(Object),
202    GuardBandX(f64),
203    GuardBandY(f64),
204    High,
205    Hold,
206    HoldVal(f64),
207    IgnoreClockLatency,
208    Increment,
209    InputTransitionFall(f64),
210    InputTransitionRise(f64),
211    Invert,
212    Late,
213    LevelSensitive,
214    LibCell(Object),
215    Library(Object),
216    LogicallyExclusive,
217    Low,
218    MasterClock(Object),
219    Max,
220    MaxStr(String),
221    MaxLibrary(Object),
222    Min,
223    MinStr(String),
224    MinLibrary(Object),
225    MinVal(f64),
226    MultiplyBy(f64),
227    Name(String),
228    Negative,
229    NetDelay,
230    NetworkLatencyIncluded,
231    NoDesignRule,
232    NoPropagate,
233    NonUnate,
234    ObjectList(Object),
235    Object(Object),
236    Percent(f64),
237    Period(f64),
238    PhysicallyExclusive,
239    Pin(Object),
240    PinLoad,
241    Positive,
242    Power(UnitValue),
243    Pulse(String),
244    ReferencePin(Object),
245    Resistance(UnitValue),
246    Rise,
247    RiseFrom(Object),
248    RiseThrough(Object),
249    RiseTo(Object),
250    Rule(String),
251    Setup,
252    SetupVal(f64),
253    Source,
254    SourceLatencyIncluded,
255    SourceObj(Object),
256    Start,
257    Static,
258    StopPropagation,
259    String(String),
260    SubtractPinLoad,
261    Through(Object),
262    Time(UnitValue),
263    To(Object),
264    Type(String),
265    Value(f64),
266    Voltage(f64),
267    VoltageUV(UnitValue),
268    Waveform(Vec<f64>),
269    Weight(f64),
270    WireLoad,
271}
272
273// -----------------------------------------------------------------------------
274
275pub(crate) fn sdc<I>() -> impl Parser<Input = I, Output = Sdc>
276where
277    I: Stream<Item = char>,
278    I::Error: ParseError<I::Item, I::Range, I::Position>,
279{
280    many1(command()).map(|x| Sdc { commands: x })
281}
282
283pub(crate) fn sdc_strict<I>() -> impl Parser<Input = I, Output = Sdc>
284where
285    I: Stream<Item = char>,
286    I::Error: ParseError<I::Item, I::Range, I::Position>,
287{
288    many1(command_strict()).map(|x| Sdc { commands: x })
289}
290
291fn command<I>() -> impl Parser<Input = I, Output = Command>
292where
293    I: Stream<Item = char>,
294    I::Error: ParseError<I::Item, I::Range, I::Position>,
295{
296    choice((attempt(command_strict()), unknown()))
297}
298
299fn command_strict<I>() -> impl Parser<Input = I, Output = Command>
300where
301    I: Stream<Item = char>,
302    I::Error: ParseError<I::Item, I::Range, I::Position>,
303{
304    let c = (
305        attempt(create_clock()),
306        attempt(create_generated_clock()),
307        attempt(create_voltage_area()),
308        attempt(current_instance()),
309    );
310    let g = (group_path(),);
311    let set = (attempt(set_sdc_version()), attempt(set()));
312    let set_ca = (set_case_analysis(),);
313    let set_cl = (
314        attempt(set_clock_gating_check()),
315        attempt(set_clock_groups()),
316        attempt(set_clock_latency()),
317        attempt(set_clock_sense()),
318        attempt(set_clock_transition()),
319        attempt(set_clock_uncertainty()),
320    );
321    let set_d = (
322        attempt(set_data_check()),
323        attempt(set_disable_timing()),
324        attempt(set_drive()),
325        attempt(set_driving_cell()),
326    );
327    let set_f = (attempt(set_false_path()), attempt(set_fanout_load()));
328    let set_id = (
329        attempt(set_ideal_latency()),
330        attempt(set_ideal_network()),
331        attempt(set_ideal_transition()),
332    );
333    let set_in = (attempt(set_input_delay()), attempt(set_input_transition()));
334    let set_le = (
335        attempt(set_level_shifter_strategy()),
336        attempt(set_level_shifter_threshold()),
337    );
338    let set_lo = (
339        attempt(set_load()),
340        attempt(set_logic_dc()),
341        attempt(set_logic_one()),
342        attempt(set_logic_zero()),
343    );
344    let set_ma = (
345        attempt(set_max_delay()),
346        attempt(set_max_time_borrow()),
347        attempt(set_max_area()),
348        attempt(set_max_capacitance()),
349        attempt(set_max_fanout()),
350        attempt(set_max_transition()),
351        attempt(set_max_dynamic_power()),
352        attempt(set_max_leakage_power()),
353    );
354    let set_mi = (
355        attempt(set_min_delay()),
356        attempt(set_min_pulse_width()),
357        attempt(set_min_capacitance()),
358        attempt(set_min_porosity()),
359    );
360    let set_mu = (set_multicycle_path(),);
361    let set_o = (
362        attempt(set_operating_conditions()),
363        attempt(set_output_delay()),
364    );
365    let set_p = (
366        attempt(set_propagated_clock()),
367        attempt(set_port_fanout_number()),
368    );
369    let set_w = (
370        attempt(set_wire_load_min_block_size()),
371        attempt(set_wire_load_model()),
372        attempt(set_wire_load_mode()),
373        attempt(set_wire_load_selection_group()),
374    );
375    let set__ = (
376        attempt(set_resistance()),
377        attempt(set_sense()),
378        attempt(set_timing_derate()),
379        attempt(set_units()),
380        attempt(set_voltage()),
381    );
382
383    choice((
384        look_ahead(space()).with(whitespace()),
385        look_ahead(char('\n')).with(linebreak()),
386        look_ahead(string("\r\n")).with(linebreak()),
387        look_ahead(char('#')).with(comment()),
388        attempt(look_ahead(char('c')).with(choice(c))),
389        attempt(look_ahead(char('g')).with(choice(g))),
390        attempt(look_ahead(string("set ")).with(choice(set))),
391        attempt(look_ahead(string("set_ca")).with(choice(set_ca))),
392        attempt(look_ahead(string("set_cl")).with(choice(set_cl))),
393        attempt(look_ahead(string("set_d")).with(choice(set_d))),
394        attempt(look_ahead(string("set_f")).with(choice(set_f))),
395        attempt(look_ahead(string("set_id")).with(choice(set_id))),
396        attempt(look_ahead(string("set_in")).with(choice(set_in))),
397        attempt(look_ahead(string("set_le")).with(choice(set_le))),
398        attempt(look_ahead(string("set_lo")).with(choice(set_lo))),
399        attempt(look_ahead(string("set_ma")).with(choice(set_ma))),
400        attempt(look_ahead(string("set_mi")).with(choice(set_mi))),
401        attempt(look_ahead(string("set_mu")).with(choice(set_mu))),
402        attempt(look_ahead(string("set_o")).with(choice(set_o))),
403        attempt(look_ahead(string("set_p")).with(choice(set_p))),
404        attempt(look_ahead(string("set_w")).with(choice(set_w))),
405        attempt(choice(set__)),
406    ))
407}
408
409// -----------------------------------------------------------------------------
410
411fn linebreak<I>() -> impl Parser<Input = I, Output = Command>
412where
413    I: Stream<Item = char>,
414    I::Error: ParseError<I::Item, I::Range, I::Position>,
415{
416    let command = lex(string("\n").or(string("\r\n"))).map(|_| Command::LineBreak);
417    command
418}
419
420// -----------------------------------------------------------------------------
421
422fn comment<I>() -> impl Parser<Input = I, Output = Command>
423where
424    I: Stream<Item = char>,
425    I::Error: ParseError<I::Item, I::Range, I::Position>,
426{
427    let command = token('#')
428        .and(many(none_of("\n".chars())))
429        .map(|(_, x)| Command::Comment(x));
430    command
431}
432
433// -----------------------------------------------------------------------------
434
435/// A type containing information of `create_clock`
436#[derive(Clone, Debug, Default, PartialEq)]
437pub struct CreateClock {
438    pub period: f64,
439    pub name: Option<String>,
440    pub waveform: Vec<f64>,
441    pub add: bool,
442    pub comment: Option<String>,
443    pub source_objects: Option<Object>,
444}
445
446impl fmt::Display for CreateClock {
447    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
448        let mut args = String::from("");
449        args.push_str(&format!(" -period {}", self.period));
450        if let Some(name) = &self.name {
451            args.push_str(&format!(" -name {}", name));
452        }
453        if !self.waveform.is_empty() {
454            args.push_str(" -waveform {");
455            for (i, s) in self.waveform.iter().enumerate() {
456                if i == 0 {
457                    args.push_str(&format!("{}", s));
458                } else {
459                    args.push_str(&format!(" {}", s));
460                }
461            }
462            args.push_str("}");
463        }
464        if self.add {
465            args.push_str(" -add");
466        }
467        if let Some(comment) = &self.comment {
468            args.push_str(&format!(" -comment \"{}\"", comment));
469        }
470        if let Some(source_objects) = &self.source_objects {
471            args.push_str(&format!(" {}", source_objects));
472        }
473        write!(f, "create_clock{}", args)
474    }
475}
476
477fn create_clock<I>() -> impl Parser<Input = I, Output = Command>
478where
479    I: Stream<Item = char>,
480    I::Error: ParseError<I::Item, I::Range, I::Position>,
481{
482    let command = symbol("create_clock");
483    let period = symbol("-period")
484        .with(float())
485        .map(|x| CommandArg::Period(x));
486    let name = symbol("-name").with(item()).map(|x| CommandArg::Name(x));
487    let waveform = symbol("-waveform")
488        .with(braces(many1(float())))
489        .map(|x| CommandArg::Waveform(x));
490    let add = symbol("-add").map(|_| CommandArg::Add);
491    let comment = symbol("-comment")
492        .with(item())
493        .map(|x| CommandArg::Comment(x));
494    let source_objects = parser(object).map(|x| CommandArg::Object(x));
495    let args = (
496        attempt(period),
497        attempt(name),
498        attempt(waveform),
499        attempt(add),
500        attempt(comment),
501        attempt(source_objects),
502    );
503    command
504        .with(many(choice(args)))
505        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
506            let mut period = None;
507            let mut name = None;
508            let mut waveform = vec![];
509            let mut add = false;
510            let mut comment = None;
511            let mut source_objects = None;
512            for x in xs {
513                match x {
514                    CommandArg::Period(x) => period = Some(x),
515                    CommandArg::Name(x) => name = Some(x),
516                    CommandArg::Waveform(x) => waveform = x,
517                    CommandArg::Add => add = true,
518                    CommandArg::Comment(x) => comment = Some(x),
519                    CommandArg::Object(x) => source_objects = Some(x),
520                    _ => unreachable!(),
521                }
522            }
523            let period = period.ok_or(AndThenError::<I>::message_static_message(
524                "create_clock:period",
525            ))?;
526            Ok(Command::CreateClock(CreateClock {
527                period,
528                name,
529                waveform,
530                add,
531                comment,
532                source_objects,
533            }))
534        })
535}
536
537#[test]
538fn test_create_clock() {
539    let mut parser = command();
540    let tgt = "create_clock -period 10 -name clk -waveform {0 5} -add -comment \"aaa\" source";
541    let ret = parser.parse(tgt).unwrap().0;
542    assert_eq!(
543        Command::CreateClock(CreateClock {
544            period: 10.0,
545            name: Some(String::from("clk")),
546            waveform: vec![0.0, 5.0],
547            add: true,
548            comment: Some(String::from("aaa")),
549            source_objects: Some(Object::String(ObjectString {
550                strings: vec![String::from("source")]
551            })),
552        }),
553        ret
554    );
555    assert_eq!(tgt, format!("{}", ret));
556}
557
558// -----------------------------------------------------------------------------
559
560/// A type containing information of `create_generated_clock`
561#[derive(Clone, Debug, Default, PartialEq)]
562pub struct CreateGeneratedClock {
563    pub name: Option<String>,
564    pub source: Object,
565    pub edges: Vec<f64>,
566    pub divide_by: Option<f64>,
567    pub multiply_by: Option<f64>,
568    pub duty_cycle: Option<f64>,
569    pub invert: bool,
570    pub edge_shift: Vec<f64>,
571    pub add: bool,
572    pub master_clock: Option<Object>,
573    pub combinational: bool,
574    pub comment: Option<String>,
575    pub source_objects: Object,
576}
577
578impl fmt::Display for CreateGeneratedClock {
579    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
580        let mut args = String::from("");
581        if let Some(name) = &self.name {
582            args.push_str(&format!(" -name {}", name));
583        }
584        args.push_str(&format!(" -source {}", self.source));
585        if !self.edges.is_empty() {
586            args.push_str(" -edges {");
587            for (i, s) in self.edges.iter().enumerate() {
588                if i == 0 {
589                    args.push_str(&format!("{}", s));
590                } else {
591                    args.push_str(&format!(" {}", s));
592                }
593            }
594            args.push_str("}");
595        }
596        if let Some(divide_by) = &self.divide_by {
597            args.push_str(&format!(" -divide_by {}", divide_by));
598        }
599        if let Some(multiply_by) = &self.multiply_by {
600            args.push_str(&format!(" -multiply_by {}", multiply_by));
601        }
602        if let Some(duty_cycle) = &self.duty_cycle {
603            args.push_str(&format!(" -duty_cycle {}", duty_cycle));
604        }
605        if self.invert {
606            args.push_str(" -invert");
607        }
608        if !self.edge_shift.is_empty() {
609            args.push_str(" -edge_shift {");
610            for (i, s) in self.edge_shift.iter().enumerate() {
611                if i == 0 {
612                    args.push_str(&format!("{}", s));
613                } else {
614                    args.push_str(&format!(" {}", s));
615                }
616            }
617            args.push_str("}");
618        }
619        if self.add {
620            args.push_str(" -add");
621        }
622        if let Some(master_clock) = &self.master_clock {
623            args.push_str(&format!(" -master_clock {}", master_clock));
624        }
625        if self.combinational {
626            args.push_str(" -combinational");
627        }
628        if let Some(comment) = &self.comment {
629            args.push_str(&format!(" -comment \"{}\"", comment));
630        }
631        args.push_str(&format!(" {}", self.source_objects));
632        write!(f, "create_generated_clock{}", args)
633    }
634}
635
636fn create_generated_clock<I>() -> impl Parser<Input = I, Output = Command>
637where
638    I: Stream<Item = char>,
639    I::Error: ParseError<I::Item, I::Range, I::Position>,
640{
641    let command = symbol("create_generated_clock");
642    let name = symbol("-name").with(item()).map(|x| CommandArg::Name(x));
643    let source = symbol("-source")
644        .with(parser(object))
645        .map(|x| CommandArg::SourceObj(x));
646    let edges = symbol("-edges")
647        .with(braces(many1(float())))
648        .map(|x| CommandArg::Edges(x));
649    let divide_by = symbol("-divide_by")
650        .with(float())
651        .map(|x| CommandArg::DivideBy(x));
652    let multiply_by = symbol("-multiply_by")
653        .with(float())
654        .map(|x| CommandArg::MultiplyBy(x));
655    let duty_cycle = symbol("-duty_cycle")
656        .with(float())
657        .map(|x| CommandArg::DutyCycle(x));
658    let invert = symbol("-invert").map(|_| CommandArg::Invert);
659    let edge_shift = symbol("-edge_shift")
660        .with(braces(many1(float())))
661        .map(|x| CommandArg::EdgeShift(x));
662    let add = symbol("-add").map(|_| CommandArg::Add);
663    let master_clock = symbol("-master_clock")
664        .with(parser(object))
665        .map(|x| CommandArg::MasterClock(x));
666    let combinational = symbol("-combinational").map(|_| CommandArg::Combinational);
667    let comment = symbol("-comment")
668        .with(item())
669        .map(|x| CommandArg::Comment(x));
670    let source_objects = parser(object).map(|x| CommandArg::Object(x));
671    let args = (
672        attempt(name),
673        attempt(source),
674        attempt(edges),
675        attempt(divide_by),
676        attempt(multiply_by),
677        attempt(duty_cycle),
678        attempt(invert),
679        attempt(edge_shift),
680        attempt(add),
681        attempt(master_clock),
682        attempt(combinational),
683        attempt(comment),
684        attempt(source_objects),
685    );
686    command
687        .with(many(choice(args)))
688        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
689            let mut name = None;
690            let mut source = None;
691            let mut edges = vec![];
692            let mut divide_by = None;
693            let mut multiply_by = None;
694            let mut duty_cycle = None;
695            let mut invert = false;
696            let mut edge_shift = vec![];
697            let mut add = false;
698            let mut master_clock = None;
699            let mut combinational = false;
700            let mut comment = None;
701            let mut source_objects = None;
702            for x in xs {
703                match x {
704                    CommandArg::Name(x) => name = Some(x),
705                    CommandArg::SourceObj(x) => source = Some(x),
706                    CommandArg::Edges(x) => edges = x,
707                    CommandArg::DivideBy(x) => divide_by = Some(x),
708                    CommandArg::MultiplyBy(x) => multiply_by = Some(x),
709                    CommandArg::DutyCycle(x) => duty_cycle = Some(x),
710                    CommandArg::Invert => invert = true,
711                    CommandArg::EdgeShift(x) => edge_shift = x,
712                    CommandArg::Add => add = true,
713                    CommandArg::MasterClock(x) => master_clock = Some(x),
714                    CommandArg::Combinational => combinational = true,
715                    CommandArg::Comment(x) => comment = Some(x),
716                    CommandArg::Object(x) => source_objects = Some(x),
717                    _ => unreachable!(),
718                }
719            }
720            let source = source.ok_or(AndThenError::<I>::message_static_message(
721                "create_generated_clock:source",
722            ))?;
723            let source_objects = source_objects.ok_or(
724                AndThenError::<I>::message_static_message("create_generated_clock:source_objects"),
725            )?;
726            Ok(Command::CreateGeneratedClock(CreateGeneratedClock {
727                name,
728                source,
729                edges,
730                divide_by,
731                multiply_by,
732                duty_cycle,
733                invert,
734                edge_shift,
735                add,
736                master_clock,
737                combinational,
738                comment,
739                source_objects,
740            }))
741        })
742}
743
744#[test]
745fn test_create_generated_clock() {
746    let mut parser = command();
747    let tgt = "create_generated_clock -name clk -source src -edges {0 0.5} -divide_by 3 -multiply_by 2 -duty_cycle 0.4 -invert -edge_shift {0 1} -add -master_clock mclk -combinational -comment \"aaa\" clk";
748    let ret = parser.parse(tgt).unwrap().0;
749    assert_eq!(
750        Command::CreateGeneratedClock(CreateGeneratedClock {
751            name: Some(String::from("clk")),
752            source: Object::String(ObjectString {
753                strings: vec![String::from("src")]
754            }),
755            edges: vec![0.0, 0.5],
756            divide_by: Some(3.0),
757            multiply_by: Some(2.0),
758            duty_cycle: Some(0.4),
759            invert: true,
760            edge_shift: vec![0.0, 1.0],
761            add: true,
762            master_clock: Some(Object::String(ObjectString {
763                strings: vec![String::from("mclk")]
764            })),
765            combinational: true,
766            comment: Some(String::from("aaa")),
767            source_objects: Object::String(ObjectString {
768                strings: vec![String::from("clk")]
769            }),
770        }),
771        ret
772    );
773    assert_eq!(tgt, format!("{}", ret));
774}
775
776// -----------------------------------------------------------------------------
777
778/// A type containing information of `create_voltage_area`
779#[derive(Clone, Debug, Default, PartialEq)]
780pub struct CreateVoltageArea {
781    pub name: String,
782    pub coordinate: Vec<f64>,
783    pub guard_band_x: Option<f64>,
784    pub guard_band_y: Option<f64>,
785    pub cell_list: Object,
786}
787
788impl fmt::Display for CreateVoltageArea {
789    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
790        let mut args = String::from("");
791        args.push_str(&format!(" -name {}", self.name));
792        if !self.coordinate.is_empty() {
793            args.push_str(" -coordinate {");
794            for (i, s) in self.coordinate.iter().enumerate() {
795                if i == 0 {
796                    args.push_str(&format!("{}", s));
797                } else {
798                    args.push_str(&format!(" {}", s));
799                }
800            }
801            args.push_str("}");
802        }
803        if let Some(guard_band_x) = &self.guard_band_x {
804            args.push_str(&format!(" -guard_band_x {}", guard_band_x));
805        }
806        if let Some(guard_band_y) = &self.guard_band_y {
807            args.push_str(&format!(" -guard_band_y {}", guard_band_y));
808        }
809        args.push_str(&format!(" {}", self.cell_list));
810        write!(f, "create_voltage_area{}", args)
811    }
812}
813
814fn create_voltage_area<I>() -> impl Parser<Input = I, Output = Command>
815where
816    I: Stream<Item = char>,
817    I::Error: ParseError<I::Item, I::Range, I::Position>,
818{
819    let command = symbol("create_voltage_area");
820    let name = symbol("-name").with(item()).map(|x| CommandArg::Name(x));
821    let coordinate = symbol("-coordinate")
822        .with(braces(many1(float())))
823        .map(|x| CommandArg::Coordinate(x));
824    let guard_band_x = symbol("-guard_band_x")
825        .with(float())
826        .map(|x| CommandArg::GuardBandX(x));
827    let guard_band_y = symbol("-guard_band_y")
828        .with(float())
829        .map(|x| CommandArg::GuardBandY(x));
830    let cell_list = parser(object).map(|x| CommandArg::Object(x));
831    let args = (
832        attempt(name),
833        attempt(coordinate),
834        attempt(guard_band_x),
835        attempt(guard_band_y),
836        attempt(cell_list),
837    );
838    command
839        .with(many(choice(args)))
840        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
841            let mut name = None;
842            let mut coordinate = Vec::new();
843            let mut guard_band_x = None;
844            let mut guard_band_y = None;
845            let mut cell_list = None;
846            for x in xs {
847                match x {
848                    CommandArg::Name(x) => name = Some(x),
849                    CommandArg::Coordinate(x) => coordinate = x,
850                    CommandArg::GuardBandX(x) => guard_band_x = Some(x),
851                    CommandArg::GuardBandY(x) => guard_band_y = Some(x),
852                    CommandArg::Object(x) => cell_list = Some(x),
853                    _ => unreachable!(),
854                }
855            }
856            let name = name.ok_or(AndThenError::<I>::message_static_message(
857                "create_voltage_area:name",
858            ))?;
859            let cell_list = cell_list.ok_or(AndThenError::<I>::message_static_message(
860                "create_voltage_area:cell_list",
861            ))?;
862            Ok(Command::CreateVoltageArea(CreateVoltageArea {
863                name,
864                coordinate,
865                guard_band_x,
866                guard_band_y,
867                cell_list,
868            }))
869        })
870}
871
872#[test]
873fn test_create_voltage_area() {
874    let mut parser = command();
875    let tgt = "create_voltage_area -name a -coordinate {10 20 30 40} -guard_band_x 0.1 -guard_band_y 0.1 a";
876    let ret = parser.parse(tgt).unwrap().0;
877    assert_eq!(
878        Command::CreateVoltageArea(CreateVoltageArea {
879            name: String::from("a"),
880            coordinate: vec![10.0, 20.0, 30.0, 40.0],
881            guard_band_x: Some(0.1),
882            guard_band_y: Some(0.1),
883            cell_list: Object::String(ObjectString {
884                strings: vec![String::from("a")]
885            }),
886        }),
887        ret
888    );
889    assert_eq!(tgt, format!("{}", ret));
890}
891
892// -----------------------------------------------------------------------------
893
894/// A type containing information of `current_instance`
895#[derive(Clone, Debug, Default, PartialEq)]
896pub struct CurrentInstance {
897    pub instance: Option<String>,
898}
899
900impl fmt::Display for CurrentInstance {
901    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
902        let mut args = String::from("");
903        if let Some(instance) = &self.instance {
904            args.push_str(&format!(" {}", instance));
905        }
906        write!(f, "current_instance{}", args)
907    }
908}
909
910fn current_instance<I>() -> impl Parser<Input = I, Output = Command>
911where
912    I: Stream<Item = char>,
913    I::Error: ParseError<I::Item, I::Range, I::Position>,
914{
915    let command = symbol("current_instance");
916    let instance = item().map(|x| CommandArg::String(x));
917    let args = (attempt(instance),);
918    command
919        .with(many(choice(args)))
920        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
921            let mut instance = None;
922            for x in xs {
923                match x {
924                    CommandArg::String(x) => instance = Some(x),
925                    _ => unreachable!(),
926                }
927            }
928            Ok(Command::CurrentInstance(CurrentInstance { instance }))
929        })
930}
931
932#[test]
933fn test_current_instance() {
934    let mut parser = command();
935    let tgt = "current_instance dut";
936    let ret = parser.parse(tgt).unwrap().0;
937    assert_eq!(
938        Command::CurrentInstance(CurrentInstance {
939            instance: Some(String::from("dut")),
940        }),
941        ret
942    );
943    assert_eq!(tgt, format!("{}", ret));
944}
945
946// -----------------------------------------------------------------------------
947
948/// A type containing information of `group_path`
949#[derive(Clone, Debug, Default, PartialEq)]
950pub struct GroupPath {
951    pub name: Option<String>,
952    pub default: bool,
953    pub weight: Option<f64>,
954    pub from: Option<Object>,
955    pub rise_from: Option<Object>,
956    pub fall_from: Option<Object>,
957    pub to: Option<Object>,
958    pub rise_to: Option<Object>,
959    pub fall_to: Option<Object>,
960    pub through: Option<Object>,
961    pub rise_through: Option<Object>,
962    pub fall_through: Option<Object>,
963    pub comment: Option<String>,
964}
965
966impl fmt::Display for GroupPath {
967    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
968        let mut args = String::from("");
969        if let Some(name) = &self.name {
970            args.push_str(&format!(" -name {}", name));
971        }
972        if self.default {
973            args.push_str(" -default");
974        }
975        if let Some(weight) = &self.weight {
976            args.push_str(&format!(" -weight {}", weight));
977        }
978        if let Some(from) = &self.from {
979            args.push_str(&format!(" -from {}", from));
980        }
981        if let Some(rise_from) = &self.rise_from {
982            args.push_str(&format!(" -rise_from {}", rise_from));
983        }
984        if let Some(fall_from) = &self.fall_from {
985            args.push_str(&format!(" -fall_from {}", fall_from));
986        }
987        if let Some(to) = &self.to {
988            args.push_str(&format!(" -to {}", to));
989        }
990        if let Some(rise_to) = &self.rise_to {
991            args.push_str(&format!(" -rise_to {}", rise_to));
992        }
993        if let Some(fall_to) = &self.fall_to {
994            args.push_str(&format!(" -fall_to {}", fall_to));
995        }
996        if let Some(through) = &self.through {
997            args.push_str(&format!(" -through {}", through));
998        }
999        if let Some(rise_through) = &self.rise_through {
1000            args.push_str(&format!(" -rise_through {}", rise_through));
1001        }
1002        if let Some(fall_through) = &self.fall_through {
1003            args.push_str(&format!(" -fall_through {}", fall_through));
1004        }
1005        if let Some(comment) = &self.comment {
1006            args.push_str(&format!(" -comment \"{}\"", comment));
1007        }
1008        write!(f, "group_path{}", args)
1009    }
1010}
1011
1012fn group_path<I>() -> impl Parser<Input = I, Output = Command>
1013where
1014    I: Stream<Item = char>,
1015    I::Error: ParseError<I::Item, I::Range, I::Position>,
1016{
1017    let command = symbol("group_path");
1018    let name = symbol("-name").with(item()).map(|x| CommandArg::Name(x));
1019    let default = symbol("-default").map(|_| CommandArg::Default);
1020    let weight = symbol("-weight")
1021        .with(float())
1022        .map(|x| CommandArg::Weight(x));
1023    let from = symbol("-from")
1024        .with(parser(object))
1025        .map(|x| CommandArg::From(x));
1026    let rise_from = symbol("-rise_from")
1027        .with(parser(object))
1028        .map(|x| CommandArg::RiseFrom(x));
1029    let fall_from = symbol("-fall_from")
1030        .with(parser(object))
1031        .map(|x| CommandArg::FallFrom(x));
1032    let to = symbol("-to")
1033        .with(parser(object))
1034        .map(|x| CommandArg::To(x));
1035    let rise_to = symbol("-rise_to")
1036        .with(parser(object))
1037        .map(|x| CommandArg::RiseTo(x));
1038    let fall_to = symbol("-fall_to")
1039        .with(parser(object))
1040        .map(|x| CommandArg::FallTo(x));
1041    let through = symbol("-through")
1042        .with(parser(object))
1043        .map(|x| CommandArg::Through(x));
1044    let rise_through = symbol("-rise_through")
1045        .with(parser(object))
1046        .map(|x| CommandArg::RiseThrough(x));
1047    let fall_through = symbol("-fall_through")
1048        .with(parser(object))
1049        .map(|x| CommandArg::FallThrough(x));
1050    let comment = symbol("-comment")
1051        .with(item())
1052        .map(|x| CommandArg::Comment(x));
1053    let args = (
1054        attempt(name),
1055        attempt(default),
1056        attempt(weight),
1057        attempt(from),
1058        attempt(rise_from),
1059        attempt(fall_from),
1060        attempt(to),
1061        attempt(rise_to),
1062        attempt(fall_to),
1063        attempt(through),
1064        attempt(rise_through),
1065        attempt(fall_through),
1066        attempt(comment),
1067    );
1068    command
1069        .with(many(choice(args)))
1070        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
1071            let mut name = None;
1072            let mut default = false;
1073            let mut weight = None;
1074            let mut from = None;
1075            let mut rise_from = None;
1076            let mut fall_from = None;
1077            let mut to = None;
1078            let mut rise_to = None;
1079            let mut fall_to = None;
1080            let mut through = None;
1081            let mut rise_through = None;
1082            let mut fall_through = None;
1083            let mut comment = None;
1084            for x in xs {
1085                match x {
1086                    CommandArg::Name(x) => name = Some(x),
1087                    CommandArg::Default => default = true,
1088                    CommandArg::Weight(x) => weight = Some(x),
1089                    CommandArg::From(x) => from = Some(x),
1090                    CommandArg::RiseFrom(x) => rise_from = Some(x),
1091                    CommandArg::FallFrom(x) => fall_from = Some(x),
1092                    CommandArg::To(x) => to = Some(x),
1093                    CommandArg::RiseTo(x) => rise_to = Some(x),
1094                    CommandArg::FallTo(x) => fall_to = Some(x),
1095                    CommandArg::Through(x) => through = Some(x),
1096                    CommandArg::RiseThrough(x) => rise_through = Some(x),
1097                    CommandArg::FallThrough(x) => fall_through = Some(x),
1098                    CommandArg::Comment(x) => comment = Some(x),
1099                    _ => unreachable!(),
1100                }
1101            }
1102            Ok(Command::GroupPath(GroupPath {
1103                name,
1104                default,
1105                weight,
1106                from,
1107                rise_from,
1108                fall_from,
1109                to,
1110                rise_to,
1111                fall_to,
1112                through,
1113                rise_through,
1114                fall_through,
1115                comment,
1116            }))
1117        })
1118}
1119
1120#[test]
1121fn test_group_path() {
1122    let mut parser = command();
1123    let tgt = "group_path -name path -default -weight 2 -from a -rise_from a -fall_from a -to b -rise_to b -fall_to b -through c -rise_through c -fall_through c -comment \"aaa\"";
1124    let ret = parser.parse(tgt).unwrap().0;
1125    assert_eq!(
1126        Command::GroupPath(GroupPath {
1127            name: Some(String::from("path")),
1128            default: true,
1129            weight: Some(2.0),
1130            from: Some(Object::String(ObjectString {
1131                strings: vec![String::from("a")]
1132            })),
1133            rise_from: Some(Object::String(ObjectString {
1134                strings: vec![String::from("a")]
1135            })),
1136            fall_from: Some(Object::String(ObjectString {
1137                strings: vec![String::from("a")]
1138            })),
1139            to: Some(Object::String(ObjectString {
1140                strings: vec![String::from("b")]
1141            })),
1142            rise_to: Some(Object::String(ObjectString {
1143                strings: vec![String::from("b")]
1144            })),
1145            fall_to: Some(Object::String(ObjectString {
1146                strings: vec![String::from("b")]
1147            })),
1148            through: Some(Object::String(ObjectString {
1149                strings: vec![String::from("c")]
1150            })),
1151            rise_through: Some(Object::String(ObjectString {
1152                strings: vec![String::from("c")]
1153            })),
1154            fall_through: Some(Object::String(ObjectString {
1155                strings: vec![String::from("c")]
1156            })),
1157            comment: Some(String::from("aaa")),
1158        }),
1159        ret
1160    );
1161    assert_eq!(tgt, format!("{}", ret));
1162}
1163
1164// -----------------------------------------------------------------------------
1165
1166/// A type containing information of `set`
1167#[derive(Clone, Debug, Default, PartialEq)]
1168pub struct Set {
1169    pub variable_name: String,
1170    pub value: Object,
1171}
1172
1173impl fmt::Display for Set {
1174    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1175        let mut args = String::from("");
1176        args.push_str(&format!(" {}", self.variable_name));
1177        args.push_str(&format!(" {}", self.value));
1178        write!(f, "set{}", args)
1179    }
1180}
1181
1182fn set<I>() -> impl Parser<Input = I, Output = Command>
1183where
1184    I: Stream<Item = char>,
1185    I::Error: ParseError<I::Item, I::Range, I::Position>,
1186{
1187    let command = symbol("set")
1188        .with(item())
1189        .and(parser(object))
1190        .map(|(x, y)| {
1191            Command::Set(Set {
1192                variable_name: x,
1193                value: y,
1194            })
1195        });
1196    command
1197}
1198
1199#[test]
1200fn test_set() {
1201    let mut parser = command();
1202    let tgt = "set a b";
1203    let ret = parser.parse(tgt).unwrap().0;
1204    assert_eq!(
1205        Command::Set(Set {
1206            variable_name: String::from("a"),
1207            value: Object::String(ObjectString {
1208                strings: vec![String::from("b")]
1209            })
1210        }),
1211        ret
1212    );
1213    assert_eq!(tgt, format!("{}", ret));
1214}
1215
1216// -----------------------------------------------------------------------------
1217
1218/// A type containing information of `set_case_analysis`
1219#[derive(Clone, Debug, Default, PartialEq)]
1220pub struct SetCaseAnalysis {
1221    pub value: CaseValue,
1222    pub port_or_pin_list: Object,
1223}
1224
1225impl fmt::Display for SetCaseAnalysis {
1226    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1227        let mut args = String::from("");
1228        args.push_str(&format!(" {}", self.value));
1229        args.push_str(&format!(" {}", self.port_or_pin_list));
1230        write!(f, "set_case_analysis{}", args)
1231    }
1232}
1233
1234#[derive(Clone, Debug, PartialEq)]
1235pub enum CaseValue {
1236    Zero,
1237    One,
1238    Rising,
1239    Falling,
1240}
1241
1242impl Default for CaseValue {
1243    fn default() -> Self {
1244        CaseValue::Zero
1245    }
1246}
1247
1248impl fmt::Display for CaseValue {
1249    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1250        match self {
1251            CaseValue::Zero => write!(f, "0"),
1252            CaseValue::One => write!(f, "1"),
1253            CaseValue::Rising => write!(f, "rising"),
1254            CaseValue::Falling => write!(f, "falling"),
1255        }
1256    }
1257}
1258
1259fn set_case_analysis<I>() -> impl Parser<Input = I, Output = Command>
1260where
1261    I: Stream<Item = char>,
1262    I::Error: ParseError<I::Item, I::Range, I::Position>,
1263{
1264    let command = symbol("set_case_analysis");
1265    let value = choice((
1266        symbol("0"),
1267        symbol("1"),
1268        symbol("rising"),
1269        symbol("falling"),
1270    ))
1271    .map(|x| match x {
1272        "0" => CommandArg::CaseValue(CaseValue::Zero),
1273        "1" => CommandArg::CaseValue(CaseValue::One),
1274        "rising" => CommandArg::CaseValue(CaseValue::Rising),
1275        "falling" => CommandArg::CaseValue(CaseValue::Falling),
1276        _ => unreachable!(),
1277    });
1278    let port_or_pin_list = parser(object).map(|x| CommandArg::Object(x));
1279    let args = (attempt(value), attempt(port_or_pin_list));
1280    command
1281        .with(many(choice(args)))
1282        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
1283            let mut value = None;
1284            let mut port_or_pin_list = None;
1285            for x in xs {
1286                match x {
1287                    CommandArg::CaseValue(x) => value = Some(x),
1288                    CommandArg::Object(x) => port_or_pin_list = Some(x),
1289                    _ => unreachable!(),
1290                }
1291            }
1292            let value = value.ok_or(AndThenError::<I>::message_static_message(
1293                "set_case_analysis:value",
1294            ))?;
1295            let port_or_pin_list = port_or_pin_list.ok_or(
1296                AndThenError::<I>::message_static_message("set_case_analysis:port_or_pin_list"),
1297            )?;
1298            Ok(Command::SetCaseAnalysis(SetCaseAnalysis {
1299                value,
1300                port_or_pin_list,
1301            }))
1302        })
1303}
1304
1305#[test]
1306fn test_set_case_analysis() {
1307    let mut parser = command();
1308    let tgt = "set_case_analysis 0 a";
1309    let ret = parser.parse(tgt).unwrap().0;
1310    assert_eq!(
1311        Command::SetCaseAnalysis(SetCaseAnalysis {
1312            value: CaseValue::Zero,
1313            port_or_pin_list: Object::String(ObjectString {
1314                strings: vec![String::from("a")]
1315            }),
1316        }),
1317        ret
1318    );
1319    let tgt = "set_case_analysis 1 a";
1320    let ret = parser.parse(tgt).unwrap().0;
1321    assert_eq!(
1322        Command::SetCaseAnalysis(SetCaseAnalysis {
1323            value: CaseValue::One,
1324            port_or_pin_list: Object::String(ObjectString {
1325                strings: vec![String::from("a")]
1326            }),
1327        }),
1328        ret
1329    );
1330    let tgt = "set_case_analysis rising a";
1331    let ret = parser.parse(tgt).unwrap().0;
1332    assert_eq!(
1333        Command::SetCaseAnalysis(SetCaseAnalysis {
1334            value: CaseValue::Rising,
1335            port_or_pin_list: Object::String(ObjectString {
1336                strings: vec![String::from("a")]
1337            }),
1338        }),
1339        ret
1340    );
1341    let tgt = "set_case_analysis falling a";
1342    let ret = parser.parse(tgt).unwrap().0;
1343    assert_eq!(
1344        Command::SetCaseAnalysis(SetCaseAnalysis {
1345            value: CaseValue::Falling,
1346            port_or_pin_list: Object::String(ObjectString {
1347                strings: vec![String::from("a")]
1348            }),
1349        }),
1350        ret
1351    );
1352    assert_eq!(tgt, format!("{}", ret));
1353}
1354
1355// -----------------------------------------------------------------------------
1356
1357/// A type containing information of `set_clock_gating_check`
1358#[derive(Clone, Debug, Default, PartialEq)]
1359pub struct SetClockGatingCheck {
1360    pub setup: Option<f64>,
1361    pub hold: Option<f64>,
1362    pub rise: bool,
1363    pub fall: bool,
1364    pub high: bool,
1365    pub low: bool,
1366    pub object_list: Option<Object>,
1367}
1368
1369impl fmt::Display for SetClockGatingCheck {
1370    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1371        let mut args = String::from("");
1372        if let Some(setup) = &self.setup {
1373            args.push_str(&format!(" -setup {}", setup));
1374        }
1375        if let Some(hold) = &self.hold {
1376            args.push_str(&format!(" -hold {}", hold));
1377        }
1378        if self.rise {
1379            args.push_str(" -rise");
1380        }
1381        if self.fall {
1382            args.push_str(" -fall");
1383        }
1384        if self.high {
1385            args.push_str(" -high");
1386        }
1387        if self.low {
1388            args.push_str(" -low");
1389        }
1390        if let Some(object_list) = &self.object_list {
1391            args.push_str(&format!(" {}", object_list));
1392        }
1393        write!(f, "set_clock_gating_check{}", args)
1394    }
1395}
1396
1397fn set_clock_gating_check<I>() -> impl Parser<Input = I, Output = Command>
1398where
1399    I: Stream<Item = char>,
1400    I::Error: ParseError<I::Item, I::Range, I::Position>,
1401{
1402    let command = symbol("set_clock_gating_check");
1403    let setup = symbol("-setup")
1404        .with(float())
1405        .map(|x| CommandArg::SetupVal(x));
1406    let hold = symbol("-hold")
1407        .with(float())
1408        .map(|x| CommandArg::HoldVal(x));
1409    let rise = symbol("-rise").map(|_| CommandArg::Rise);
1410    let fall = symbol("-fall").map(|_| CommandArg::Fall);
1411    let high = symbol("-high").map(|_| CommandArg::High);
1412    let low = symbol("-low").map(|_| CommandArg::Low);
1413    let object_list = parser(object).map(|x| CommandArg::Object(x));
1414    let args = (
1415        attempt(setup),
1416        attempt(hold),
1417        attempt(rise),
1418        attempt(fall),
1419        attempt(high),
1420        attempt(low),
1421        attempt(object_list),
1422    );
1423    command
1424        .with(many(choice(args)))
1425        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
1426            let mut setup = None;
1427            let mut hold = None;
1428            let mut rise = false;
1429            let mut fall = false;
1430            let mut high = false;
1431            let mut low = false;
1432            let mut object_list = None;
1433            for x in xs {
1434                match x {
1435                    CommandArg::SetupVal(x) => setup = Some(x),
1436                    CommandArg::HoldVal(x) => hold = Some(x),
1437                    CommandArg::Rise => rise = true,
1438                    CommandArg::Fall => fall = true,
1439                    CommandArg::High => high = true,
1440                    CommandArg::Low => low = true,
1441                    CommandArg::Object(x) => object_list = Some(x),
1442                    _ => unreachable!(),
1443                }
1444            }
1445            Ok(Command::SetClockGatingCheck(SetClockGatingCheck {
1446                setup,
1447                hold,
1448                rise,
1449                fall,
1450                high,
1451                low,
1452                object_list,
1453            }))
1454        })
1455}
1456
1457#[test]
1458fn test_set_clock_gating_check() {
1459    let mut parser = command();
1460    let tgt = "set_clock_gating_check -setup 1.2 -hold 0.5 -rise -fall -high -low a";
1461    let ret = parser.parse(tgt).unwrap().0;
1462    assert_eq!(
1463        Command::SetClockGatingCheck(SetClockGatingCheck {
1464            setup: Some(1.2),
1465            hold: Some(0.5),
1466            rise: true,
1467            fall: true,
1468            high: true,
1469            low: true,
1470            object_list: Some(Object::String(ObjectString {
1471                strings: vec![String::from("a")]
1472            })),
1473        }),
1474        ret
1475    );
1476    assert_eq!(tgt, format!("{}", ret));
1477}
1478
1479// -----------------------------------------------------------------------------
1480
1481/// A type containing information of `set_clock_groups`
1482#[derive(Clone, Debug, Default, PartialEq)]
1483pub struct SetClockGroups {
1484    pub group: Object,
1485    pub logically_exclusive: bool,
1486    pub physically_exclusive: bool,
1487    pub asynchronous: bool,
1488    pub allow_paths: bool,
1489    pub name: Option<String>,
1490    pub comment: Option<String>,
1491}
1492
1493impl fmt::Display for SetClockGroups {
1494    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1495        let mut args = String::from("");
1496        args.push_str(&format!(" -group {}", self.group));
1497        if self.logically_exclusive {
1498            args.push_str(" -logically_exclusive");
1499        }
1500        if self.physically_exclusive {
1501            args.push_str(" -physically_exclusive");
1502        }
1503        if self.asynchronous {
1504            args.push_str(" -asynchronous");
1505        }
1506        if self.allow_paths {
1507            args.push_str(" -allow_paths");
1508        }
1509        if let Some(name) = &self.name {
1510            args.push_str(&format!(" -name {}", name));
1511        }
1512        if let Some(comment) = &self.comment {
1513            args.push_str(&format!(" -comment \"{}\"", comment));
1514        }
1515        write!(f, "set_clock_groups{}", args)
1516    }
1517}
1518
1519fn set_clock_groups<I>() -> impl Parser<Input = I, Output = Command>
1520where
1521    I: Stream<Item = char>,
1522    I::Error: ParseError<I::Item, I::Range, I::Position>,
1523{
1524    let command = attempt(symbol("set_clock_groups")).or(symbol("set_clock_groups"));
1525    let group = symbol("-group")
1526        .with(parser(object))
1527        .map(|x| CommandArg::Group(x));
1528    let logically_exclusive =
1529        symbol("-logically_exclusive").map(|_| CommandArg::LogicallyExclusive);
1530    let physically_exclusive =
1531        symbol("-physically_exclusive").map(|_| CommandArg::PhysicallyExclusive);
1532    let asynchronous = symbol("-asynchronous").map(|_| CommandArg::Asynchronous);
1533    let allow_paths = symbol("-allow_paths").map(|_| CommandArg::AllowPaths);
1534    let name = symbol("-name").with(item()).map(|x| CommandArg::Name(x));
1535    let comment = symbol("-comment")
1536        .with(item())
1537        .map(|x| CommandArg::Comment(x));
1538    let args = (
1539        attempt(group),
1540        attempt(logically_exclusive),
1541        attempt(physically_exclusive),
1542        attempt(asynchronous),
1543        attempt(allow_paths),
1544        attempt(name),
1545        attempt(comment),
1546    );
1547    command
1548        .with(many(choice(args)))
1549        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
1550            let mut group = None;
1551            let mut logically_exclusive = false;
1552            let mut physically_exclusive = false;
1553            let mut asynchronous = false;
1554            let mut allow_paths = false;
1555            let mut name = None;
1556            let mut comment = None;
1557            for x in xs {
1558                match x {
1559                    CommandArg::Group(x) => group = Some(x),
1560                    CommandArg::LogicallyExclusive => logically_exclusive = true,
1561                    CommandArg::PhysicallyExclusive => physically_exclusive = true,
1562                    CommandArg::Asynchronous => asynchronous = true,
1563                    CommandArg::AllowPaths => allow_paths = true,
1564                    CommandArg::Name(x) => name = Some(x),
1565                    CommandArg::Comment(x) => comment = Some(x),
1566                    _ => unreachable!(),
1567                }
1568            }
1569            let group = group.ok_or(AndThenError::<I>::message_static_message(
1570                "set_clock_groups:group",
1571            ))?;
1572            Ok(Command::SetClockGroups(SetClockGroups {
1573                group,
1574                logically_exclusive,
1575                physically_exclusive,
1576                asynchronous,
1577                allow_paths,
1578                name,
1579                comment,
1580            }))
1581        })
1582}
1583
1584#[test]
1585fn test_set_clock_groups() {
1586    let mut parser = command();
1587    let tgt = "set_clock_groups -group clk -logically_exclusive -physically_exclusive -asynchronous -allow_paths -name clk -comment \"aaa\"";
1588    let ret = parser.parse(tgt).unwrap().0;
1589    assert_eq!(
1590        Command::SetClockGroups(SetClockGroups {
1591            group: Object::String(ObjectString {
1592                strings: vec![String::from("clk")]
1593            }),
1594            logically_exclusive: true,
1595            physically_exclusive: true,
1596            asynchronous: true,
1597            allow_paths: true,
1598            name: Some(String::from("clk")),
1599            comment: Some(String::from("aaa")),
1600        }),
1601        ret
1602    );
1603    assert_eq!(tgt, format!("{}", ret));
1604}
1605
1606// -----------------------------------------------------------------------------
1607
1608/// A type containing information of `set_clock_latency`
1609#[derive(Clone, Debug, Default, PartialEq)]
1610pub struct SetClockLatency {
1611    pub rise: bool,
1612    pub fall: bool,
1613    pub min: bool,
1614    pub max: bool,
1615    pub source: bool,
1616    pub dynamic: bool,
1617    pub late: bool,
1618    pub early: bool,
1619    pub clock: Option<Object>,
1620    pub delay: f64,
1621    pub object_list: Object,
1622}
1623
1624impl fmt::Display for SetClockLatency {
1625    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1626        let mut args = String::from("");
1627        if self.rise {
1628            args.push_str(" -rise");
1629        }
1630        if self.fall {
1631            args.push_str(" -fall");
1632        }
1633        if self.min {
1634            args.push_str(" -min");
1635        }
1636        if self.max {
1637            args.push_str(" -max");
1638        }
1639        if self.source {
1640            args.push_str(" -source");
1641        }
1642        if self.dynamic {
1643            args.push_str(" -dynamic");
1644        }
1645        if self.late {
1646            args.push_str(" -late");
1647        }
1648        if self.early {
1649            args.push_str(" -early");
1650        }
1651        if let Some(clock) = &self.clock {
1652            args.push_str(&format!(" -clock {}", clock));
1653        }
1654        args.push_str(&format!(" {}", self.delay));
1655        args.push_str(&format!(" {}", self.object_list));
1656        write!(f, "set_clock_latency{}", args)
1657    }
1658}
1659
1660fn set_clock_latency<I>() -> impl Parser<Input = I, Output = Command>
1661where
1662    I: Stream<Item = char>,
1663    I::Error: ParseError<I::Item, I::Range, I::Position>,
1664{
1665    let command = symbol("set_clock_latency");
1666    let rise = symbol("-rise").map(|_| CommandArg::Rise);
1667    let fall = symbol("-fall").map(|_| CommandArg::Fall);
1668    let min = symbol("-min").map(|_| CommandArg::Min);
1669    let max = symbol("-max").map(|_| CommandArg::Max);
1670    let source = symbol("-source").map(|_| CommandArg::Source);
1671    let dynamic = symbol("-dynamic").map(|_| CommandArg::Dynamic);
1672    let late = symbol("-late").map(|_| CommandArg::Late);
1673    let early = symbol("-early").map(|_| CommandArg::Early);
1674    let clock = symbol("-clock")
1675        .with(parser(object))
1676        .map(|x| CommandArg::ClockObj(x));
1677    let delay = float().map(|x| CommandArg::Value(x));
1678    let object_list = parser(object).map(|x| CommandArg::Object(x));
1679    let args = (
1680        attempt(rise),
1681        attempt(fall),
1682        attempt(min),
1683        attempt(max),
1684        attempt(source),
1685        attempt(dynamic),
1686        attempt(late),
1687        attempt(early),
1688        attempt(clock),
1689        attempt(delay),
1690        attempt(object_list),
1691    );
1692    command
1693        .with(many(choice(args)))
1694        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
1695            let mut rise = false;
1696            let mut fall = false;
1697            let mut min = false;
1698            let mut max = false;
1699            let mut source = false;
1700            let mut dynamic = false;
1701            let mut late = false;
1702            let mut early = false;
1703            let mut delay = None;
1704            let mut clock = None;
1705            let mut object_list = None;
1706            for x in xs {
1707                match x {
1708                    CommandArg::Rise => rise = true,
1709                    CommandArg::Fall => fall = true,
1710                    CommandArg::Min => min = true,
1711                    CommandArg::Max => max = true,
1712                    CommandArg::Source => source = true,
1713                    CommandArg::Dynamic => dynamic = true,
1714                    CommandArg::Late => late = true,
1715                    CommandArg::Early => early = true,
1716                    CommandArg::ClockObj(x) => clock = Some(x),
1717                    CommandArg::Value(x) => delay = Some(x),
1718                    CommandArg::Object(x) => object_list = Some(x),
1719                    _ => unreachable!(),
1720                }
1721            }
1722            let delay = delay.ok_or(AndThenError::<I>::message_static_message(
1723                "set_clock_latency:delay",
1724            ))?;
1725            let object_list = object_list.ok_or(AndThenError::<I>::message_static_message(
1726                "set_clock_latency:object_list",
1727            ))?;
1728            Ok(Command::SetClockLatency(SetClockLatency {
1729                rise,
1730                fall,
1731                min,
1732                max,
1733                source,
1734                dynamic,
1735                late,
1736                early,
1737                clock,
1738                delay,
1739                object_list,
1740            }))
1741        })
1742}
1743
1744#[test]
1745fn test_set_clock_latency() {
1746    let mut parser = command();
1747    let tgt =
1748        "set_clock_latency -rise -fall -min -max -source -dynamic -late -early -clock clk 0.12 obj";
1749    let ret = parser.parse(tgt).unwrap().0;
1750    assert_eq!(
1751        Command::SetClockLatency(SetClockLatency {
1752            rise: true,
1753            fall: true,
1754            min: true,
1755            max: true,
1756            source: true,
1757            dynamic: true,
1758            late: true,
1759            early: true,
1760            clock: Some(Object::String(ObjectString {
1761                strings: vec![String::from("clk")]
1762            })),
1763            delay: 0.12,
1764            object_list: Object::String(ObjectString {
1765                strings: vec![String::from("obj")]
1766            }),
1767        }),
1768        ret
1769    );
1770    assert_eq!(tgt, format!("{}", ret));
1771}
1772
1773// -----------------------------------------------------------------------------
1774
1775/// A type containing information of `set_clock_sense`
1776#[derive(Clone, Debug, Default, PartialEq)]
1777pub struct SetClockSense {
1778    pub positive: bool,
1779    pub negative: bool,
1780    pub stop_propagation: bool,
1781    pub pulse: Option<String>,
1782    pub clocks: Option<Object>,
1783    pub pin_list: Object,
1784}
1785
1786impl fmt::Display for SetClockSense {
1787    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1788        let mut args = String::from("");
1789        if self.positive {
1790            args.push_str(" -positive");
1791        }
1792        if self.negative {
1793            args.push_str(" -negative");
1794        }
1795        if self.stop_propagation {
1796            args.push_str(" -stop_propagation");
1797        }
1798        if let Some(pulse) = &self.pulse {
1799            args.push_str(&format!(" -pulse {}", pulse));
1800        }
1801        if let Some(clocks) = &self.clocks {
1802            args.push_str(&format!(" -clocks {}", clocks));
1803        }
1804        args.push_str(&format!(" {}", self.pin_list));
1805        write!(f, "set_clock_sense{}", args)
1806    }
1807}
1808
1809fn set_clock_sense<I>() -> impl Parser<Input = I, Output = Command>
1810where
1811    I: Stream<Item = char>,
1812    I::Error: ParseError<I::Item, I::Range, I::Position>,
1813{
1814    let command = symbol("set_clock_sense");
1815    let positive = symbol("-positive").map(|_| CommandArg::Positive);
1816    let negative = symbol("-negative").map(|_| CommandArg::Negative);
1817    let stop_propagation = symbol("-stop_propagation").map(|_| CommandArg::StopPropagation);
1818    let pulse = symbol("-pulse").with(item()).map(|x| CommandArg::Pulse(x));
1819    let clocks = symbol("-clocks")
1820        .with(parser(object))
1821        .map(|x| CommandArg::Clocks(x));
1822    let pin_list = parser(object).map(|x| CommandArg::Object(x));
1823    let args = (
1824        attempt(positive),
1825        attempt(negative),
1826        attempt(stop_propagation),
1827        attempt(pulse),
1828        attempt(clocks),
1829        attempt(pin_list),
1830    );
1831    command
1832        .with(many(choice(args)))
1833        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
1834            let mut positive = false;
1835            let mut negative = false;
1836            let mut stop_propagation = false;
1837            let mut pulse = None;
1838            let mut clocks = None;
1839            let mut pin_list = None;
1840            for x in xs {
1841                match x {
1842                    CommandArg::Positive => positive = true,
1843                    CommandArg::Negative => negative = true,
1844                    CommandArg::StopPropagation => stop_propagation = true,
1845                    CommandArg::Pulse(x) => pulse = Some(x),
1846                    CommandArg::Clocks(x) => clocks = Some(x),
1847                    CommandArg::Object(x) => pin_list = Some(x),
1848                    _ => unreachable!(),
1849                }
1850            }
1851            let pin_list = pin_list.ok_or(AndThenError::<I>::message_static_message(
1852                "set_clock_sense:pin_list is required",
1853            ))?;
1854            Ok(Command::SetClockSense(SetClockSense {
1855                positive,
1856                negative,
1857                stop_propagation,
1858                pulse,
1859                clocks,
1860                pin_list,
1861            }))
1862        })
1863}
1864
1865#[test]
1866fn test_set_clock_sense() {
1867    let mut parser = command();
1868    let tgt = "set_clock_sense -positive -negative -stop_propagation -pulse a -clocks clk pin";
1869    let ret = parser.parse(tgt).unwrap().0;
1870    assert_eq!(
1871        Command::SetClockSense(SetClockSense {
1872            positive: true,
1873            negative: true,
1874            stop_propagation: true,
1875            pulse: Some(String::from("a")),
1876            clocks: Some(Object::String(ObjectString {
1877                strings: vec![String::from("clk")]
1878            })),
1879            pin_list: Object::String(ObjectString {
1880                strings: vec![String::from("pin")]
1881            }),
1882        }),
1883        ret
1884    );
1885    assert_eq!(tgt, format!("{}", ret));
1886}
1887
1888// -----------------------------------------------------------------------------
1889
1890/// A type containing information of `set_clock_transition`
1891#[derive(Clone, Debug, Default, PartialEq)]
1892pub struct SetClockTransition {
1893    pub rise: bool,
1894    pub fall: bool,
1895    pub min: bool,
1896    pub max: bool,
1897    pub transition: f64,
1898    pub clock_list: Object,
1899}
1900
1901impl fmt::Display for SetClockTransition {
1902    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1903        let mut args = String::from("");
1904        if self.rise {
1905            args.push_str(" -rise");
1906        }
1907        if self.fall {
1908            args.push_str(" -fall");
1909        }
1910        if self.min {
1911            args.push_str(" -min");
1912        }
1913        if self.max {
1914            args.push_str(" -max");
1915        }
1916        args.push_str(&format!(" {}", self.transition));
1917        args.push_str(&format!(" {}", self.clock_list));
1918        write!(f, "set_clock_transition{}", args)
1919    }
1920}
1921
1922fn set_clock_transition<I>() -> impl Parser<Input = I, Output = Command>
1923where
1924    I: Stream<Item = char>,
1925    I::Error: ParseError<I::Item, I::Range, I::Position>,
1926{
1927    let command = symbol("set_clock_transition");
1928    let rise = symbol("-rise").map(|_| CommandArg::Rise);
1929    let fall = symbol("-fall").map(|_| CommandArg::Fall);
1930    let min = symbol("-min").map(|_| CommandArg::Min);
1931    let max = symbol("-max").map(|_| CommandArg::Max);
1932    let transition = float().map(|x| CommandArg::Value(x));
1933    let clock_list = parser(object).map(|x| CommandArg::Object(x));
1934    let args = (
1935        attempt(rise),
1936        attempt(fall),
1937        attempt(min),
1938        attempt(max),
1939        attempt(transition),
1940        attempt(clock_list),
1941    );
1942    command
1943        .with(many(choice(args)))
1944        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
1945            let mut rise = false;
1946            let mut fall = false;
1947            let mut min = false;
1948            let mut max = false;
1949            let mut transition = None;
1950            let mut clock_list = None;
1951            for x in xs {
1952                match x {
1953                    CommandArg::Rise => rise = true,
1954                    CommandArg::Fall => fall = true,
1955                    CommandArg::Min => min = true,
1956                    CommandArg::Max => max = true,
1957                    CommandArg::Value(x) => transition = Some(x),
1958                    CommandArg::Object(x) => clock_list = Some(x),
1959                    _ => unreachable!(),
1960                }
1961            }
1962            let transition = transition.ok_or(AndThenError::<I>::message_static_message(
1963                "set_clock_transition:transition",
1964            ))?;
1965            let clock_list = clock_list.ok_or(AndThenError::<I>::message_static_message(
1966                "set_clock_transition:clock_list",
1967            ))?;
1968            Ok(Command::SetClockTransition(SetClockTransition {
1969                rise,
1970                fall,
1971                min,
1972                max,
1973                transition,
1974                clock_list,
1975            }))
1976        })
1977}
1978
1979#[test]
1980fn test_set_clock_transition() {
1981    let mut parser = command();
1982    let tgt = "set_clock_transition -rise -fall -min -max 0.012 clk";
1983    let ret = parser.parse(tgt).unwrap().0;
1984    assert_eq!(
1985        Command::SetClockTransition(SetClockTransition {
1986            rise: true,
1987            fall: true,
1988            min: true,
1989            max: true,
1990            transition: 12e-3,
1991            clock_list: Object::String(ObjectString {
1992                strings: vec![String::from("clk")]
1993            }),
1994        }),
1995        ret
1996    );
1997    assert_eq!(tgt, format!("{}", ret));
1998}
1999
2000// -----------------------------------------------------------------------------
2001
2002/// A type containing information of `set_clock_uncertainty`
2003#[derive(Clone, Debug, Default, PartialEq)]
2004pub struct SetClockUncertainty {
2005    pub from: Option<Object>,
2006    pub rise_from: Option<Object>,
2007    pub fall_from: Option<Object>,
2008    pub to: Option<Object>,
2009    pub rise_to: Option<Object>,
2010    pub fall_to: Option<Object>,
2011    pub rise: bool,
2012    pub fall: bool,
2013    pub setup: bool,
2014    pub hold: bool,
2015    pub uncertainty: f64,
2016    pub object_list: Option<Object>,
2017}
2018
2019impl fmt::Display for SetClockUncertainty {
2020    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2021        let mut args = String::from("");
2022        if let Some(from) = &self.from {
2023            args.push_str(&format!(" -from {}", from));
2024        }
2025        if let Some(rise_from) = &self.rise_from {
2026            args.push_str(&format!(" -rise_from {}", rise_from));
2027        }
2028        if let Some(fall_from) = &self.fall_from {
2029            args.push_str(&format!(" -fall_from {}", fall_from));
2030        }
2031        if let Some(to) = &self.to {
2032            args.push_str(&format!(" -to {}", to));
2033        }
2034        if let Some(rise_to) = &self.rise_to {
2035            args.push_str(&format!(" -rise_to {}", rise_to));
2036        }
2037        if let Some(fall_to) = &self.fall_to {
2038            args.push_str(&format!(" -fall_to {}", fall_to));
2039        }
2040        if self.rise {
2041            args.push_str(" -rise");
2042        }
2043        if self.fall {
2044            args.push_str(" -fall");
2045        }
2046        if self.setup {
2047            args.push_str(" -setup");
2048        }
2049        if self.hold {
2050            args.push_str(" -hold");
2051        }
2052        args.push_str(&format!(" {}", self.uncertainty));
2053        if let Some(object_list) = &self.object_list {
2054            args.push_str(&format!(" {}", object_list));
2055        }
2056        write!(f, "set_clock_uncertainty{}", args)
2057    }
2058}
2059
2060fn set_clock_uncertainty<I>() -> impl Parser<Input = I, Output = Command>
2061where
2062    I: Stream<Item = char>,
2063    I::Error: ParseError<I::Item, I::Range, I::Position>,
2064{
2065    let command = symbol("set_clock_uncertainty");
2066    let from = symbol("-from")
2067        .with(parser(object))
2068        .map(|x| CommandArg::From(x));
2069    let rise_from = symbol("-rise_from")
2070        .with(parser(object))
2071        .map(|x| CommandArg::RiseFrom(x));
2072    let fall_from = symbol("-fall_from")
2073        .with(parser(object))
2074        .map(|x| CommandArg::FallFrom(x));
2075    let to = symbol("-to")
2076        .with(parser(object))
2077        .map(|x| CommandArg::To(x));
2078    let rise_to = symbol("-rise_to")
2079        .with(parser(object))
2080        .map(|x| CommandArg::RiseTo(x));
2081    let fall_to = symbol("-fall_to")
2082        .with(parser(object))
2083        .map(|x| CommandArg::FallTo(x));
2084    let rise = symbol("-rise").map(|_| CommandArg::Rise);
2085    let fall = symbol("-fall").map(|_| CommandArg::Fall);
2086    let setup = symbol("-setup").map(|_| CommandArg::Setup);
2087    let hold = symbol("-hold").map(|_| CommandArg::Hold);
2088    let uncertainty = float().map(|x| CommandArg::Value(x));
2089    let object_list = parser(object).map(|x| CommandArg::Object(x));
2090    let args = (
2091        attempt(from),
2092        attempt(rise_from),
2093        attempt(fall_from),
2094        attempt(to),
2095        attempt(rise_to),
2096        attempt(fall_to),
2097        attempt(rise),
2098        attempt(fall),
2099        attempt(setup),
2100        attempt(hold),
2101        attempt(uncertainty),
2102        attempt(object_list),
2103    );
2104    command
2105        .with(many(choice(args)))
2106        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
2107            let mut from = None;
2108            let mut rise_from = None;
2109            let mut fall_from = None;
2110            let mut to = None;
2111            let mut rise_to = None;
2112            let mut fall_to = None;
2113            let mut rise = false;
2114            let mut fall = false;
2115            let mut setup = false;
2116            let mut hold = false;
2117            let mut uncertainty = None;
2118            let mut object_list = None;
2119            for x in xs {
2120                match x {
2121                    CommandArg::From(x) => from = Some(x),
2122                    CommandArg::RiseFrom(x) => rise_from = Some(x),
2123                    CommandArg::FallFrom(x) => fall_from = Some(x),
2124                    CommandArg::To(x) => to = Some(x),
2125                    CommandArg::RiseTo(x) => rise_to = Some(x),
2126                    CommandArg::FallTo(x) => fall_to = Some(x),
2127                    CommandArg::Rise => rise = true,
2128                    CommandArg::Fall => fall = true,
2129                    CommandArg::Setup => setup = true,
2130                    CommandArg::Hold => hold = true,
2131                    CommandArg::Value(x) => uncertainty = Some(x),
2132                    CommandArg::Object(x) => object_list = Some(x),
2133                    _ => unreachable!(),
2134                }
2135            }
2136            let uncertainty = uncertainty.ok_or(AndThenError::<I>::message_static_message(
2137                "set_clock_uncertainty:uncertainty",
2138            ))?;
2139            Ok(Command::SetClockUncertainty(SetClockUncertainty {
2140                from,
2141                rise_from,
2142                fall_from,
2143                to,
2144                rise_to,
2145                fall_to,
2146                rise,
2147                fall,
2148                setup,
2149                hold,
2150                uncertainty,
2151                object_list,
2152            }))
2153        })
2154}
2155
2156#[test]
2157fn test_set_clock_uncertainty() {
2158    let mut parser = command();
2159    let tgt = "set_clock_uncertainty -from a -rise_from a -fall_from a -to a -rise_to a -fall_to a -rise -fall -setup -hold 0.1 a";
2160    let ret = parser.parse(tgt).unwrap().0;
2161    assert_eq!(
2162        Command::SetClockUncertainty(SetClockUncertainty {
2163            from: Some(Object::String(ObjectString {
2164                strings: vec![String::from("a")]
2165            })),
2166            rise_from: Some(Object::String(ObjectString {
2167                strings: vec![String::from("a")]
2168            })),
2169            fall_from: Some(Object::String(ObjectString {
2170                strings: vec![String::from("a")]
2171            })),
2172            to: Some(Object::String(ObjectString {
2173                strings: vec![String::from("a")]
2174            })),
2175            rise_to: Some(Object::String(ObjectString {
2176                strings: vec![String::from("a")]
2177            })),
2178            fall_to: Some(Object::String(ObjectString {
2179                strings: vec![String::from("a")]
2180            })),
2181            rise: true,
2182            fall: true,
2183            setup: true,
2184            hold: true,
2185            uncertainty: 0.1,
2186            object_list: Some(Object::String(ObjectString {
2187                strings: vec![String::from("a")]
2188            })),
2189        }),
2190        ret
2191    );
2192    assert_eq!(tgt, format!("{}", ret));
2193}
2194
2195// -----------------------------------------------------------------------------
2196
2197/// A type containing information of `set_data_check`
2198#[derive(Clone, Debug, Default, PartialEq)]
2199pub struct SetDataCheck {
2200    pub from: Option<Object>,
2201    pub to: Option<Object>,
2202    pub rise_from: Option<Object>,
2203    pub fall_from: Option<Object>,
2204    pub rise_to: Option<Object>,
2205    pub fall_to: Option<Object>,
2206    pub setup: bool,
2207    pub hold: bool,
2208    pub clock: Option<Object>,
2209    pub value: f64,
2210}
2211
2212impl fmt::Display for SetDataCheck {
2213    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2214        let mut args = String::from("");
2215        if let Some(from) = &self.from {
2216            args.push_str(&format!(" -from {}", from));
2217        }
2218        if let Some(to) = &self.to {
2219            args.push_str(&format!(" -to {}", to));
2220        }
2221        if let Some(rise_from) = &self.rise_from {
2222            args.push_str(&format!(" -rise_from {}", rise_from));
2223        }
2224        if let Some(fall_from) = &self.fall_from {
2225            args.push_str(&format!(" -fall_from {}", fall_from));
2226        }
2227        if let Some(rise_to) = &self.rise_to {
2228            args.push_str(&format!(" -rise_to {}", rise_to));
2229        }
2230        if let Some(fall_to) = &self.fall_to {
2231            args.push_str(&format!(" -fall_to {}", fall_to));
2232        }
2233        if self.setup {
2234            args.push_str(" -setup");
2235        }
2236        if self.hold {
2237            args.push_str(" -hold");
2238        }
2239        if let Some(clock) = &self.clock {
2240            args.push_str(&format!(" -clock {}", clock));
2241        }
2242        args.push_str(&format!(" {}", self.value));
2243        write!(f, "set_data_check{}", args)
2244    }
2245}
2246
2247fn set_data_check<I>() -> impl Parser<Input = I, Output = Command>
2248where
2249    I: Stream<Item = char>,
2250    I::Error: ParseError<I::Item, I::Range, I::Position>,
2251{
2252    let command = symbol("set_data_check");
2253    let from = symbol("-from")
2254        .with(parser(object))
2255        .map(|x| CommandArg::From(x));
2256    let to = symbol("-to")
2257        .with(parser(object))
2258        .map(|x| CommandArg::To(x));
2259    let rise_from = symbol("-rise_from")
2260        .with(parser(object))
2261        .map(|x| CommandArg::RiseFrom(x));
2262    let fall_from = symbol("-fall_from")
2263        .with(parser(object))
2264        .map(|x| CommandArg::FallFrom(x));
2265    let rise_to = symbol("-rise_to")
2266        .with(parser(object))
2267        .map(|x| CommandArg::RiseTo(x));
2268    let fall_to = symbol("-fall_to")
2269        .with(parser(object))
2270        .map(|x| CommandArg::FallTo(x));
2271    let setup = symbol("-setup").map(|_| CommandArg::Setup);
2272    let hold = symbol("-hold").map(|_| CommandArg::Hold);
2273    let clock = symbol("-clock")
2274        .with(parser(object))
2275        .map(|x| CommandArg::ClockObj(x));
2276    let value = float().map(|x| CommandArg::Value(x));
2277    let args = (
2278        attempt(from),
2279        attempt(to),
2280        attempt(rise_from),
2281        attempt(fall_from),
2282        attempt(rise_to),
2283        attempt(fall_to),
2284        attempt(setup),
2285        attempt(hold),
2286        attempt(clock),
2287        attempt(value),
2288    );
2289    command
2290        .with(many(choice(args)))
2291        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
2292            let mut from = None;
2293            let mut to = None;
2294            let mut rise_from = None;
2295            let mut fall_from = None;
2296            let mut rise_to = None;
2297            let mut fall_to = None;
2298            let mut setup = false;
2299            let mut hold = false;
2300            let mut clock = None;
2301            let mut value = None;
2302            for x in xs {
2303                match x {
2304                    CommandArg::From(x) => from = Some(x),
2305                    CommandArg::To(x) => to = Some(x),
2306                    CommandArg::RiseFrom(x) => rise_from = Some(x),
2307                    CommandArg::FallFrom(x) => fall_from = Some(x),
2308                    CommandArg::RiseTo(x) => rise_to = Some(x),
2309                    CommandArg::FallTo(x) => fall_to = Some(x),
2310                    CommandArg::Setup => setup = true,
2311                    CommandArg::Hold => hold = true,
2312                    CommandArg::ClockObj(x) => clock = Some(x),
2313                    CommandArg::Value(x) => value = Some(x),
2314                    _ => unreachable!(),
2315                }
2316            }
2317            let value = value.ok_or(AndThenError::<I>::message_static_message(
2318                "set_data_check:value",
2319            ))?;
2320            Ok(Command::SetDataCheck(SetDataCheck {
2321                from,
2322                to,
2323                rise_from,
2324                fall_from,
2325                rise_to,
2326                fall_to,
2327                setup,
2328                hold,
2329                clock,
2330                value,
2331            }))
2332        })
2333}
2334
2335#[test]
2336fn test_set_data_check() {
2337    let mut parser = command();
2338    let tgt = "set_data_check -from a -to a -rise_from a -fall_from a -rise_to a -fall_to a -setup -hold -clock a 0.1";
2339    let ret = parser.parse(tgt).unwrap().0;
2340    assert_eq!(
2341        Command::SetDataCheck(SetDataCheck {
2342            from: Some(Object::String(ObjectString {
2343                strings: vec![String::from("a")]
2344            })),
2345            to: Some(Object::String(ObjectString {
2346                strings: vec![String::from("a")]
2347            })),
2348            rise_from: Some(Object::String(ObjectString {
2349                strings: vec![String::from("a")]
2350            })),
2351            fall_from: Some(Object::String(ObjectString {
2352                strings: vec![String::from("a")]
2353            })),
2354            rise_to: Some(Object::String(ObjectString {
2355                strings: vec![String::from("a")]
2356            })),
2357            fall_to: Some(Object::String(ObjectString {
2358                strings: vec![String::from("a")]
2359            })),
2360            setup: true,
2361            hold: true,
2362            clock: Some(Object::String(ObjectString {
2363                strings: vec![String::from("a")]
2364            })),
2365            value: 0.1,
2366        }),
2367        ret
2368    );
2369    assert_eq!(tgt, format!("{}", ret));
2370}
2371
2372// -----------------------------------------------------------------------------
2373
2374/// A type containing information of `set_disable_timing`
2375#[derive(Clone, Debug, Default, PartialEq)]
2376pub struct SetDisableTiming {
2377    pub from: Option<Object>,
2378    pub to: Option<Object>,
2379    pub cell_pin_list: Object,
2380}
2381
2382impl fmt::Display for SetDisableTiming {
2383    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2384        let mut args = String::from("");
2385        if let Some(from) = &self.from {
2386            args.push_str(&format!(" -from {}", from));
2387        }
2388        if let Some(to) = &self.to {
2389            args.push_str(&format!(" -to {}", to));
2390        }
2391        args.push_str(&format!(" {}", self.cell_pin_list));
2392        write!(f, "set_disable_timing{}", args)
2393    }
2394}
2395
2396fn set_disable_timing<I>() -> impl Parser<Input = I, Output = Command>
2397where
2398    I: Stream<Item = char>,
2399    I::Error: ParseError<I::Item, I::Range, I::Position>,
2400{
2401    let command = symbol("set_disable_timing");
2402    let from = symbol("-from")
2403        .with(parser(object))
2404        .map(|x| CommandArg::From(x));
2405    let to = symbol("-to")
2406        .with(parser(object))
2407        .map(|x| CommandArg::To(x));
2408    let cell_pin_list = parser(object).map(|x| CommandArg::Object(x));
2409    let args = (attempt(from), attempt(to), attempt(cell_pin_list));
2410    command
2411        .with(many(choice(args)))
2412        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
2413            let mut from = None;
2414            let mut to = None;
2415            let mut cell_pin_list = None;
2416            for x in xs {
2417                match x {
2418                    CommandArg::From(x) => from = Some(x),
2419                    CommandArg::To(x) => to = Some(x),
2420                    CommandArg::Object(x) => cell_pin_list = Some(x),
2421                    _ => unreachable!(),
2422                }
2423            }
2424            let cell_pin_list = cell_pin_list.ok_or(AndThenError::<I>::message_static_message(
2425                "set_disable_timing:cell_pin_list",
2426            ))?;
2427            Ok(Command::SetDisableTiming(SetDisableTiming {
2428                from,
2429                to,
2430                cell_pin_list,
2431            }))
2432        })
2433}
2434
2435#[test]
2436fn test_set_disable_timing() {
2437    let mut parser = command();
2438    let tgt = "set_disable_timing -from a -to a a";
2439    let ret = parser.parse(tgt).unwrap().0;
2440    assert_eq!(
2441        Command::SetDisableTiming(SetDisableTiming {
2442            from: Some(Object::String(ObjectString {
2443                strings: vec![String::from("a")]
2444            })),
2445            to: Some(Object::String(ObjectString {
2446                strings: vec![String::from("a")]
2447            })),
2448            cell_pin_list: Object::String(ObjectString {
2449                strings: vec![String::from("a")]
2450            }),
2451        }),
2452        ret
2453    );
2454    assert_eq!(tgt, format!("{}", ret));
2455}
2456
2457// -----------------------------------------------------------------------------
2458
2459/// A type containing information of `set_drive`
2460#[derive(Clone, Debug, Default, PartialEq)]
2461pub struct SetDrive {
2462    pub rise: bool,
2463    pub fall: bool,
2464    pub min: bool,
2465    pub max: bool,
2466    pub resistance: f64,
2467    pub port_list: Object,
2468}
2469
2470impl fmt::Display for SetDrive {
2471    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2472        let mut args = String::from("");
2473        if self.rise {
2474            args.push_str(" -rise");
2475        }
2476        if self.fall {
2477            args.push_str(" -fall");
2478        }
2479        if self.min {
2480            args.push_str(" -min");
2481        }
2482        if self.max {
2483            args.push_str(" -max");
2484        }
2485        args.push_str(&format!(" {}", self.resistance));
2486        args.push_str(&format!(" {}", self.port_list));
2487        write!(f, "set_drive{}", args)
2488    }
2489}
2490
2491fn set_drive<I>() -> impl Parser<Input = I, Output = Command>
2492where
2493    I: Stream<Item = char>,
2494    I::Error: ParseError<I::Item, I::Range, I::Position>,
2495{
2496    let command = symbol("set_drive");
2497    let rise = symbol("-rise").map(|_| CommandArg::Rise);
2498    let fall = symbol("-fall").map(|_| CommandArg::Fall);
2499    let min = symbol("-min").map(|_| CommandArg::Min);
2500    let max = symbol("-max").map(|_| CommandArg::Max);
2501    let resistance = float().map(|x| CommandArg::Value(x));
2502    let port_list = parser(object).map(|x| CommandArg::Object(x));
2503    let args = (
2504        attempt(rise),
2505        attempt(fall),
2506        attempt(min),
2507        attempt(max),
2508        attempt(resistance),
2509        attempt(port_list),
2510    );
2511    command
2512        .with(many(choice(args)))
2513        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
2514            let mut rise = false;
2515            let mut fall = false;
2516            let mut min = false;
2517            let mut max = false;
2518            let mut resistance = None;
2519            let mut port_list = None;
2520            for x in xs {
2521                match x {
2522                    CommandArg::Rise => rise = true,
2523                    CommandArg::Fall => fall = true,
2524                    CommandArg::Min => min = true,
2525                    CommandArg::Max => max = true,
2526                    CommandArg::Value(x) => resistance = Some(x),
2527                    CommandArg::Object(x) => port_list = Some(x),
2528                    _ => unreachable!(),
2529                }
2530            }
2531            let resistance = resistance.ok_or(AndThenError::<I>::message_static_message(
2532                "set_drive:resistance",
2533            ))?;
2534            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
2535                "set_drive:port_list",
2536            ))?;
2537            Ok(Command::SetDrive(SetDrive {
2538                rise,
2539                fall,
2540                min,
2541                max,
2542                resistance,
2543                port_list,
2544            }))
2545        })
2546}
2547
2548#[test]
2549fn test_set_drive() {
2550    let mut parser = command();
2551    let tgt = "set_drive -rise -fall -min -max 0.1 a";
2552    let ret = parser.parse(tgt).unwrap().0;
2553    assert_eq!(
2554        Command::SetDrive(SetDrive {
2555            rise: true,
2556            fall: true,
2557            min: true,
2558            max: true,
2559            resistance: 0.1,
2560            port_list: Object::String(ObjectString {
2561                strings: vec![String::from("a")]
2562            }),
2563        }),
2564        ret
2565    );
2566    assert_eq!(tgt, format!("{}", ret));
2567}
2568
2569// -----------------------------------------------------------------------------
2570
2571/// A type containing information of `set_driving_cell`
2572#[derive(Clone, Debug, Default, PartialEq)]
2573pub struct SetDrivingCell {
2574    pub lib_cell: Option<Object>,
2575    pub rise: bool,
2576    pub fall: bool,
2577    pub min: bool,
2578    pub max: bool,
2579    pub library: Option<Object>,
2580    pub pin: Option<Object>,
2581    pub from_pin: Option<Object>,
2582    pub dont_scale: bool,
2583    pub no_design_rule: bool,
2584    pub clock: Option<Object>,
2585    pub clock_fall: bool,
2586    pub input_transition_rise: Option<f64>,
2587    pub input_transition_fall: Option<f64>,
2588    pub multiply_by: Option<f64>,
2589    pub port_list: Object,
2590}
2591
2592impl fmt::Display for SetDrivingCell {
2593    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2594        let mut args = String::from("");
2595        if let Some(lib_cell) = &self.lib_cell {
2596            args.push_str(&format!(" -lib_cell {}", lib_cell));
2597        }
2598        if self.rise {
2599            args.push_str(" -rise");
2600        }
2601        if self.fall {
2602            args.push_str(" -fall");
2603        }
2604        if self.min {
2605            args.push_str(" -min");
2606        }
2607        if self.max {
2608            args.push_str(" -max");
2609        }
2610        if let Some(library) = &self.library {
2611            args.push_str(&format!(" -library {}", library));
2612        }
2613        if let Some(pin) = &self.pin {
2614            args.push_str(&format!(" -pin {}", pin));
2615        }
2616        if let Some(from_pin) = &self.from_pin {
2617            args.push_str(&format!(" -from_pin {}", from_pin));
2618        }
2619        if self.dont_scale {
2620            args.push_str(" -dont_scale");
2621        }
2622        if self.no_design_rule {
2623            args.push_str(" -no_design_rule");
2624        }
2625        if let Some(clock) = &self.clock {
2626            args.push_str(&format!(" -clock {}", clock));
2627        }
2628        if self.clock_fall {
2629            args.push_str(" -clock_fall");
2630        }
2631        if let Some(input_transition_rise) = &self.input_transition_rise {
2632            args.push_str(&format!(
2633                " -input_transition_rise {}",
2634                input_transition_rise
2635            ));
2636        }
2637        if let Some(input_transition_fall) = &self.input_transition_fall {
2638            args.push_str(&format!(
2639                " -input_transition_fall {}",
2640                input_transition_fall
2641            ));
2642        }
2643        if let Some(multiply_by) = &self.multiply_by {
2644            args.push_str(&format!(" -multiply_by {}", multiply_by));
2645        }
2646        args.push_str(&format!(" {}", self.port_list));
2647        write!(f, "set_driving_cell{}", args)
2648    }
2649}
2650
2651fn set_driving_cell<I>() -> impl Parser<Input = I, Output = Command>
2652where
2653    I: Stream<Item = char>,
2654    I::Error: ParseError<I::Item, I::Range, I::Position>,
2655{
2656    let command = symbol("set_driving_cell");
2657    let lib_cell = symbol("-lib_cell")
2658        .with(parser(object))
2659        .map(|x| CommandArg::LibCell(x));
2660    let rise = symbol("-rise").map(|_| CommandArg::Rise);
2661    let fall = symbol("-fall").map(|_| CommandArg::Fall);
2662    let min = symbol("-min").map(|_| CommandArg::Min);
2663    let max = symbol("-max").map(|_| CommandArg::Max);
2664    let library = symbol("-library")
2665        .with(parser(object))
2666        .map(|x| CommandArg::Library(x));
2667    let pin = symbol("-pin")
2668        .with(parser(object))
2669        .map(|x| CommandArg::Pin(x));
2670    let from_pin = symbol("-from_pin")
2671        .with(parser(object))
2672        .map(|x| CommandArg::FromPin(x));
2673    let dont_scale = symbol("-dont_scale").map(|_| CommandArg::DontScale);
2674    let no_design_rule = symbol("-no_design_rule").map(|_| CommandArg::NoDesignRule);
2675    let clock = symbol("-clock")
2676        .with(parser(object))
2677        .map(|x| CommandArg::ClockObj(x));
2678    let clock_fall = symbol("-clock_fall").map(|_| CommandArg::ClockFall);
2679    let input_transition_rise = symbol("-input_transition_rise")
2680        .with(float())
2681        .map(|x| CommandArg::InputTransitionRise(x));
2682    let input_transition_fall = symbol("-input_transition_fall")
2683        .with(float())
2684        .map(|x| CommandArg::InputTransitionFall(x));
2685    let multiply_by = symbol("-multiply_by")
2686        .with(float())
2687        .map(|x| CommandArg::MultiplyBy(x));
2688    let port_list = parser(object).map(|x| CommandArg::Object(x));
2689    let args = (
2690        attempt(lib_cell),
2691        attempt(rise),
2692        attempt(fall),
2693        attempt(min),
2694        attempt(max),
2695        attempt(library),
2696        attempt(pin),
2697        attempt(from_pin),
2698        attempt(dont_scale),
2699        attempt(no_design_rule),
2700        attempt(clock),
2701        attempt(clock_fall),
2702        attempt(input_transition_rise),
2703        attempt(input_transition_fall),
2704        attempt(multiply_by),
2705        attempt(port_list),
2706    );
2707    command
2708        .with(many(choice(args)))
2709        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
2710            let mut lib_cell = None;
2711            let mut rise = false;
2712            let mut fall = false;
2713            let mut min = false;
2714            let mut max = false;
2715            let mut library = None;
2716            let mut pin = None;
2717            let mut from_pin = None;
2718            let mut dont_scale = false;
2719            let mut no_design_rule = false;
2720            let mut clock = None;
2721            let mut clock_fall = false;
2722            let mut input_transition_rise = None;
2723            let mut input_transition_fall = None;
2724            let mut multiply_by = None;
2725            let mut port_list = None;
2726            for x in xs {
2727                match x {
2728                    CommandArg::LibCell(x) => lib_cell = Some(x),
2729                    CommandArg::Rise => rise = true,
2730                    CommandArg::Fall => fall = true,
2731                    CommandArg::Min => min = true,
2732                    CommandArg::Max => max = true,
2733                    CommandArg::Library(x) => library = Some(x),
2734                    CommandArg::Pin(x) => pin = Some(x),
2735                    CommandArg::FromPin(x) => from_pin = Some(x),
2736                    CommandArg::DontScale => dont_scale = true,
2737                    CommandArg::NoDesignRule => no_design_rule = true,
2738                    CommandArg::ClockObj(x) => clock = Some(x),
2739                    CommandArg::ClockFall => clock_fall = true,
2740                    CommandArg::InputTransitionRise(x) => input_transition_rise = Some(x),
2741                    CommandArg::InputTransitionFall(x) => input_transition_fall = Some(x),
2742                    CommandArg::MultiplyBy(x) => multiply_by = Some(x),
2743                    CommandArg::Object(x) => port_list = Some(x),
2744                    _ => unreachable!(),
2745                }
2746            }
2747            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
2748                "set_driving_cell:port_list",
2749            ))?;
2750            Ok(Command::SetDrivingCell(SetDrivingCell {
2751                lib_cell,
2752                rise,
2753                fall,
2754                min,
2755                max,
2756                library,
2757                pin,
2758                from_pin,
2759                dont_scale,
2760                no_design_rule,
2761                clock,
2762                clock_fall,
2763                input_transition_rise,
2764                input_transition_fall,
2765                multiply_by,
2766                port_list,
2767            }))
2768        })
2769}
2770
2771#[test]
2772fn test_set_driving_cell() {
2773    let mut parser = command();
2774    let tgt = "set_driving_cell -lib_cell a -rise -fall -min -max -library a -pin a -from_pin a -dont_scale -no_design_rule -clock a -clock_fall -input_transition_rise 0.1 -input_transition_fall 0.1 -multiply_by 0.1 a";
2775    let ret = parser.parse(tgt).unwrap().0;
2776    assert_eq!(
2777        Command::SetDrivingCell(SetDrivingCell {
2778            lib_cell: Some(Object::String(ObjectString {
2779                strings: vec![String::from("a")]
2780            })),
2781            rise: true,
2782            fall: true,
2783            min: true,
2784            max: true,
2785            library: Some(Object::String(ObjectString {
2786                strings: vec![String::from("a")]
2787            })),
2788            pin: Some(Object::String(ObjectString {
2789                strings: vec![String::from("a")]
2790            })),
2791            from_pin: Some(Object::String(ObjectString {
2792                strings: vec![String::from("a")]
2793            })),
2794            dont_scale: true,
2795            no_design_rule: true,
2796            clock: Some(Object::String(ObjectString {
2797                strings: vec![String::from("a")]
2798            })),
2799            clock_fall: true,
2800            input_transition_rise: Some(0.1),
2801            input_transition_fall: Some(0.1),
2802            multiply_by: Some(0.1),
2803            port_list: Object::String(ObjectString {
2804                strings: vec![String::from("a")]
2805            }),
2806        }),
2807        ret
2808    );
2809    assert_eq!(tgt, format!("{}", ret));
2810}
2811
2812// -----------------------------------------------------------------------------
2813
2814/// A type containing information of `set_false_path`
2815#[derive(Clone, Debug, Default, PartialEq)]
2816pub struct SetFalsePath {
2817    pub setup: bool,
2818    pub hold: bool,
2819    pub rise: bool,
2820    pub fall: bool,
2821    pub from: Option<Object>,
2822    pub to: Option<Object>,
2823    pub through: Option<Object>,
2824    pub rise_from: Option<Object>,
2825    pub rise_to: Option<Object>,
2826    pub rise_through: Option<Object>,
2827    pub fall_from: Option<Object>,
2828    pub fall_to: Option<Object>,
2829    pub fall_through: Option<Object>,
2830    pub comment: Option<String>,
2831}
2832
2833impl fmt::Display for SetFalsePath {
2834    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2835        let mut args = String::from("");
2836        if self.setup {
2837            args.push_str(" -setup");
2838        }
2839        if self.hold {
2840            args.push_str(" -hold");
2841        }
2842        if self.rise {
2843            args.push_str(" -rise");
2844        }
2845        if self.fall {
2846            args.push_str(" -fall");
2847        }
2848        if let Some(from) = &self.from {
2849            args.push_str(&format!(" -from {}", from));
2850        }
2851        if let Some(to) = &self.to {
2852            args.push_str(&format!(" -to {}", to));
2853        }
2854        if let Some(through) = &self.through {
2855            args.push_str(&format!(" -through {}", through));
2856        }
2857        if let Some(rise_from) = &self.rise_from {
2858            args.push_str(&format!(" -rise_from {}", rise_from));
2859        }
2860        if let Some(rise_to) = &self.rise_to {
2861            args.push_str(&format!(" -rise_to {}", rise_to));
2862        }
2863        if let Some(rise_through) = &self.rise_through {
2864            args.push_str(&format!(" -rise_through {}", rise_through));
2865        }
2866        if let Some(fall_from) = &self.fall_from {
2867            args.push_str(&format!(" -fall_from {}", fall_from));
2868        }
2869        if let Some(fall_to) = &self.fall_to {
2870            args.push_str(&format!(" -fall_to {}", fall_to));
2871        }
2872        if let Some(fall_through) = &self.fall_through {
2873            args.push_str(&format!(" -fall_through {}", fall_through));
2874        }
2875        if let Some(comment) = &self.comment {
2876            args.push_str(&format!(" -comment \"{}\"", comment));
2877        }
2878        write!(f, "set_false_path{}", args)
2879    }
2880}
2881
2882fn set_false_path<I>() -> impl Parser<Input = I, Output = Command>
2883where
2884    I: Stream<Item = char>,
2885    I::Error: ParseError<I::Item, I::Range, I::Position>,
2886{
2887    let command = symbol("set_false_path");
2888    let setup = symbol("-setup").map(|_| CommandArg::Setup);
2889    let hold = symbol("-hold").map(|_| CommandArg::Hold);
2890    let rise = symbol("-rise").map(|_| CommandArg::Rise);
2891    let fall = symbol("-fall").map(|_| CommandArg::Fall);
2892    let from = symbol("-from")
2893        .with(parser(object))
2894        .map(|x| CommandArg::From(x));
2895    let to = symbol("-to")
2896        .with(parser(object))
2897        .map(|x| CommandArg::To(x));
2898    let through = symbol("-through")
2899        .with(parser(object))
2900        .map(|x| CommandArg::Through(x));
2901    let rise_from = symbol("-rise_from")
2902        .with(parser(object))
2903        .map(|x| CommandArg::RiseFrom(x));
2904    let rise_to = symbol("-rise_to")
2905        .with(parser(object))
2906        .map(|x| CommandArg::RiseTo(x));
2907    let rise_through = symbol("-rise_through")
2908        .with(parser(object))
2909        .map(|x| CommandArg::RiseThrough(x));
2910    let fall_from = symbol("-fall_from")
2911        .with(parser(object))
2912        .map(|x| CommandArg::FallFrom(x));
2913    let fall_to = symbol("-fall_to")
2914        .with(parser(object))
2915        .map(|x| CommandArg::FallTo(x));
2916    let fall_through = symbol("-fall_through")
2917        .with(parser(object))
2918        .map(|x| CommandArg::FallThrough(x));
2919    let comment = symbol("-comment")
2920        .with(item())
2921        .map(|x| CommandArg::Comment(x));
2922    let args = (
2923        attempt(setup),
2924        attempt(hold),
2925        attempt(from),
2926        attempt(to),
2927        attempt(through),
2928        attempt(rise_from),
2929        attempt(rise_to),
2930        attempt(rise_through),
2931        attempt(fall_from),
2932        attempt(fall_to),
2933        attempt(fall_through),
2934        attempt(rise),
2935        attempt(fall),
2936        attempt(comment),
2937    );
2938    command
2939        .with(many(choice(args)))
2940        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
2941            let mut setup = false;
2942            let mut hold = false;
2943            let mut rise = false;
2944            let mut fall = false;
2945            let mut from = None;
2946            let mut to = None;
2947            let mut through = None;
2948            let mut rise_from = None;
2949            let mut rise_to = None;
2950            let mut rise_through = None;
2951            let mut fall_from = None;
2952            let mut fall_to = None;
2953            let mut fall_through = None;
2954            let mut comment = None;
2955            for x in xs {
2956                match x {
2957                    CommandArg::Setup => setup = true,
2958                    CommandArg::Hold => hold = true,
2959                    CommandArg::Rise => rise = true,
2960                    CommandArg::Fall => fall = true,
2961                    CommandArg::From(x) => from = Some(x),
2962                    CommandArg::To(x) => to = Some(x),
2963                    CommandArg::Through(x) => through = Some(x),
2964                    CommandArg::RiseFrom(x) => rise_from = Some(x),
2965                    CommandArg::RiseTo(x) => rise_to = Some(x),
2966                    CommandArg::RiseThrough(x) => rise_through = Some(x),
2967                    CommandArg::FallFrom(x) => fall_from = Some(x),
2968                    CommandArg::FallTo(x) => fall_to = Some(x),
2969                    CommandArg::FallThrough(x) => fall_through = Some(x),
2970                    CommandArg::Comment(x) => comment = Some(x),
2971                    _ => unreachable!(),
2972                }
2973            }
2974            Ok(Command::SetFalsePath(SetFalsePath {
2975                setup,
2976                hold,
2977                rise,
2978                fall,
2979                from,
2980                to,
2981                through,
2982                rise_from,
2983                rise_to,
2984                rise_through,
2985                fall_from,
2986                fall_to,
2987                fall_through,
2988                comment,
2989            }))
2990        })
2991}
2992
2993#[test]
2994fn test_set_false_path() {
2995    let mut parser = command();
2996    let tgt = "set_false_path -setup -hold -rise -fall -from a -to a -through a -rise_from a -rise_to a -rise_through a -fall_from a -fall_to a -fall_through a -comment \"aaa\"";
2997    let ret = parser.parse(tgt).unwrap().0;
2998    assert_eq!(
2999        Command::SetFalsePath(SetFalsePath {
3000            setup: true,
3001            hold: true,
3002            rise: true,
3003            fall: true,
3004            from: Some(Object::String(ObjectString {
3005                strings: vec![String::from("a")]
3006            })),
3007            to: Some(Object::String(ObjectString {
3008                strings: vec![String::from("a")]
3009            })),
3010            through: Some(Object::String(ObjectString {
3011                strings: vec![String::from("a")]
3012            })),
3013            rise_from: Some(Object::String(ObjectString {
3014                strings: vec![String::from("a")]
3015            })),
3016            rise_to: Some(Object::String(ObjectString {
3017                strings: vec![String::from("a")]
3018            })),
3019            rise_through: Some(Object::String(ObjectString {
3020                strings: vec![String::from("a")]
3021            })),
3022            fall_from: Some(Object::String(ObjectString {
3023                strings: vec![String::from("a")]
3024            })),
3025            fall_to: Some(Object::String(ObjectString {
3026                strings: vec![String::from("a")]
3027            })),
3028            fall_through: Some(Object::String(ObjectString {
3029                strings: vec![String::from("a")]
3030            })),
3031            comment: Some(String::from("aaa")),
3032        }),
3033        ret
3034    );
3035    assert_eq!(tgt, format!("{}", ret));
3036}
3037
3038// -----------------------------------------------------------------------------
3039
3040/// A type containing information of `set_fanout_load`
3041#[derive(Clone, Debug, Default, PartialEq)]
3042pub struct SetFanoutLoad {
3043    pub value: f64,
3044    pub port_list: Object,
3045}
3046
3047impl fmt::Display for SetFanoutLoad {
3048    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3049        let mut args = String::from("");
3050        args.push_str(&format!(" {}", self.value));
3051        args.push_str(&format!(" {}", self.port_list));
3052        write!(f, "set_fanout_load{}", args)
3053    }
3054}
3055
3056fn set_fanout_load<I>() -> impl Parser<Input = I, Output = Command>
3057where
3058    I: Stream<Item = char>,
3059    I::Error: ParseError<I::Item, I::Range, I::Position>,
3060{
3061    let command = symbol("set_fanout_load");
3062    let value = float().map(|x| CommandArg::Value(x));
3063    let port_list = parser(object).map(|x| CommandArg::Object(x));
3064    let args = (attempt(value), attempt(port_list));
3065    command
3066        .with(many(choice(args)))
3067        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3068            let mut value = None;
3069            let mut port_list = None;
3070            for x in xs {
3071                match x {
3072                    CommandArg::Value(x) => value = Some(x),
3073                    CommandArg::Object(x) => port_list = Some(x),
3074                    _ => unreachable!(),
3075                }
3076            }
3077            let value = value.ok_or(AndThenError::<I>::message_static_message(
3078                "set_fanout_load:value",
3079            ))?;
3080            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
3081                "set_fanout_load:port_list",
3082            ))?;
3083            Ok(Command::SetFanoutLoad(SetFanoutLoad { value, port_list }))
3084        })
3085}
3086
3087#[test]
3088fn test_set_fanout_load() {
3089    let mut parser = command();
3090    let tgt = "set_fanout_load 0.1 a";
3091    let ret = parser.parse(tgt).unwrap().0;
3092    assert_eq!(
3093        Command::SetFanoutLoad(SetFanoutLoad {
3094            value: 0.1,
3095            port_list: Object::String(ObjectString {
3096                strings: vec![String::from("a")]
3097            }),
3098        }),
3099        ret
3100    );
3101    assert_eq!(tgt, format!("{}", ret));
3102}
3103
3104// -----------------------------------------------------------------------------
3105
3106/// A type containing information of `set_ideal_latency`
3107#[derive(Clone, Debug, Default, PartialEq)]
3108pub struct SetIdealLatency {
3109    pub rise: bool,
3110    pub fall: bool,
3111    pub min: bool,
3112    pub max: bool,
3113    pub delay: f64,
3114    pub object_list: Object,
3115}
3116
3117impl fmt::Display for SetIdealLatency {
3118    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3119        let mut args = String::from("");
3120        if self.rise {
3121            args.push_str(" -rise");
3122        }
3123        if self.fall {
3124            args.push_str(" -fall");
3125        }
3126        if self.min {
3127            args.push_str(" -min");
3128        }
3129        if self.max {
3130            args.push_str(" -max");
3131        }
3132        args.push_str(&format!(" {}", self.delay));
3133        args.push_str(&format!(" {}", self.object_list));
3134        write!(f, "set_ideal_latency{}", args)
3135    }
3136}
3137
3138fn set_ideal_latency<I>() -> impl Parser<Input = I, Output = Command>
3139where
3140    I: Stream<Item = char>,
3141    I::Error: ParseError<I::Item, I::Range, I::Position>,
3142{
3143    let command = symbol("set_ideal_latency");
3144    let rise = symbol("-rise").map(|_| CommandArg::Rise);
3145    let fall = symbol("-fall").map(|_| CommandArg::Fall);
3146    let min = symbol("-min").map(|_| CommandArg::Min);
3147    let max = symbol("-max").map(|_| CommandArg::Max);
3148    let delay = float().map(|x| CommandArg::Value(x));
3149    let object_list = parser(object).map(|x| CommandArg::Object(x));
3150    let args = (
3151        attempt(rise),
3152        attempt(fall),
3153        attempt(min),
3154        attempt(max),
3155        attempt(delay),
3156        attempt(object_list),
3157    );
3158    command
3159        .with(many(choice(args)))
3160        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3161            let mut rise = false;
3162            let mut fall = false;
3163            let mut min = false;
3164            let mut max = false;
3165            let mut delay = None;
3166            let mut object_list = None;
3167            for x in xs {
3168                match x {
3169                    CommandArg::Rise => rise = true,
3170                    CommandArg::Fall => fall = true,
3171                    CommandArg::Min => min = true,
3172                    CommandArg::Max => max = true,
3173                    CommandArg::Value(x) => delay = Some(x),
3174                    CommandArg::Object(x) => object_list = Some(x),
3175                    _ => unreachable!(),
3176                }
3177            }
3178            let delay = delay.ok_or(AndThenError::<I>::message_static_message(
3179                "set_ideal_latency:delay",
3180            ))?;
3181            let object_list = object_list.ok_or(AndThenError::<I>::message_static_message(
3182                "set_ideal_latency:object_list",
3183            ))?;
3184            Ok(Command::SetIdealLatency(SetIdealLatency {
3185                rise,
3186                fall,
3187                min,
3188                max,
3189                delay,
3190                object_list,
3191            }))
3192        })
3193}
3194
3195#[test]
3196fn test_set_ideal_latency() {
3197    let mut parser = command();
3198    let tgt = "set_ideal_latency -rise -fall -min -max 0.1 a";
3199    let ret = parser.parse(tgt).unwrap().0;
3200    assert_eq!(
3201        Command::SetIdealLatency(SetIdealLatency {
3202            rise: true,
3203            fall: true,
3204            min: true,
3205            max: true,
3206            delay: 0.1,
3207            object_list: Object::String(ObjectString {
3208                strings: vec![String::from("a")]
3209            }),
3210        }),
3211        ret
3212    );
3213    assert_eq!(tgt, format!("{}", ret));
3214}
3215
3216// -----------------------------------------------------------------------------
3217
3218/// A type containing information of `set_ideal_network`
3219#[derive(Clone, Debug, Default, PartialEq)]
3220pub struct SetIdealNetwork {
3221    pub no_propagate: bool,
3222    pub object_list: Object,
3223}
3224
3225impl fmt::Display for SetIdealNetwork {
3226    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3227        let mut args = String::from("");
3228        if self.no_propagate {
3229            args.push_str(" -no_propagate");
3230        }
3231        args.push_str(&format!(" {}", self.object_list));
3232        write!(f, "set_ideal_network{}", args)
3233    }
3234}
3235
3236fn set_ideal_network<I>() -> impl Parser<Input = I, Output = Command>
3237where
3238    I: Stream<Item = char>,
3239    I::Error: ParseError<I::Item, I::Range, I::Position>,
3240{
3241    let command = symbol("set_ideal_network");
3242    let no_propagate = symbol("-no_propagate").map(|_| CommandArg::NoPropagate);
3243    let object_list = parser(object).map(|x| CommandArg::Object(x));
3244    let args = (attempt(no_propagate), attempt(object_list));
3245    command
3246        .with(many(choice(args)))
3247        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3248            let mut no_propagate = false;
3249            let mut object_list = None;
3250            for x in xs {
3251                match x {
3252                    CommandArg::NoPropagate => no_propagate = true,
3253                    CommandArg::Object(x) => object_list = Some(x),
3254                    _ => unreachable!(),
3255                }
3256            }
3257            let object_list = object_list.ok_or(AndThenError::<I>::message_static_message(
3258                "set_ideal_network:object_list",
3259            ))?;
3260            Ok(Command::SetIdealNetwork(SetIdealNetwork {
3261                no_propagate,
3262                object_list,
3263            }))
3264        })
3265}
3266
3267#[test]
3268fn test_set_ideal_network() {
3269    let mut parser = command();
3270    let tgt = "set_ideal_network -no_propagate a";
3271    let ret = parser.parse(tgt).unwrap().0;
3272    assert_eq!(
3273        Command::SetIdealNetwork(SetIdealNetwork {
3274            no_propagate: true,
3275            object_list: Object::String(ObjectString {
3276                strings: vec![String::from("a")]
3277            }),
3278        }),
3279        ret
3280    );
3281    assert_eq!(tgt, format!("{}", ret));
3282}
3283
3284// -----------------------------------------------------------------------------
3285
3286/// A type containing information of `set_ideal_transition`
3287#[derive(Clone, Debug, Default, PartialEq)]
3288pub struct SetIdealTransition {
3289    pub rise: bool,
3290    pub fall: bool,
3291    pub min: bool,
3292    pub max: bool,
3293    pub transition_time: f64,
3294    pub object_list: Object,
3295}
3296
3297impl fmt::Display for SetIdealTransition {
3298    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3299        let mut args = String::from("");
3300        if self.rise {
3301            args.push_str(" -rise");
3302        }
3303        if self.fall {
3304            args.push_str(" -fall");
3305        }
3306        if self.min {
3307            args.push_str(" -min");
3308        }
3309        if self.max {
3310            args.push_str(" -max");
3311        }
3312        args.push_str(&format!(" {}", self.transition_time));
3313        args.push_str(&format!(" {}", self.object_list));
3314        write!(f, "set_ideal_transition{}", args)
3315    }
3316}
3317
3318fn set_ideal_transition<I>() -> impl Parser<Input = I, Output = Command>
3319where
3320    I: Stream<Item = char>,
3321    I::Error: ParseError<I::Item, I::Range, I::Position>,
3322{
3323    let command = symbol("set_ideal_transition");
3324    let rise = symbol("-rise").map(|_| CommandArg::Rise);
3325    let fall = symbol("-fall").map(|_| CommandArg::Fall);
3326    let min = symbol("-min").map(|_| CommandArg::Min);
3327    let max = symbol("-max").map(|_| CommandArg::Max);
3328    let transition_time = float().map(|x| CommandArg::Value(x));
3329    let object_list = parser(object).map(|x| CommandArg::Object(x));
3330    let args = (
3331        attempt(rise),
3332        attempt(fall),
3333        attempt(min),
3334        attempt(max),
3335        attempt(transition_time),
3336        attempt(object_list),
3337    );
3338    command
3339        .with(many(choice(args)))
3340        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3341            let mut rise = false;
3342            let mut fall = false;
3343            let mut min = false;
3344            let mut max = false;
3345            let mut transition_time = None;
3346            let mut object_list = None;
3347            for x in xs {
3348                match x {
3349                    CommandArg::Rise => rise = true,
3350                    CommandArg::Fall => fall = true,
3351                    CommandArg::Min => min = true,
3352                    CommandArg::Max => max = true,
3353                    CommandArg::Value(x) => transition_time = Some(x),
3354                    CommandArg::Object(x) => object_list = Some(x),
3355                    _ => unreachable!(),
3356                }
3357            }
3358            let transition_time = transition_time.ok_or(
3359                AndThenError::<I>::message_static_message("set_ideal_transition:transition_time"),
3360            )?;
3361            let object_list = object_list.ok_or(AndThenError::<I>::message_static_message(
3362                "set_ideal_transition:object_list",
3363            ))?;
3364            Ok(Command::SetIdealTransition(SetIdealTransition {
3365                rise,
3366                fall,
3367                min,
3368                max,
3369                transition_time,
3370                object_list,
3371            }))
3372        })
3373}
3374
3375#[test]
3376fn test_set_ideal_transition() {
3377    let mut parser = command();
3378    let tgt = "set_ideal_transition -rise -fall -min -max 0.1 a";
3379    let ret = parser.parse(tgt).unwrap().0;
3380    assert_eq!(
3381        Command::SetIdealTransition(SetIdealTransition {
3382            rise: true,
3383            fall: true,
3384            min: true,
3385            max: true,
3386            transition_time: 0.1,
3387            object_list: Object::String(ObjectString {
3388                strings: vec![String::from("a")]
3389            }),
3390        }),
3391        ret
3392    );
3393    assert_eq!(tgt, format!("{}", ret));
3394}
3395
3396// -----------------------------------------------------------------------------
3397
3398/// A type containing information of `set_input_delay`
3399#[derive(Clone, Debug, Default, PartialEq)]
3400pub struct SetInputDelay {
3401    pub clock: Option<Object>,
3402    pub reference_pin: Option<Object>,
3403    pub clock_fall: bool,
3404    pub level_sensitive: bool,
3405    pub rise: bool,
3406    pub fall: bool,
3407    pub max: bool,
3408    pub min: bool,
3409    pub add_delay: bool,
3410    pub network_latency_included: bool,
3411    pub source_latency_included: bool,
3412    pub delay_value: f64,
3413    pub port_pin_list: Object,
3414}
3415
3416impl fmt::Display for SetInputDelay {
3417    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3418        let mut args = String::from("");
3419        if let Some(clock) = &self.clock {
3420            args.push_str(&format!(" -clock {}", clock));
3421        }
3422        if let Some(reference_pin) = &self.reference_pin {
3423            args.push_str(&format!(" -reference_pin {}", reference_pin));
3424        }
3425        if self.clock_fall {
3426            args.push_str(" -clock_fall");
3427        }
3428        if self.level_sensitive {
3429            args.push_str(" -level_sensitive");
3430        }
3431        if self.rise {
3432            args.push_str(" -rise");
3433        }
3434        if self.fall {
3435            args.push_str(" -fall");
3436        }
3437        if self.max {
3438            args.push_str(" -max");
3439        }
3440        if self.min {
3441            args.push_str(" -min");
3442        }
3443        if self.add_delay {
3444            args.push_str(" -add_delay");
3445        }
3446        if self.network_latency_included {
3447            args.push_str(" -network_latency_included");
3448        }
3449        if self.source_latency_included {
3450            args.push_str(" -source_latency_included");
3451        }
3452        args.push_str(&format!(" {}", self.delay_value));
3453        args.push_str(&format!(" {}", self.port_pin_list));
3454        write!(f, "set_input_delay{}", args)
3455    }
3456}
3457
3458fn set_input_delay<I>() -> impl Parser<Input = I, Output = Command>
3459where
3460    I: Stream<Item = char>,
3461    I::Error: ParseError<I::Item, I::Range, I::Position>,
3462{
3463    let command = symbol("set_input_delay");
3464    let clock = symbol("-clock")
3465        .with(parser(object))
3466        .map(|x| CommandArg::ClockObj(x));
3467    let reference_pin = symbol("-reference_pin")
3468        .with(parser(object))
3469        .map(|x| CommandArg::ReferencePin(x));
3470    let clock_fall = symbol("-clock_fall").map(|_| CommandArg::ClockFall);
3471    let level_sensitive = symbol("-level_sensitive").map(|_| CommandArg::LevelSensitive);
3472    let rise = symbol("-rise").map(|_| CommandArg::Rise);
3473    let fall = symbol("-fall").map(|_| CommandArg::Fall);
3474    let max = symbol("-max").map(|_| CommandArg::Max);
3475    let min = symbol("-min").map(|_| CommandArg::Min);
3476    let add_delay = symbol("-add_delay").map(|_| CommandArg::AddDelay);
3477    let network_latency_included =
3478        symbol("-network_latency_included").map(|_| CommandArg::NetworkLatencyIncluded);
3479    let source_latency_included =
3480        symbol("-source_latency_included").map(|_| CommandArg::SourceLatencyIncluded);
3481    let delay_value = float().map(|x| CommandArg::Value(x));
3482    let port_pin_list = parser(object).map(|x| CommandArg::Object(x));
3483    let args = (
3484        attempt(clock),
3485        attempt(reference_pin),
3486        attempt(clock_fall),
3487        attempt(level_sensitive),
3488        attempt(rise),
3489        attempt(fall),
3490        attempt(max),
3491        attempt(min),
3492        attempt(add_delay),
3493        attempt(network_latency_included),
3494        attempt(source_latency_included),
3495        attempt(delay_value),
3496        attempt(port_pin_list),
3497    );
3498    command
3499        .with(many(choice(args)))
3500        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3501            let mut clock = None;
3502            let mut reference_pin = None;
3503            let mut clock_fall = false;
3504            let mut level_sensitive = false;
3505            let mut rise = false;
3506            let mut fall = false;
3507            let mut max = false;
3508            let mut min = false;
3509            let mut add_delay = false;
3510            let mut network_latency_included = false;
3511            let mut source_latency_included = false;
3512            let mut delay_value = None;
3513            let mut port_pin_list = None;
3514            for x in xs {
3515                match x {
3516                    CommandArg::ClockObj(x) => clock = Some(x),
3517                    CommandArg::ReferencePin(x) => reference_pin = Some(x),
3518                    CommandArg::ClockFall => clock_fall = true,
3519                    CommandArg::LevelSensitive => level_sensitive = true,
3520                    CommandArg::Rise => rise = true,
3521                    CommandArg::Fall => fall = true,
3522                    CommandArg::Max => max = true,
3523                    CommandArg::Min => min = true,
3524                    CommandArg::AddDelay => add_delay = true,
3525                    CommandArg::NetworkLatencyIncluded => network_latency_included = true,
3526                    CommandArg::SourceLatencyIncluded => source_latency_included = true,
3527                    CommandArg::Value(x) => delay_value = Some(x),
3528                    CommandArg::Object(x) => port_pin_list = Some(x),
3529                    _ => unreachable!(),
3530                }
3531            }
3532            let delay_value = delay_value.ok_or(AndThenError::<I>::message_static_message(
3533                "set_input_delay:delay_value",
3534            ))?;
3535            let port_pin_list = port_pin_list.ok_or(AndThenError::<I>::message_static_message(
3536                "set_input_delay:port_pin_list",
3537            ))?;
3538            Ok(Command::SetInputDelay(SetInputDelay {
3539                clock,
3540                reference_pin,
3541                clock_fall,
3542                level_sensitive,
3543                rise,
3544                fall,
3545                max,
3546                min,
3547                add_delay,
3548                network_latency_included,
3549                source_latency_included,
3550                delay_value,
3551                port_pin_list,
3552            }))
3553        })
3554}
3555
3556#[test]
3557fn test_set_input_delay() {
3558    let mut parser = command();
3559    let tgt = "set_input_delay -clock a -reference_pin a -clock_fall -level_sensitive -rise -fall -max -min -add_delay -network_latency_included -source_latency_included 0.1 a";
3560    let ret = parser.parse(tgt).unwrap().0;
3561    assert_eq!(
3562        Command::SetInputDelay(SetInputDelay {
3563            clock: Some(Object::String(ObjectString {
3564                strings: vec![String::from("a")]
3565            })),
3566            reference_pin: Some(Object::String(ObjectString {
3567                strings: vec![String::from("a")]
3568            })),
3569            clock_fall: true,
3570            level_sensitive: true,
3571            rise: true,
3572            fall: true,
3573            min: true,
3574            max: true,
3575            add_delay: true,
3576            network_latency_included: true,
3577            source_latency_included: true,
3578            delay_value: 0.1,
3579            port_pin_list: Object::String(ObjectString {
3580                strings: vec![String::from("a")]
3581            }),
3582        }),
3583        ret
3584    );
3585    assert_eq!(tgt, format!("{}", ret));
3586}
3587
3588// -----------------------------------------------------------------------------
3589
3590/// A type containing information of `set_input_transition`
3591#[derive(Clone, Debug, Default, PartialEq)]
3592pub struct SetInputTransition {
3593    pub rise: bool,
3594    pub fall: bool,
3595    pub min: bool,
3596    pub max: bool,
3597    pub clock: Option<Object>,
3598    pub clock_fall: bool,
3599    pub transition: f64,
3600    pub port_list: Object,
3601}
3602
3603impl fmt::Display for SetInputTransition {
3604    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3605        let mut args = String::from("");
3606        if self.rise {
3607            args.push_str(" -rise");
3608        }
3609        if self.fall {
3610            args.push_str(" -fall");
3611        }
3612        if self.min {
3613            args.push_str(" -min");
3614        }
3615        if self.max {
3616            args.push_str(" -max");
3617        }
3618        if let Some(clock) = &self.clock {
3619            args.push_str(&format!(" -clock {}", clock));
3620        }
3621        if self.clock_fall {
3622            args.push_str(" -clock_fall");
3623        }
3624        args.push_str(&format!(" {}", self.transition));
3625        args.push_str(&format!(" {}", self.port_list));
3626        write!(f, "set_input_transition{}", args)
3627    }
3628}
3629
3630fn set_input_transition<I>() -> impl Parser<Input = I, Output = Command>
3631where
3632    I: Stream<Item = char>,
3633    I::Error: ParseError<I::Item, I::Range, I::Position>,
3634{
3635    let command = symbol("set_input_transition");
3636    let rise = symbol("-rise").map(|_| CommandArg::Rise);
3637    let fall = symbol("-fall").map(|_| CommandArg::Fall);
3638    let min = symbol("-min").map(|_| CommandArg::Min);
3639    let max = symbol("-max").map(|_| CommandArg::Max);
3640    let clock = symbol("-clock")
3641        .with(parser(object))
3642        .map(|x| CommandArg::ClockObj(x));
3643    let clock_fall = symbol("-clock_fall").map(|_| CommandArg::ClockFall);
3644    let transition = float().map(|x| CommandArg::Value(x));
3645    let port_list = parser(object).map(|x| CommandArg::Object(x));
3646    let args = (
3647        attempt(rise),
3648        attempt(fall),
3649        attempt(min),
3650        attempt(max),
3651        attempt(clock),
3652        attempt(clock_fall),
3653        attempt(transition),
3654        attempt(port_list),
3655    );
3656    command
3657        .with(many(choice(args)))
3658        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3659            let mut rise = false;
3660            let mut fall = false;
3661            let mut min = false;
3662            let mut max = false;
3663            let mut clock = None;
3664            let mut clock_fall = false;
3665            let mut transition = None;
3666            let mut port_list = None;
3667            for x in xs {
3668                match x {
3669                    CommandArg::Rise => rise = true,
3670                    CommandArg::Fall => fall = true,
3671                    CommandArg::Min => min = true,
3672                    CommandArg::Max => max = true,
3673                    CommandArg::ClockObj(x) => clock = Some(x),
3674                    CommandArg::ClockFall => clock_fall = true,
3675                    CommandArg::Value(x) => transition = Some(x),
3676                    CommandArg::Object(x) => port_list = Some(x),
3677                    _ => unreachable!(),
3678                }
3679            }
3680            let transition = transition.ok_or(AndThenError::<I>::message_static_message(
3681                "set_input_transition:transition",
3682            ))?;
3683            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
3684                "set_input_transition:port_list",
3685            ))?;
3686            Ok(Command::SetInputTransition(SetInputTransition {
3687                rise,
3688                fall,
3689                min,
3690                max,
3691                clock,
3692                clock_fall,
3693                transition,
3694                port_list,
3695            }))
3696        })
3697}
3698
3699#[test]
3700fn test_set_input_transition() {
3701    let mut parser = command();
3702    let tgt = "set_input_transition -rise -fall -min -max -clock a -clock_fall 0.1 a";
3703    let ret = parser.parse(tgt).unwrap().0;
3704    assert_eq!(
3705        Command::SetInputTransition(SetInputTransition {
3706            rise: true,
3707            fall: true,
3708            min: true,
3709            max: true,
3710            clock: Some(Object::String(ObjectString {
3711                strings: vec![String::from("a")]
3712            })),
3713            clock_fall: true,
3714            transition: 0.1,
3715            port_list: Object::String(ObjectString {
3716                strings: vec![String::from("a")]
3717            }),
3718        }),
3719        ret
3720    );
3721    assert_eq!(tgt, format!("{}", ret));
3722}
3723
3724// -----------------------------------------------------------------------------
3725
3726/// A type containing information of `set_level_shifter_strategy`
3727#[derive(Clone, Debug, Default, PartialEq)]
3728pub struct SetLevelShifterStrategy {
3729    pub rule: Option<String>,
3730}
3731
3732impl fmt::Display for SetLevelShifterStrategy {
3733    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3734        let mut args = String::from("");
3735        if let Some(rule) = &self.rule {
3736            args.push_str(&format!(" -rule {}", rule));
3737        }
3738        write!(f, "set_level_shifter_strategy{}", args)
3739    }
3740}
3741
3742fn set_level_shifter_strategy<I>() -> impl Parser<Input = I, Output = Command>
3743where
3744    I: Stream<Item = char>,
3745    I::Error: ParseError<I::Item, I::Range, I::Position>,
3746{
3747    let command = symbol("set_level_shifter_strategy");
3748    let rule = symbol("-rule").with(item()).map(|x| CommandArg::Rule(x));
3749    let args = (attempt(rule),);
3750    command
3751        .with(many(choice(args)))
3752        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3753            let mut rule = None;
3754            for x in xs {
3755                match x {
3756                    CommandArg::Rule(x) => rule = Some(x),
3757                    _ => unreachable!(),
3758                }
3759            }
3760            Ok(Command::SetLevelShifterStrategy(SetLevelShifterStrategy {
3761                rule,
3762            }))
3763        })
3764}
3765
3766#[test]
3767fn test_set_level_shifter_strategy() {
3768    let mut parser = command();
3769    let tgt = "set_level_shifter_strategy -rule a";
3770    let ret = parser.parse(tgt).unwrap().0;
3771    assert_eq!(
3772        Command::SetLevelShifterStrategy(SetLevelShifterStrategy {
3773            rule: Some(String::from("a")),
3774        }),
3775        ret
3776    );
3777    assert_eq!(tgt, format!("{}", ret));
3778}
3779
3780// -----------------------------------------------------------------------------
3781
3782/// A type containing information of `set_level_shifter_threshold`
3783#[derive(Clone, Debug, Default, PartialEq)]
3784pub struct SetLevelShifterThreshold {
3785    pub voltage: Option<f64>,
3786    pub percent: Option<f64>,
3787}
3788
3789impl fmt::Display for SetLevelShifterThreshold {
3790    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3791        let mut args = String::from("");
3792        if let Some(voltage) = &self.voltage {
3793            args.push_str(&format!(" -voltage {}", voltage));
3794        }
3795        if let Some(percent) = &self.percent {
3796            args.push_str(&format!(" -percent {}", percent));
3797        }
3798        write!(f, "set_level_shifter_threshold{}", args)
3799    }
3800}
3801
3802fn set_level_shifter_threshold<I>() -> impl Parser<Input = I, Output = Command>
3803where
3804    I: Stream<Item = char>,
3805    I::Error: ParseError<I::Item, I::Range, I::Position>,
3806{
3807    let command = symbol("set_level_shifter_threshold");
3808    let voltage = symbol("-voltage")
3809        .with(float())
3810        .map(|x| CommandArg::Voltage(x));
3811    let percent = symbol("-percent")
3812        .with(float())
3813        .map(|x| CommandArg::Percent(x));
3814    let args = (attempt(voltage), attempt(percent));
3815    command
3816        .with(many(choice(args)))
3817        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3818            let mut voltage = None;
3819            let mut percent = None;
3820            for x in xs {
3821                match x {
3822                    CommandArg::Voltage(x) => voltage = Some(x),
3823                    CommandArg::Percent(x) => percent = Some(x),
3824                    _ => unreachable!(),
3825                }
3826            }
3827            Ok(Command::SetLevelShifterThreshold(
3828                SetLevelShifterThreshold { voltage, percent },
3829            ))
3830        })
3831}
3832
3833#[test]
3834fn test_set_level_shifter_threshold() {
3835    let mut parser = command();
3836    let tgt = "set_level_shifter_threshold -voltage 0.1 -percent 0.1";
3837    let ret = parser.parse(tgt).unwrap().0;
3838    assert_eq!(
3839        Command::SetLevelShifterThreshold(SetLevelShifterThreshold {
3840            voltage: Some(0.1),
3841            percent: Some(0.1),
3842        }),
3843        ret
3844    );
3845    assert_eq!(tgt, format!("{}", ret));
3846}
3847
3848// -----------------------------------------------------------------------------
3849
3850/// A type containing information of `set_load`
3851#[derive(Clone, Debug, Default, PartialEq)]
3852pub struct SetLoad {
3853    pub min: bool,
3854    pub max: bool,
3855    pub subtract_pin_load: bool,
3856    pub pin_load: bool,
3857    pub wire_load: bool,
3858    pub value: f64,
3859    pub objects: Object,
3860}
3861
3862impl fmt::Display for SetLoad {
3863    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3864        let mut args = String::from("");
3865        if self.min {
3866            args.push_str(" -min");
3867        }
3868        if self.max {
3869            args.push_str(" -max");
3870        }
3871        if self.subtract_pin_load {
3872            args.push_str(" -subtract_pin_load");
3873        }
3874        if self.pin_load {
3875            args.push_str(" -pin_load");
3876        }
3877        if self.wire_load {
3878            args.push_str(" -wire_load");
3879        }
3880        args.push_str(&format!(" {}", self.value));
3881        args.push_str(&format!(" {}", self.objects));
3882        write!(f, "set_load{}", args)
3883    }
3884}
3885
3886fn set_load<I>() -> impl Parser<Input = I, Output = Command>
3887where
3888    I: Stream<Item = char>,
3889    I::Error: ParseError<I::Item, I::Range, I::Position>,
3890{
3891    let command = symbol("set_load");
3892    let min = symbol("-min").map(|_| CommandArg::Min);
3893    let max = symbol("-max").map(|_| CommandArg::Max);
3894    let subtract_pin_load = symbol("-subtract_pin_load").map(|_| CommandArg::SubtractPinLoad);
3895    let pin_load = symbol("-pin_load").map(|_| CommandArg::PinLoad);
3896    let wire_load = symbol("-wire_load").map(|_| CommandArg::WireLoad);
3897    let value = float().map(|x| CommandArg::Value(x));
3898    let objects = parser(object).map(|x| CommandArg::Object(x));
3899    let args = (
3900        attempt(min),
3901        attempt(max),
3902        attempt(subtract_pin_load),
3903        attempt(pin_load),
3904        attempt(wire_load),
3905        attempt(value),
3906        attempt(objects),
3907    );
3908    command
3909        .with(many(choice(args)))
3910        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3911            let mut min = false;
3912            let mut max = false;
3913            let mut subtract_pin_load = false;
3914            let mut pin_load = false;
3915            let mut wire_load = false;
3916            let mut value = None;
3917            let mut objects = None;
3918            for x in xs {
3919                match x {
3920                    CommandArg::Min => min = true,
3921                    CommandArg::Max => max = true,
3922                    CommandArg::SubtractPinLoad => subtract_pin_load = true,
3923                    CommandArg::PinLoad => pin_load = true,
3924                    CommandArg::WireLoad => wire_load = true,
3925                    CommandArg::Value(x) => value = Some(x),
3926                    CommandArg::Object(x) => objects = Some(x),
3927                    _ => unreachable!(),
3928                }
3929            }
3930            let value = value.ok_or(AndThenError::<I>::message_static_message("set_load:value"))?;
3931            let objects = objects.ok_or(AndThenError::<I>::message_static_message(
3932                "set_load:objects",
3933            ))?;
3934            Ok(Command::SetLoad(SetLoad {
3935                min,
3936                max,
3937                subtract_pin_load,
3938                pin_load,
3939                wire_load,
3940                value,
3941                objects,
3942            }))
3943        })
3944}
3945
3946#[test]
3947fn test_set_load() {
3948    let mut parser = command();
3949    let tgt = "set_load -min -max -subtract_pin_load -pin_load -wire_load 0.1 a";
3950    let ret = parser.parse(tgt).unwrap().0;
3951    assert_eq!(
3952        Command::SetLoad(SetLoad {
3953            min: true,
3954            max: true,
3955            subtract_pin_load: true,
3956            pin_load: true,
3957            wire_load: true,
3958            value: 0.1,
3959            objects: Object::String(ObjectString {
3960                strings: vec![String::from("a")]
3961            }),
3962        }),
3963        ret
3964    );
3965    assert_eq!(tgt, format!("{}", ret));
3966}
3967
3968// -----------------------------------------------------------------------------
3969
3970/// A type containing information of `set_logic_dc`
3971#[derive(Clone, Debug, Default, PartialEq)]
3972pub struct SetLogicDc {
3973    pub port_list: Object,
3974}
3975
3976impl fmt::Display for SetLogicDc {
3977    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3978        let mut args = String::from("");
3979        args.push_str(&format!(" {}", self.port_list));
3980        write!(f, "set_logic_dc{}", args)
3981    }
3982}
3983
3984fn set_logic_dc<I>() -> impl Parser<Input = I, Output = Command>
3985where
3986    I: Stream<Item = char>,
3987    I::Error: ParseError<I::Item, I::Range, I::Position>,
3988{
3989    let command = symbol("set_logic_dc");
3990    let port_list = parser(object).map(|x| CommandArg::Object(x));
3991    let args = (attempt(port_list),);
3992    command
3993        .with(many(choice(args)))
3994        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
3995            let mut port_list = None;
3996            for x in xs {
3997                match x {
3998                    CommandArg::Object(x) => port_list = Some(x),
3999                    _ => unreachable!(),
4000                }
4001            }
4002            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
4003                "set_logic_dc:port_list",
4004            ))?;
4005            Ok(Command::SetLogicDc(SetLogicDc { port_list }))
4006        })
4007}
4008
4009#[test]
4010fn test_set_logic_dc() {
4011    let mut parser = command();
4012    let tgt = "set_logic_dc a";
4013    let ret = parser.parse(tgt).unwrap().0;
4014    assert_eq!(
4015        Command::SetLogicDc(SetLogicDc {
4016            port_list: Object::String(ObjectString {
4017                strings: vec![String::from("a")]
4018            }),
4019        }),
4020        ret
4021    );
4022    assert_eq!(tgt, format!("{}", ret));
4023}
4024
4025// -----------------------------------------------------------------------------
4026
4027/// A type containing information of `set_logic_one`
4028#[derive(Clone, Debug, Default, PartialEq)]
4029pub struct SetLogicOne {
4030    pub port_list: Object,
4031}
4032
4033impl fmt::Display for SetLogicOne {
4034    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4035        let mut args = String::from("");
4036        args.push_str(&format!(" {}", self.port_list));
4037        write!(f, "set_logic_one{}", args)
4038    }
4039}
4040
4041fn set_logic_one<I>() -> impl Parser<Input = I, Output = Command>
4042where
4043    I: Stream<Item = char>,
4044    I::Error: ParseError<I::Item, I::Range, I::Position>,
4045{
4046    let command = symbol("set_logic_one");
4047    let port_list = parser(object).map(|x| CommandArg::Object(x));
4048    let args = (attempt(port_list),);
4049    command
4050        .with(many(choice(args)))
4051        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4052            let mut port_list = None;
4053            for x in xs {
4054                match x {
4055                    CommandArg::Object(x) => port_list = Some(x),
4056                    _ => unreachable!(),
4057                }
4058            }
4059            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
4060                "set_logic_one:port_list",
4061            ))?;
4062            Ok(Command::SetLogicOne(SetLogicOne { port_list }))
4063        })
4064}
4065
4066#[test]
4067fn test_set_logic_one() {
4068    let mut parser = command();
4069    let tgt = "set_logic_one a";
4070    let ret = parser.parse(tgt).unwrap().0;
4071    assert_eq!(
4072        Command::SetLogicOne(SetLogicOne {
4073            port_list: Object::String(ObjectString {
4074                strings: vec![String::from("a")]
4075            }),
4076        }),
4077        ret
4078    );
4079    assert_eq!(tgt, format!("{}", ret));
4080}
4081
4082// -----------------------------------------------------------------------------
4083
4084/// A type containing information of `set_logic_zero`
4085#[derive(Clone, Debug, Default, PartialEq)]
4086pub struct SetLogicZero {
4087    pub port_list: Object,
4088}
4089
4090impl fmt::Display for SetLogicZero {
4091    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4092        let mut args = String::from("");
4093        args.push_str(&format!(" {}", self.port_list));
4094        write!(f, "set_logic_zero{}", args)
4095    }
4096}
4097
4098fn set_logic_zero<I>() -> impl Parser<Input = I, Output = Command>
4099where
4100    I: Stream<Item = char>,
4101    I::Error: ParseError<I::Item, I::Range, I::Position>,
4102{
4103    let command = symbol("set_logic_zero");
4104    let port_list = parser(object).map(|x| CommandArg::Object(x));
4105    let args = (attempt(port_list),);
4106    command
4107        .with(many(choice(args)))
4108        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4109            let mut port_list = None;
4110            for x in xs {
4111                match x {
4112                    CommandArg::Object(x) => port_list = Some(x),
4113                    _ => unreachable!(),
4114                }
4115            }
4116            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
4117                "set_logic_zero:port_list",
4118            ))?;
4119            Ok(Command::SetLogicZero(SetLogicZero { port_list }))
4120        })
4121}
4122
4123#[test]
4124fn test_set_logic_zero() {
4125    let mut parser = command();
4126    let tgt = "set_logic_zero a";
4127    let ret = parser.parse(tgt).unwrap().0;
4128    assert_eq!(
4129        Command::SetLogicZero(SetLogicZero {
4130            port_list: Object::String(ObjectString {
4131                strings: vec![String::from("a")]
4132            }),
4133        }),
4134        ret
4135    );
4136    assert_eq!(tgt, format!("{}", ret));
4137}
4138
4139// -----------------------------------------------------------------------------
4140
4141/// A type containing information of `set_max_area`
4142#[derive(Clone, Debug, Default, PartialEq)]
4143pub struct SetMaxArea {
4144    pub area_value: f64,
4145}
4146
4147impl fmt::Display for SetMaxArea {
4148    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4149        let mut args = String::from("");
4150        args.push_str(&format!(" {}", self.area_value));
4151        write!(f, "set_max_area{}", args)
4152    }
4153}
4154
4155fn set_max_area<I>() -> impl Parser<Input = I, Output = Command>
4156where
4157    I: Stream<Item = char>,
4158    I::Error: ParseError<I::Item, I::Range, I::Position>,
4159{
4160    let command = symbol("set_max_area");
4161    let area_value = float().map(|x| CommandArg::Value(x));
4162    let args = (attempt(area_value),);
4163    command
4164        .with(many(choice(args)))
4165        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4166            let mut area_value = None;
4167            for x in xs {
4168                match x {
4169                    CommandArg::Value(x) => area_value = Some(x),
4170                    _ => unreachable!(),
4171                }
4172            }
4173            let area_value = area_value.ok_or(AndThenError::<I>::message_static_message(
4174                "set_max_area:area_value",
4175            ))?;
4176            Ok(Command::SetMaxArea(SetMaxArea { area_value }))
4177        })
4178}
4179
4180#[test]
4181fn test_set_max_area() {
4182    let mut parser = command();
4183    let tgt = "set_max_area 0.1";
4184    let ret = parser.parse(tgt).unwrap().0;
4185    assert_eq!(Command::SetMaxArea(SetMaxArea { area_value: 0.1 }), ret);
4186    assert_eq!(tgt, format!("{}", ret));
4187}
4188
4189// -----------------------------------------------------------------------------
4190
4191/// A type containing information of `set_max_capacitance`
4192#[derive(Clone, Debug, Default, PartialEq)]
4193pub struct SetMaxCapacitance {
4194    pub value: f64,
4195    pub objects: Object,
4196}
4197
4198impl fmt::Display for SetMaxCapacitance {
4199    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4200        let mut args = String::from("");
4201        args.push_str(&format!(" {}", self.value));
4202        args.push_str(&format!(" {}", self.objects));
4203        write!(f, "set_max_capacitance{}", args)
4204    }
4205}
4206
4207fn set_max_capacitance<I>() -> impl Parser<Input = I, Output = Command>
4208where
4209    I: Stream<Item = char>,
4210    I::Error: ParseError<I::Item, I::Range, I::Position>,
4211{
4212    let command = symbol("set_max_capacitance");
4213    let value = float().map(|x| CommandArg::Value(x));
4214    let objects = parser(object).map(|x| CommandArg::Object(x));
4215    let args = (attempt(value), attempt(objects));
4216    command
4217        .with(many(choice(args)))
4218        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4219            let mut value = None;
4220            let mut objects = None;
4221            for x in xs {
4222                match x {
4223                    CommandArg::Value(x) => value = Some(x),
4224                    CommandArg::Object(x) => objects = Some(x),
4225                    _ => unreachable!(),
4226                }
4227            }
4228            let value = value.ok_or(AndThenError::<I>::message_static_message(
4229                "set_max_capacitance:value",
4230            ))?;
4231            let objects = objects.ok_or(AndThenError::<I>::message_static_message(
4232                "set_max_capacitance:objects",
4233            ))?;
4234            Ok(Command::SetMaxCapacitance(SetMaxCapacitance {
4235                value,
4236                objects,
4237            }))
4238        })
4239}
4240
4241#[test]
4242fn test_set_max_capacitance() {
4243    let mut parser = command();
4244    let tgt = "set_max_capacitance 0.1 a";
4245    let ret = parser.parse(tgt).unwrap().0;
4246    assert_eq!(
4247        Command::SetMaxCapacitance(SetMaxCapacitance {
4248            value: 0.1,
4249            objects: Object::String(ObjectString {
4250                strings: vec![String::from("a")]
4251            }),
4252        }),
4253        ret
4254    );
4255    assert_eq!(tgt, format!("{}", ret));
4256}
4257
4258// -----------------------------------------------------------------------------
4259
4260/// A type containing information of `set_max_delay`
4261#[derive(Clone, Debug, Default, PartialEq)]
4262pub struct SetMaxDelay {
4263    pub rise: bool,
4264    pub fall: bool,
4265    pub from: Option<Object>,
4266    pub to: Option<Object>,
4267    pub through: Option<Object>,
4268    pub rise_from: Option<Object>,
4269    pub rise_to: Option<Object>,
4270    pub rise_through: Option<Object>,
4271    pub fall_from: Option<Object>,
4272    pub fall_to: Option<Object>,
4273    pub fall_through: Option<Object>,
4274    pub ignore_clock_latency: bool,
4275    pub comment: Option<String>,
4276    pub delay_value: f64,
4277}
4278
4279impl fmt::Display for SetMaxDelay {
4280    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4281        let mut args = String::from("");
4282        if self.rise {
4283            args.push_str(" -rise");
4284        }
4285        if self.fall {
4286            args.push_str(" -fall");
4287        }
4288        if let Some(from) = &self.from {
4289            args.push_str(&format!(" -from {}", from));
4290        }
4291        if let Some(to) = &self.to {
4292            args.push_str(&format!(" -to {}", to));
4293        }
4294        if let Some(through) = &self.through {
4295            args.push_str(&format!(" -through {}", through));
4296        }
4297        if let Some(rise_from) = &self.rise_from {
4298            args.push_str(&format!(" -rise_from {}", rise_from));
4299        }
4300        if let Some(rise_to) = &self.rise_to {
4301            args.push_str(&format!(" -rise_to {}", rise_to));
4302        }
4303        if let Some(rise_through) = &self.rise_through {
4304            args.push_str(&format!(" -rise_through {}", rise_through));
4305        }
4306        if let Some(fall_from) = &self.fall_from {
4307            args.push_str(&format!(" -fall_from {}", fall_from));
4308        }
4309        if let Some(fall_to) = &self.fall_to {
4310            args.push_str(&format!(" -fall_to {}", fall_to));
4311        }
4312        if let Some(fall_through) = &self.fall_through {
4313            args.push_str(&format!(" -fall_through {}", fall_through));
4314        }
4315        if self.ignore_clock_latency {
4316            args.push_str(" -ignore_clock_latency");
4317        }
4318        if let Some(comment) = &self.comment {
4319            args.push_str(&format!(" -comment \"{}\"", comment));
4320        }
4321        args.push_str(&format!(" {}", self.delay_value));
4322        write!(f, "set_max_delay{}", args)
4323    }
4324}
4325
4326fn set_max_delay<I>() -> impl Parser<Input = I, Output = Command>
4327where
4328    I: Stream<Item = char>,
4329    I::Error: ParseError<I::Item, I::Range, I::Position>,
4330{
4331    let command = symbol("set_max_delay");
4332    let rise = symbol("-rise").map(|_| CommandArg::Rise);
4333    let fall = symbol("-fall").map(|_| CommandArg::Fall);
4334    let from = symbol("-from")
4335        .with(parser(object))
4336        .map(|x| CommandArg::From(x));
4337    let to = symbol("-to")
4338        .with(parser(object))
4339        .map(|x| CommandArg::To(x));
4340    let through = symbol("-through")
4341        .with(parser(object))
4342        .map(|x| CommandArg::Through(x));
4343    let rise_from = symbol("-rise_from")
4344        .with(parser(object))
4345        .map(|x| CommandArg::RiseFrom(x));
4346    let rise_to = symbol("-rise_to")
4347        .with(parser(object))
4348        .map(|x| CommandArg::RiseTo(x));
4349    let rise_through = symbol("-rise_through")
4350        .with(parser(object))
4351        .map(|x| CommandArg::RiseThrough(x));
4352    let fall_from = symbol("-fall_from")
4353        .with(parser(object))
4354        .map(|x| CommandArg::FallFrom(x));
4355    let fall_to = symbol("-fall_to")
4356        .with(parser(object))
4357        .map(|x| CommandArg::FallTo(x));
4358    let fall_through = symbol("-fall_through")
4359        .with(parser(object))
4360        .map(|x| CommandArg::FallThrough(x));
4361    let ignore_clock_latency =
4362        symbol("-ignore_clock_latency").map(|_| CommandArg::IgnoreClockLatency);
4363    let comment = symbol("-comment")
4364        .with(item())
4365        .map(|x| CommandArg::Comment(x));
4366    let delay_value = float().map(|x| CommandArg::Value(x));
4367    let args = (
4368        attempt(from),
4369        attempt(to),
4370        attempt(through),
4371        attempt(rise_from),
4372        attempt(rise_to),
4373        attempt(rise_through),
4374        attempt(fall_from),
4375        attempt(fall_to),
4376        attempt(fall_through),
4377        attempt(rise),
4378        attempt(fall),
4379        attempt(ignore_clock_latency),
4380        attempt(comment),
4381        attempt(delay_value),
4382    );
4383    command
4384        .with(many(choice(args)))
4385        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4386            let mut rise = false;
4387            let mut fall = false;
4388            let mut from = None;
4389            let mut to = None;
4390            let mut through = None;
4391            let mut rise_from = None;
4392            let mut rise_to = None;
4393            let mut rise_through = None;
4394            let mut fall_from = None;
4395            let mut fall_to = None;
4396            let mut fall_through = None;
4397            let mut ignore_clock_latency = false;
4398            let mut comment = None;
4399            let mut delay_value = None;
4400            for x in xs {
4401                match x {
4402                    CommandArg::Rise => rise = true,
4403                    CommandArg::Fall => fall = true,
4404                    CommandArg::From(x) => from = Some(x),
4405                    CommandArg::To(x) => to = Some(x),
4406                    CommandArg::Through(x) => through = Some(x),
4407                    CommandArg::RiseFrom(x) => rise_from = Some(x),
4408                    CommandArg::RiseTo(x) => rise_to = Some(x),
4409                    CommandArg::RiseThrough(x) => rise_through = Some(x),
4410                    CommandArg::FallFrom(x) => fall_from = Some(x),
4411                    CommandArg::FallTo(x) => fall_to = Some(x),
4412                    CommandArg::FallThrough(x) => fall_through = Some(x),
4413                    CommandArg::IgnoreClockLatency => ignore_clock_latency = true,
4414                    CommandArg::Comment(x) => comment = Some(x),
4415                    CommandArg::Value(x) => delay_value = Some(x),
4416                    _ => unreachable!(),
4417                }
4418            }
4419            let delay_value = delay_value.ok_or(AndThenError::<I>::message_static_message(
4420                "set_max_delay:delay_value",
4421            ))?;
4422            Ok(Command::SetMaxDelay(SetMaxDelay {
4423                rise,
4424                fall,
4425                from,
4426                to,
4427                through,
4428                rise_from,
4429                rise_to,
4430                rise_through,
4431                fall_from,
4432                fall_to,
4433                fall_through,
4434                ignore_clock_latency,
4435                comment,
4436                delay_value,
4437            }))
4438        })
4439}
4440
4441#[test]
4442fn test_set_max_delay() {
4443    let mut parser = command();
4444    let tgt = "set_max_delay -rise -fall -from a -to a -through a -rise_from a -rise_to a -rise_through a -fall_from a -fall_to a -fall_through a -ignore_clock_latency -comment \"aaa\" 0.1";
4445    let ret = parser.parse(tgt).unwrap().0;
4446    assert_eq!(
4447        Command::SetMaxDelay(SetMaxDelay {
4448            rise: true,
4449            fall: true,
4450            from: Some(Object::String(ObjectString {
4451                strings: vec![String::from("a")]
4452            })),
4453            to: Some(Object::String(ObjectString {
4454                strings: vec![String::from("a")]
4455            })),
4456            through: Some(Object::String(ObjectString {
4457                strings: vec![String::from("a")]
4458            })),
4459            rise_from: Some(Object::String(ObjectString {
4460                strings: vec![String::from("a")]
4461            })),
4462            rise_to: Some(Object::String(ObjectString {
4463                strings: vec![String::from("a")]
4464            })),
4465            rise_through: Some(Object::String(ObjectString {
4466                strings: vec![String::from("a")]
4467            })),
4468            fall_from: Some(Object::String(ObjectString {
4469                strings: vec![String::from("a")]
4470            })),
4471            fall_to: Some(Object::String(ObjectString {
4472                strings: vec![String::from("a")]
4473            })),
4474            fall_through: Some(Object::String(ObjectString {
4475                strings: vec![String::from("a")]
4476            })),
4477            ignore_clock_latency: true,
4478            comment: Some(String::from("aaa")),
4479            delay_value: 0.1,
4480        }),
4481        ret
4482    );
4483    assert_eq!(tgt, format!("{}", ret));
4484}
4485
4486// -----------------------------------------------------------------------------
4487
4488/// A type containing information of `set_max_dynamic_power`
4489#[derive(Clone, Debug, Default, PartialEq)]
4490pub struct SetMaxDynamicPower {
4491    pub power: f64,
4492    pub unit: Option<String>,
4493}
4494
4495impl fmt::Display for SetMaxDynamicPower {
4496    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4497        let mut args = String::from("");
4498        args.push_str(&format!(" {}", self.power));
4499        if let Some(unit) = &self.unit {
4500            args.push_str(&format!(" {}", unit));
4501        }
4502        write!(f, "set_max_dynamic_power{}", args)
4503    }
4504}
4505
4506fn set_max_dynamic_power<I>() -> impl Parser<Input = I, Output = Command>
4507where
4508    I: Stream<Item = char>,
4509    I::Error: ParseError<I::Item, I::Range, I::Position>,
4510    I::Error: ParseError<I::Item, I::Range, I::Position>,
4511{
4512    let command = symbol("set_max_dynamic_power");
4513    let power = float().map(|x| CommandArg::Value(x));
4514    let unit = item().map(|x| CommandArg::String(x));
4515    let args = (attempt(power), attempt(unit));
4516    command
4517        .with(many(choice(args)))
4518        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4519            let mut power = None;
4520            let mut unit = None;
4521            for x in xs {
4522                match x {
4523                    CommandArg::Value(x) => power = Some(x),
4524                    CommandArg::String(x) => unit = Some(x),
4525                    _ => unreachable!(),
4526                }
4527            }
4528            let power = power.ok_or(AndThenError::<I>::message_static_message(
4529                "set_max_dynamic_power:power",
4530            ))?;
4531            Ok(Command::SetMaxDynamicPower(SetMaxDynamicPower {
4532                power,
4533                unit,
4534            }))
4535        })
4536}
4537
4538#[test]
4539fn test_set_max_dynamic_power() {
4540    let mut parser = command();
4541    let tgt = "set_max_dynamic_power 0.1 mW";
4542    let ret = parser.parse(tgt).unwrap().0;
4543    assert_eq!(
4544        Command::SetMaxDynamicPower(SetMaxDynamicPower {
4545            power: 0.1,
4546            unit: Some(String::from("mW")),
4547        }),
4548        ret
4549    );
4550    assert_eq!(tgt, format!("{}", ret));
4551}
4552
4553// -----------------------------------------------------------------------------
4554
4555/// A type containing information of `set_max_fanout`
4556#[derive(Clone, Debug, Default, PartialEq)]
4557pub struct SetMaxFanout {
4558    pub value: f64,
4559    pub objects: Object,
4560}
4561
4562impl fmt::Display for SetMaxFanout {
4563    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4564        let mut args = String::from("");
4565        args.push_str(&format!(" {}", self.value));
4566        args.push_str(&format!(" {}", self.objects));
4567        write!(f, "set_max_fanout{}", args)
4568    }
4569}
4570
4571fn set_max_fanout<I>() -> impl Parser<Input = I, Output = Command>
4572where
4573    I: Stream<Item = char>,
4574    I::Error: ParseError<I::Item, I::Range, I::Position>,
4575{
4576    let command = symbol("set_max_fanout");
4577    let value = float().map(|x| CommandArg::Value(x));
4578    let objects = parser(object).map(|x| CommandArg::Object(x));
4579    let args = (attempt(value), attempt(objects));
4580    command
4581        .with(many(choice(args)))
4582        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4583            let mut value = None;
4584            let mut objects = None;
4585            for x in xs {
4586                match x {
4587                    CommandArg::Value(x) => value = Some(x),
4588                    CommandArg::Object(x) => objects = Some(x),
4589                    _ => unreachable!(),
4590                }
4591            }
4592            let value = value.ok_or(AndThenError::<I>::message_static_message(
4593                "set_max_fanout:value",
4594            ))?;
4595            let objects = objects.ok_or(AndThenError::<I>::message_static_message(
4596                "set_max_fanout:objects",
4597            ))?;
4598            Ok(Command::SetMaxFanout(SetMaxFanout { value, objects }))
4599        })
4600}
4601
4602#[test]
4603fn test_set_max_fanout() {
4604    let mut parser = command();
4605    let tgt = "set_max_fanout 0.1 a";
4606    let ret = parser.parse(tgt).unwrap().0;
4607    assert_eq!(
4608        Command::SetMaxFanout(SetMaxFanout {
4609            value: 0.1,
4610            objects: Object::String(ObjectString {
4611                strings: vec![String::from("a")]
4612            }),
4613        }),
4614        ret
4615    );
4616    assert_eq!(tgt, format!("{}", ret));
4617}
4618
4619// -----------------------------------------------------------------------------
4620
4621/// A type containing information of `set_max_leakage_power`
4622#[derive(Clone, Debug, Default, PartialEq)]
4623pub struct SetMaxLeakagePower {
4624    pub power: f64,
4625    pub unit: Option<String>,
4626}
4627
4628impl fmt::Display for SetMaxLeakagePower {
4629    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4630        let mut args = String::from("");
4631        args.push_str(&format!(" {}", self.power));
4632        if let Some(unit) = &self.unit {
4633            args.push_str(&format!(" {}", unit));
4634        }
4635        write!(f, "set_max_leakage_power{}", args)
4636    }
4637}
4638
4639fn set_max_leakage_power<I>() -> impl Parser<Input = I, Output = Command>
4640where
4641    I: Stream<Item = char>,
4642    I::Error: ParseError<I::Item, I::Range, I::Position>,
4643    I::Error: ParseError<I::Item, I::Range, I::Position>,
4644{
4645    let command = symbol("set_max_leakage_power");
4646    let power = float().map(|x| CommandArg::Value(x));
4647    let unit = item().map(|x| CommandArg::String(x));
4648    let args = (attempt(power), attempt(unit));
4649    command
4650        .with(many(choice(args)))
4651        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4652            let mut power = None;
4653            let mut unit = None;
4654            for x in xs {
4655                match x {
4656                    CommandArg::Value(x) => power = Some(x),
4657                    CommandArg::String(x) => unit = Some(x),
4658                    _ => unreachable!(),
4659                }
4660            }
4661            let power = power.ok_or(AndThenError::<I>::message_static_message(
4662                "set_max_leakage_power:power",
4663            ))?;
4664            Ok(Command::SetMaxLeakagePower(SetMaxLeakagePower {
4665                power,
4666                unit,
4667            }))
4668        })
4669}
4670
4671#[test]
4672fn test_set_max_leakage_power() {
4673    let mut parser = command();
4674    let tgt = "set_max_leakage_power 0.1 mW";
4675    let ret = parser.parse(tgt).unwrap().0;
4676    assert_eq!(
4677        Command::SetMaxLeakagePower(SetMaxLeakagePower {
4678            power: 0.1,
4679            unit: Some(String::from("mW")),
4680        }),
4681        ret
4682    );
4683    assert_eq!(tgt, format!("{}", ret));
4684}
4685
4686// -----------------------------------------------------------------------------
4687
4688/// A type containing information of `set_max_time_borrow`
4689#[derive(Clone, Debug, Default, PartialEq)]
4690pub struct SetMaxTimeBorrow {
4691    pub delay_value: f64,
4692    pub object_list: Object,
4693}
4694
4695impl fmt::Display for SetMaxTimeBorrow {
4696    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4697        let mut args = String::from("");
4698        args.push_str(&format!(" {}", self.delay_value));
4699        args.push_str(&format!(" {}", self.object_list));
4700        write!(f, "set_max_time_borrow{}", args)
4701    }
4702}
4703
4704fn set_max_time_borrow<I>() -> impl Parser<Input = I, Output = Command>
4705where
4706    I: Stream<Item = char>,
4707    I::Error: ParseError<I::Item, I::Range, I::Position>,
4708{
4709    let command = symbol("set_max_time_borrow");
4710    let delay_value = float().map(|x| CommandArg::Value(x));
4711    let object_list = parser(object).map(|x| CommandArg::Object(x));
4712    let args = (attempt(delay_value), attempt(object_list));
4713    command
4714        .with(many(choice(args)))
4715        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4716            let mut delay_value = None;
4717            let mut object_list = None;
4718            for x in xs {
4719                match x {
4720                    CommandArg::Value(x) => delay_value = Some(x),
4721                    CommandArg::Object(x) => object_list = Some(x),
4722                    _ => unreachable!(),
4723                }
4724            }
4725            let delay_value = delay_value.ok_or(AndThenError::<I>::message_static_message(
4726                "set_max_time_borrow:delay_value",
4727            ))?;
4728            let object_list = object_list.ok_or(AndThenError::<I>::message_static_message(
4729                "set_max_time_borrow:object_list",
4730            ))?;
4731            Ok(Command::SetMaxTimeBorrow(SetMaxTimeBorrow {
4732                delay_value,
4733                object_list,
4734            }))
4735        })
4736}
4737
4738#[test]
4739fn test_set_max_time_borrow() {
4740    let mut parser = command();
4741    let tgt = "set_max_time_borrow 0.1 a";
4742    let ret = parser.parse(tgt).unwrap().0;
4743    assert_eq!(
4744        Command::SetMaxTimeBorrow(SetMaxTimeBorrow {
4745            delay_value: 0.1,
4746            object_list: Object::String(ObjectString {
4747                strings: vec![String::from("a")]
4748            }),
4749        }),
4750        ret
4751    );
4752    assert_eq!(tgt, format!("{}", ret));
4753}
4754
4755// -----------------------------------------------------------------------------
4756
4757/// A type containing information of `set_max_transition`
4758#[derive(Clone, Debug, Default, PartialEq)]
4759pub struct SetMaxTransition {
4760    pub clock_path: bool,
4761    pub data_path: bool,
4762    pub rise: bool,
4763    pub fall: bool,
4764    pub value: f64,
4765    pub object_list: Object,
4766}
4767
4768impl fmt::Display for SetMaxTransition {
4769    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4770        let mut args = String::from("");
4771        if self.clock_path {
4772            args.push_str(" -clock_path");
4773        }
4774        if self.data_path {
4775            args.push_str(" -data_path");
4776        }
4777        if self.rise {
4778            args.push_str(" -rise");
4779        }
4780        if self.fall {
4781            args.push_str(" -fall");
4782        }
4783        args.push_str(&format!(" {}", self.value));
4784        args.push_str(&format!(" {}", self.object_list));
4785        write!(f, "set_max_transition{}", args)
4786    }
4787}
4788
4789fn set_max_transition<I>() -> impl Parser<Input = I, Output = Command>
4790where
4791    I: Stream<Item = char>,
4792    I::Error: ParseError<I::Item, I::Range, I::Position>,
4793{
4794    let command = symbol("set_max_transition");
4795    let clock_path = symbol("-clock_path").map(|_| CommandArg::ClockPath);
4796    let data_path = symbol("-data_path").map(|_| CommandArg::DataPath);
4797    let rise = symbol("-rise").map(|_| CommandArg::Rise);
4798    let fall = symbol("-fall").map(|_| CommandArg::Fall);
4799    let value = float().map(|x| CommandArg::Value(x));
4800    let object_list = parser(object).map(|x| CommandArg::Object(x));
4801    let args = (
4802        attempt(clock_path),
4803        attempt(data_path),
4804        attempt(rise),
4805        attempt(fall),
4806        attempt(value),
4807        attempt(object_list),
4808    );
4809    command
4810        .with(many(choice(args)))
4811        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4812            let mut clock_path = false;
4813            let mut data_path = false;
4814            let mut rise = false;
4815            let mut fall = false;
4816            let mut value = None;
4817            let mut object_list = None;
4818            for x in xs {
4819                match x {
4820                    CommandArg::ClockPath => clock_path = true,
4821                    CommandArg::DataPath => data_path = true,
4822                    CommandArg::Rise => rise = true,
4823                    CommandArg::Fall => fall = true,
4824                    CommandArg::Value(x) => value = Some(x),
4825                    CommandArg::Object(x) => object_list = Some(x),
4826                    _ => unreachable!(),
4827                }
4828            }
4829            let value = value.ok_or(AndThenError::<I>::message_static_message(
4830                "set_max_transition:value",
4831            ))?;
4832            let object_list = object_list.ok_or(AndThenError::<I>::message_static_message(
4833                "set_max_transition:object_list",
4834            ))?;
4835            Ok(Command::SetMaxTransition(SetMaxTransition {
4836                clock_path,
4837                data_path,
4838                rise,
4839                fall,
4840                value,
4841                object_list,
4842            }))
4843        })
4844}
4845
4846#[test]
4847fn test_set_max_transition() {
4848    let mut parser = command();
4849    let tgt = "set_max_transition -clock_path -data_path -rise -fall 0.1 a";
4850    let ret = parser.parse(tgt).unwrap().0;
4851    assert_eq!(
4852        Command::SetMaxTransition(SetMaxTransition {
4853            clock_path: true,
4854            data_path: true,
4855            rise: true,
4856            fall: true,
4857            value: 0.1,
4858            object_list: Object::String(ObjectString {
4859                strings: vec![String::from("a")]
4860            }),
4861        }),
4862        ret
4863    );
4864    assert_eq!(tgt, format!("{}", ret));
4865}
4866
4867// -----------------------------------------------------------------------------
4868
4869/// A type containing information of `set_min_capacitance`
4870#[derive(Clone, Debug, Default, PartialEq)]
4871pub struct SetMinCapacitance {
4872    pub value: f64,
4873    pub objects: Object,
4874}
4875
4876impl fmt::Display for SetMinCapacitance {
4877    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4878        let mut args = String::from("");
4879        args.push_str(&format!(" {}", self.value));
4880        args.push_str(&format!(" {}", self.objects));
4881        write!(f, "set_min_capacitance{}", args)
4882    }
4883}
4884
4885fn set_min_capacitance<I>() -> impl Parser<Input = I, Output = Command>
4886where
4887    I: Stream<Item = char>,
4888    I::Error: ParseError<I::Item, I::Range, I::Position>,
4889{
4890    let command = symbol("set_min_capacitance");
4891    let value = float().map(|x| CommandArg::Value(x));
4892    let objects = parser(object).map(|x| CommandArg::Object(x));
4893    let args = (attempt(value), attempt(objects));
4894    command
4895        .with(many(choice(args)))
4896        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
4897            let mut value = None;
4898            let mut objects = None;
4899            for x in xs {
4900                match x {
4901                    CommandArg::Value(x) => value = Some(x),
4902                    CommandArg::Object(x) => objects = Some(x),
4903                    _ => unreachable!(),
4904                }
4905            }
4906            let value = value.ok_or(AndThenError::<I>::message_static_message(
4907                "set_min_capacitance:value",
4908            ))?;
4909            let objects = objects.ok_or(AndThenError::<I>::message_static_message(
4910                "set_min_capacitance:objects",
4911            ))?;
4912            Ok(Command::SetMinCapacitance(SetMinCapacitance {
4913                value,
4914                objects,
4915            }))
4916        })
4917}
4918
4919#[test]
4920fn test_set_min_capacitance() {
4921    let mut parser = command();
4922    let tgt = "set_min_capacitance 0.1 a";
4923    let ret = parser.parse(tgt).unwrap().0;
4924    assert_eq!(
4925        Command::SetMinCapacitance(SetMinCapacitance {
4926            value: 0.1,
4927            objects: Object::String(ObjectString {
4928                strings: vec![String::from("a")]
4929            }),
4930        }),
4931        ret
4932    );
4933    assert_eq!(tgt, format!("{}", ret));
4934}
4935
4936// -----------------------------------------------------------------------------
4937
4938/// A type containing information of `set_min_delay`
4939#[derive(Clone, Debug, Default, PartialEq)]
4940pub struct SetMinDelay {
4941    pub rise: bool,
4942    pub fall: bool,
4943    pub from: Option<Object>,
4944    pub to: Option<Object>,
4945    pub through: Option<Object>,
4946    pub rise_from: Option<Object>,
4947    pub rise_to: Option<Object>,
4948    pub rise_through: Option<Object>,
4949    pub fall_from: Option<Object>,
4950    pub fall_to: Option<Object>,
4951    pub fall_through: Option<Object>,
4952    pub ignore_clock_latency: bool,
4953    pub comment: Option<String>,
4954    pub delay_value: f64,
4955}
4956
4957impl fmt::Display for SetMinDelay {
4958    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4959        let mut args = String::from("");
4960        if self.rise {
4961            args.push_str(" -rise");
4962        }
4963        if self.fall {
4964            args.push_str(" -fall");
4965        }
4966        if let Some(from) = &self.from {
4967            args.push_str(&format!(" -from {}", from));
4968        }
4969        if let Some(to) = &self.to {
4970            args.push_str(&format!(" -to {}", to));
4971        }
4972        if let Some(through) = &self.through {
4973            args.push_str(&format!(" -through {}", through));
4974        }
4975        if let Some(rise_from) = &self.rise_from {
4976            args.push_str(&format!(" -rise_from {}", rise_from));
4977        }
4978        if let Some(rise_to) = &self.rise_to {
4979            args.push_str(&format!(" -rise_to {}", rise_to));
4980        }
4981        if let Some(rise_through) = &self.rise_through {
4982            args.push_str(&format!(" -rise_through {}", rise_through));
4983        }
4984        if let Some(fall_from) = &self.fall_from {
4985            args.push_str(&format!(" -fall_from {}", fall_from));
4986        }
4987        if let Some(fall_to) = &self.fall_to {
4988            args.push_str(&format!(" -fall_to {}", fall_to));
4989        }
4990        if let Some(fall_through) = &self.fall_through {
4991            args.push_str(&format!(" -fall_through {}", fall_through));
4992        }
4993        if self.ignore_clock_latency {
4994            args.push_str(" -ignore_clock_latency");
4995        }
4996        if let Some(comment) = &self.comment {
4997            args.push_str(&format!(" -comment \"{}\"", comment));
4998        }
4999        args.push_str(&format!(" {}", self.delay_value));
5000        write!(f, "set_min_delay{}", args)
5001    }
5002}
5003
5004fn set_min_delay<I>() -> impl Parser<Input = I, Output = Command>
5005where
5006    I: Stream<Item = char>,
5007    I::Error: ParseError<I::Item, I::Range, I::Position>,
5008{
5009    let command = symbol("set_min_delay");
5010    let rise = symbol("-rise").map(|_| CommandArg::Rise);
5011    let fall = symbol("-fall").map(|_| CommandArg::Fall);
5012    let from = symbol("-from")
5013        .with(parser(object))
5014        .map(|x| CommandArg::From(x));
5015    let to = symbol("-to")
5016        .with(parser(object))
5017        .map(|x| CommandArg::To(x));
5018    let through = symbol("-through")
5019        .with(parser(object))
5020        .map(|x| CommandArg::Through(x));
5021    let rise_from = symbol("-rise_from")
5022        .with(parser(object))
5023        .map(|x| CommandArg::RiseFrom(x));
5024    let rise_to = symbol("-rise_to")
5025        .with(parser(object))
5026        .map(|x| CommandArg::RiseTo(x));
5027    let rise_through = symbol("-rise_through")
5028        .with(parser(object))
5029        .map(|x| CommandArg::RiseThrough(x));
5030    let fall_from = symbol("-fall_from")
5031        .with(parser(object))
5032        .map(|x| CommandArg::FallFrom(x));
5033    let fall_to = symbol("-fall_to")
5034        .with(parser(object))
5035        .map(|x| CommandArg::FallTo(x));
5036    let fall_through = symbol("-fall_through")
5037        .with(parser(object))
5038        .map(|x| CommandArg::FallThrough(x));
5039    let ignore_clock_latency =
5040        symbol("-ignore_clock_latency").map(|_| CommandArg::IgnoreClockLatency);
5041    let comment = symbol("-comment")
5042        .with(item())
5043        .map(|x| CommandArg::Comment(x));
5044    let delay_value = float().map(|x| CommandArg::Value(x));
5045    let args = (
5046        attempt(from),
5047        attempt(to),
5048        attempt(through),
5049        attempt(rise_from),
5050        attempt(rise_to),
5051        attempt(rise_through),
5052        attempt(fall_from),
5053        attempt(fall_to),
5054        attempt(fall_through),
5055        attempt(rise),
5056        attempt(fall),
5057        attempt(ignore_clock_latency),
5058        attempt(comment),
5059        attempt(delay_value),
5060    );
5061    command
5062        .with(many(choice(args)))
5063        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
5064            let mut rise = false;
5065            let mut fall = false;
5066            let mut from = None;
5067            let mut to = None;
5068            let mut through = None;
5069            let mut rise_from = None;
5070            let mut rise_to = None;
5071            let mut rise_through = None;
5072            let mut fall_from = None;
5073            let mut fall_to = None;
5074            let mut fall_through = None;
5075            let mut ignore_clock_latency = false;
5076            let mut comment = None;
5077            let mut delay_value = None;
5078            for x in xs {
5079                match x {
5080                    CommandArg::Rise => rise = true,
5081                    CommandArg::Fall => fall = true,
5082                    CommandArg::From(x) => from = Some(x),
5083                    CommandArg::To(x) => to = Some(x),
5084                    CommandArg::Through(x) => through = Some(x),
5085                    CommandArg::RiseFrom(x) => rise_from = Some(x),
5086                    CommandArg::RiseTo(x) => rise_to = Some(x),
5087                    CommandArg::RiseThrough(x) => rise_through = Some(x),
5088                    CommandArg::FallFrom(x) => fall_from = Some(x),
5089                    CommandArg::FallTo(x) => fall_to = Some(x),
5090                    CommandArg::FallThrough(x) => fall_through = Some(x),
5091                    CommandArg::IgnoreClockLatency => ignore_clock_latency = true,
5092                    CommandArg::Comment(x) => comment = Some(x),
5093                    CommandArg::Value(x) => delay_value = Some(x),
5094                    _ => unreachable!(),
5095                }
5096            }
5097            let delay_value = delay_value.ok_or(AndThenError::<I>::message_static_message(
5098                "set_min_delay:delay_value",
5099            ))?;
5100            Ok(Command::SetMinDelay(SetMinDelay {
5101                rise,
5102                fall,
5103                from,
5104                to,
5105                through,
5106                rise_from,
5107                rise_to,
5108                rise_through,
5109                fall_from,
5110                fall_to,
5111                fall_through,
5112                ignore_clock_latency,
5113                comment,
5114                delay_value,
5115            }))
5116        })
5117}
5118
5119#[test]
5120fn test_set_min_delay() {
5121    let mut parser = command();
5122    let tgt = "set_min_delay -rise -fall -from a -to a -through a -rise_from a -rise_to a -rise_through a -fall_from a -fall_to a -fall_through a -ignore_clock_latency -comment \"aaa\" 0.1";
5123    let ret = parser.parse(tgt).unwrap().0;
5124    assert_eq!(
5125        Command::SetMinDelay(SetMinDelay {
5126            rise: true,
5127            fall: true,
5128            from: Some(Object::String(ObjectString {
5129                strings: vec![String::from("a")]
5130            })),
5131            to: Some(Object::String(ObjectString {
5132                strings: vec![String::from("a")]
5133            })),
5134            through: Some(Object::String(ObjectString {
5135                strings: vec![String::from("a")]
5136            })),
5137            rise_from: Some(Object::String(ObjectString {
5138                strings: vec![String::from("a")]
5139            })),
5140            rise_to: Some(Object::String(ObjectString {
5141                strings: vec![String::from("a")]
5142            })),
5143            rise_through: Some(Object::String(ObjectString {
5144                strings: vec![String::from("a")]
5145            })),
5146            fall_from: Some(Object::String(ObjectString {
5147                strings: vec![String::from("a")]
5148            })),
5149            fall_to: Some(Object::String(ObjectString {
5150                strings: vec![String::from("a")]
5151            })),
5152            fall_through: Some(Object::String(ObjectString {
5153                strings: vec![String::from("a")]
5154            })),
5155            ignore_clock_latency: true,
5156            comment: Some(String::from("aaa")),
5157            delay_value: 0.1,
5158        }),
5159        ret
5160    );
5161    assert_eq!(tgt, format!("{}", ret));
5162}
5163
5164// -----------------------------------------------------------------------------
5165
5166/// A type containing information of `set_min_porosity`
5167#[derive(Clone, Debug, Default, PartialEq)]
5168pub struct SetMinPorosity {
5169    pub porosity_value: f64,
5170    pub object_list: Object,
5171}
5172
5173impl fmt::Display for SetMinPorosity {
5174    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5175        let mut args = String::from("");
5176        args.push_str(&format!(" {}", self.porosity_value));
5177        args.push_str(&format!(" {}", self.object_list));
5178        write!(f, "set_min_porosity{}", args)
5179    }
5180}
5181
5182fn set_min_porosity<I>() -> impl Parser<Input = I, Output = Command>
5183where
5184    I: Stream<Item = char>,
5185    I::Error: ParseError<I::Item, I::Range, I::Position>,
5186{
5187    let command = symbol("set_min_porosity");
5188    let porosity_value = float().map(|x| CommandArg::Value(x));
5189    let object_list = parser(object).map(|x| CommandArg::Object(x));
5190    let args = (attempt(porosity_value), attempt(object_list));
5191    command
5192        .with(many(choice(args)))
5193        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
5194            let mut value = None;
5195            let mut objects = None;
5196            for x in xs {
5197                match x {
5198                    CommandArg::Value(x) => value = Some(x),
5199                    CommandArg::Object(x) => objects = Some(x),
5200                    _ => unreachable!(),
5201                }
5202            }
5203            let porosity_value = value.ok_or(AndThenError::<I>::message_static_message(
5204                "set_min_porosity:value",
5205            ))?;
5206            let object_list = objects.ok_or(AndThenError::<I>::message_static_message(
5207                "set_min_porosity:objects",
5208            ))?;
5209            Ok(Command::SetMinPorosity(SetMinPorosity {
5210                porosity_value,
5211                object_list,
5212            }))
5213        })
5214}
5215
5216#[test]
5217fn test_set_min_porosity() {
5218    let mut parser = command();
5219    let tgt = "set_min_porosity 0.1 a";
5220    let ret = parser.parse(tgt).unwrap().0;
5221    assert_eq!(
5222        Command::SetMinPorosity(SetMinPorosity {
5223            porosity_value: 0.1,
5224            object_list: Object::String(ObjectString {
5225                strings: vec![String::from("a")]
5226            }),
5227        }),
5228        ret
5229    );
5230    assert_eq!(tgt, format!("{}", ret));
5231}
5232
5233// -----------------------------------------------------------------------------
5234
5235/// A type containing information of `set_min_pulse_width`
5236#[derive(Clone, Debug, Default, PartialEq)]
5237pub struct SetMinPulseWidth {
5238    pub low: bool,
5239    pub high: bool,
5240    pub value: f64,
5241    pub object_list: Option<Object>,
5242}
5243
5244impl fmt::Display for SetMinPulseWidth {
5245    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5246        let mut args = String::from("");
5247        if self.low {
5248            args.push_str(" -low");
5249        }
5250        if self.high {
5251            args.push_str(" -high");
5252        }
5253        args.push_str(&format!(" {}", self.value));
5254        if let Some(object_list) = &self.object_list {
5255            args.push_str(&format!(" {}", object_list));
5256        }
5257        write!(f, "set_min_pulse_width{}", args)
5258    }
5259}
5260
5261fn set_min_pulse_width<I>() -> impl Parser<Input = I, Output = Command>
5262where
5263    I: Stream<Item = char>,
5264    I::Error: ParseError<I::Item, I::Range, I::Position>,
5265{
5266    let command = symbol("set_min_pulse_width");
5267    let low = symbol("-low").map(|_| CommandArg::Low);
5268    let high = symbol("-high").map(|_| CommandArg::High);
5269    let value = float().map(|x| CommandArg::Value(x));
5270    let object_list = parser(object).map(|x| CommandArg::Object(x));
5271    let args = (
5272        attempt(low),
5273        attempt(high),
5274        attempt(value),
5275        attempt(object_list),
5276    );
5277    command
5278        .with(many(choice(args)))
5279        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
5280            let mut low = false;
5281            let mut high = false;
5282            let mut value = None;
5283            let mut object_list = None;
5284            for x in xs {
5285                match x {
5286                    CommandArg::Low => low = true,
5287                    CommandArg::High => high = true,
5288                    CommandArg::Value(x) => value = Some(x),
5289                    CommandArg::Object(x) => object_list = Some(x),
5290                    _ => unreachable!(),
5291                }
5292            }
5293            let value = value.ok_or(AndThenError::<I>::message_static_message(
5294                "set_min_pulse_width:value",
5295            ))?;
5296            Ok(Command::SetMinPulseWidth(SetMinPulseWidth {
5297                low,
5298                high,
5299                value,
5300                object_list,
5301            }))
5302        })
5303}
5304
5305#[test]
5306fn test_set_min_pulse_width() {
5307    let mut parser = command();
5308    let tgt = "set_min_pulse_width -low -high 0.1 a";
5309    let ret = parser.parse(tgt).unwrap().0;
5310    assert_eq!(
5311        Command::SetMinPulseWidth(SetMinPulseWidth {
5312            low: true,
5313            high: true,
5314            value: 0.1,
5315            object_list: Some(Object::String(ObjectString {
5316                strings: vec![String::from("a")]
5317            })),
5318        }),
5319        ret
5320    );
5321    assert_eq!(tgt, format!("{}", ret));
5322}
5323
5324// -----------------------------------------------------------------------------
5325
5326/// A type containing information of `set_multicycle_path`
5327#[derive(Clone, Debug, Default, PartialEq)]
5328pub struct SetMulticyclePath {
5329    pub setup: bool,
5330    pub hold: bool,
5331    pub rise: bool,
5332    pub fall: bool,
5333    pub start: bool,
5334    pub end: bool,
5335    pub from: Option<Object>,
5336    pub to: Option<Object>,
5337    pub through: Option<Object>,
5338    pub rise_from: Option<Object>,
5339    pub rise_to: Option<Object>,
5340    pub rise_through: Option<Object>,
5341    pub fall_from: Option<Object>,
5342    pub fall_to: Option<Object>,
5343    pub fall_through: Option<Object>,
5344    pub comment: Option<String>,
5345    pub path_multiplier: f64,
5346}
5347
5348impl fmt::Display for SetMulticyclePath {
5349    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5350        let mut args = String::from("");
5351        if self.setup {
5352            args.push_str(" -setup");
5353        }
5354        if self.hold {
5355            args.push_str(" -hold");
5356        }
5357        if self.rise {
5358            args.push_str(" -rise");
5359        }
5360        if self.fall {
5361            args.push_str(" -fall");
5362        }
5363        if self.start {
5364            args.push_str(" -start");
5365        }
5366        if self.end {
5367            args.push_str(" -end");
5368        }
5369        if let Some(from) = &self.from {
5370            args.push_str(&format!(" -from {}", from));
5371        }
5372        if let Some(to) = &self.to {
5373            args.push_str(&format!(" -to {}", to));
5374        }
5375        if let Some(through) = &self.through {
5376            args.push_str(&format!(" -through {}", through));
5377        }
5378        if let Some(rise_from) = &self.rise_from {
5379            args.push_str(&format!(" -rise_from {}", rise_from));
5380        }
5381        if let Some(rise_to) = &self.rise_to {
5382            args.push_str(&format!(" -rise_to {}", rise_to));
5383        }
5384        if let Some(rise_through) = &self.rise_through {
5385            args.push_str(&format!(" -rise_through {}", rise_through));
5386        }
5387        if let Some(fall_from) = &self.fall_from {
5388            args.push_str(&format!(" -fall_from {}", fall_from));
5389        }
5390        if let Some(fall_to) = &self.fall_to {
5391            args.push_str(&format!(" -fall_to {}", fall_to));
5392        }
5393        if let Some(fall_through) = &self.fall_through {
5394            args.push_str(&format!(" -fall_through {}", fall_through));
5395        }
5396        if let Some(comment) = &self.comment {
5397            args.push_str(&format!(" -comment \"{}\"", comment));
5398        }
5399        args.push_str(&format!(" {}", self.path_multiplier));
5400        write!(f, "set_multicycle_path{}", args)
5401    }
5402}
5403
5404fn set_multicycle_path<I>() -> impl Parser<Input = I, Output = Command>
5405where
5406    I: Stream<Item = char>,
5407    I::Error: ParseError<I::Item, I::Range, I::Position>,
5408{
5409    let command = symbol("set_multicycle_path");
5410    let setup = symbol("-setup").map(|_| CommandArg::Setup);
5411    let hold = symbol("-hold").map(|_| CommandArg::Hold);
5412    let rise = symbol("-rise").map(|_| CommandArg::Rise);
5413    let fall = symbol("-fall").map(|_| CommandArg::Fall);
5414    let start = symbol("-start").map(|_| CommandArg::Start);
5415    let end = symbol("-end").map(|_| CommandArg::End);
5416    let from = symbol("-from")
5417        .with(parser(object))
5418        .map(|x| CommandArg::From(x));
5419    let to = symbol("-to")
5420        .with(parser(object))
5421        .map(|x| CommandArg::To(x));
5422    let through = symbol("-through")
5423        .with(parser(object))
5424        .map(|x| CommandArg::Through(x));
5425    let rise_from = symbol("-rise_from")
5426        .with(parser(object))
5427        .map(|x| CommandArg::RiseFrom(x));
5428    let rise_to = symbol("-rise_to")
5429        .with(parser(object))
5430        .map(|x| CommandArg::RiseTo(x));
5431    let rise_through = symbol("-rise_through")
5432        .with(parser(object))
5433        .map(|x| CommandArg::RiseThrough(x));
5434    let fall_from = symbol("-fall_from")
5435        .with(parser(object))
5436        .map(|x| CommandArg::FallFrom(x));
5437    let fall_to = symbol("-fall_to")
5438        .with(parser(object))
5439        .map(|x| CommandArg::FallTo(x));
5440    let fall_through = symbol("-fall_through")
5441        .with(parser(object))
5442        .map(|x| CommandArg::FallThrough(x));
5443    let comment = symbol("-comment")
5444        .with(item())
5445        .map(|x| CommandArg::Comment(x));
5446    let path_multiplier = float().map(|x| CommandArg::Value(x));
5447    let args = (
5448        attempt(setup),
5449        attempt(hold),
5450        attempt(start),
5451        attempt(end),
5452        attempt(from),
5453        attempt(to),
5454        attempt(through),
5455        attempt(rise_from),
5456        attempt(rise_to),
5457        attempt(rise_through),
5458        attempt(fall_from),
5459        attempt(fall_to),
5460        attempt(fall_through),
5461        attempt(rise),
5462        attempt(fall),
5463        attempt(comment),
5464        attempt(path_multiplier),
5465    );
5466    command
5467        .with(many(choice(args)))
5468        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
5469            let mut setup = false;
5470            let mut hold = false;
5471            let mut rise = false;
5472            let mut fall = false;
5473            let mut start = false;
5474            let mut end = false;
5475            let mut from = None;
5476            let mut to = None;
5477            let mut through = None;
5478            let mut rise_from = None;
5479            let mut rise_to = None;
5480            let mut rise_through = None;
5481            let mut fall_from = None;
5482            let mut fall_to = None;
5483            let mut fall_through = None;
5484            let mut comment = None;
5485            let mut path_multiplier = None;
5486            for x in xs {
5487                match x {
5488                    CommandArg::Setup => setup = true,
5489                    CommandArg::Hold => hold = true,
5490                    CommandArg::Rise => rise = true,
5491                    CommandArg::Fall => fall = true,
5492                    CommandArg::Start => start = true,
5493                    CommandArg::End => end = true,
5494                    CommandArg::From(x) => from = Some(x),
5495                    CommandArg::To(x) => to = Some(x),
5496                    CommandArg::Through(x) => through = Some(x),
5497                    CommandArg::RiseFrom(x) => rise_from = Some(x),
5498                    CommandArg::RiseTo(x) => rise_to = Some(x),
5499                    CommandArg::RiseThrough(x) => rise_through = Some(x),
5500                    CommandArg::FallFrom(x) => fall_from = Some(x),
5501                    CommandArg::FallTo(x) => fall_to = Some(x),
5502                    CommandArg::FallThrough(x) => fall_through = Some(x),
5503                    CommandArg::Comment(x) => comment = Some(x),
5504                    CommandArg::Value(x) => path_multiplier = Some(x),
5505                    _ => unreachable!(),
5506                }
5507            }
5508            let path_multiplier = path_multiplier.ok_or(
5509                AndThenError::<I>::message_static_message("set_multicycle_path:path_multiplier"),
5510            )?;
5511            Ok(Command::SetMulticyclePath(SetMulticyclePath {
5512                setup,
5513                hold,
5514                rise,
5515                fall,
5516                start,
5517                end,
5518                from,
5519                to,
5520                through,
5521                rise_from,
5522                rise_to,
5523                rise_through,
5524                fall_from,
5525                fall_to,
5526                fall_through,
5527                comment,
5528                path_multiplier,
5529            }))
5530        })
5531}
5532
5533#[test]
5534fn test_set_multicycle_path() {
5535    let mut parser = command();
5536    let tgt = "set_multicycle_path -setup -hold -rise -fall -start -end -from a -to a -through a -rise_from a -rise_to a -rise_through a -fall_from a -fall_to a -fall_through a -comment \"aaa\" 0.1";
5537    let ret = parser.parse(tgt).unwrap().0;
5538    assert_eq!(
5539        Command::SetMulticyclePath(SetMulticyclePath {
5540            setup: true,
5541            hold: true,
5542            rise: true,
5543            fall: true,
5544            start: true,
5545            end: true,
5546            from: Some(Object::String(ObjectString {
5547                strings: vec![String::from("a")]
5548            })),
5549            to: Some(Object::String(ObjectString {
5550                strings: vec![String::from("a")]
5551            })),
5552            through: Some(Object::String(ObjectString {
5553                strings: vec![String::from("a")]
5554            })),
5555            rise_from: Some(Object::String(ObjectString {
5556                strings: vec![String::from("a")]
5557            })),
5558            rise_to: Some(Object::String(ObjectString {
5559                strings: vec![String::from("a")]
5560            })),
5561            rise_through: Some(Object::String(ObjectString {
5562                strings: vec![String::from("a")]
5563            })),
5564            fall_from: Some(Object::String(ObjectString {
5565                strings: vec![String::from("a")]
5566            })),
5567            fall_to: Some(Object::String(ObjectString {
5568                strings: vec![String::from("a")]
5569            })),
5570            fall_through: Some(Object::String(ObjectString {
5571                strings: vec![String::from("a")]
5572            })),
5573            comment: Some(String::from("aaa")),
5574            path_multiplier: 0.1,
5575        }),
5576        ret
5577    );
5578    assert_eq!(tgt, format!("{}", ret));
5579}
5580
5581// -----------------------------------------------------------------------------
5582
5583/// A type containing information of `set_operating_conditions`
5584#[derive(Clone, Debug, PartialEq)]
5585pub struct SetOperatingConditions {
5586    pub library: Option<Object>,
5587    pub analysis_type: Option<String>,
5588    pub max: Option<String>,
5589    pub min: Option<String>,
5590    pub max_library: Option<Object>,
5591    pub min_library: Option<Object>,
5592    pub object_list: Option<Object>,
5593    pub condition: Option<String>,
5594}
5595
5596impl fmt::Display for SetOperatingConditions {
5597    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5598        let mut args = String::from("");
5599        if let Some(library) = &self.library {
5600            args.push_str(&format!(" -library {}", library));
5601        }
5602        if let Some(analysis_type) = &self.analysis_type {
5603            args.push_str(&format!(" -analysis_type {}", analysis_type));
5604        }
5605        if let Some(max) = &self.max {
5606            args.push_str(&format!(" -max {}", max));
5607        }
5608        if let Some(min) = &self.min {
5609            args.push_str(&format!(" -min {}", min));
5610        }
5611        if let Some(max_library) = &self.max_library {
5612            args.push_str(&format!(" -max_library {}", max_library));
5613        }
5614        if let Some(min_library) = &self.min_library {
5615            args.push_str(&format!(" -min_library {}", min_library));
5616        }
5617        if let Some(object_list) = &self.object_list {
5618            args.push_str(&format!(" -object_list {}", object_list));
5619        }
5620        if let Some(condition) = &self.condition {
5621            args.push_str(&format!(" {}", condition));
5622        }
5623        write!(f, "set_operating_conditions{}", args)
5624    }
5625}
5626
5627fn set_operating_conditions<I>() -> impl Parser<Input = I, Output = Command>
5628where
5629    I: Stream<Item = char>,
5630    I::Error: ParseError<I::Item, I::Range, I::Position>,
5631{
5632    let command = symbol("set_operating_conditions");
5633    let library = symbol("-library")
5634        .with(parser(object))
5635        .map(|x| CommandArg::Library(x));
5636    let analysis_type = symbol("-analysis_type")
5637        .with(item())
5638        .map(|x| CommandArg::AnalysisType(x));
5639    let max = symbol("-max").with(item()).map(|x| CommandArg::MaxStr(x));
5640    let min = symbol("-min").with(item()).map(|x| CommandArg::MinStr(x));
5641    let max_library = symbol("-max_library")
5642        .with(parser(object))
5643        .map(|x| CommandArg::MaxLibrary(x));
5644    let min_library = symbol("-min_library")
5645        .with(parser(object))
5646        .map(|x| CommandArg::MinLibrary(x));
5647    let object_list = symbol("-object_list")
5648        .with(parser(object))
5649        .map(|x| CommandArg::ObjectList(x));
5650    let condition = item().map(|x| CommandArg::String(x));
5651    let args = (
5652        attempt(library),
5653        attempt(analysis_type),
5654        attempt(max),
5655        attempt(min),
5656        attempt(max_library),
5657        attempt(min_library),
5658        attempt(object_list),
5659        attempt(condition),
5660    );
5661    command
5662        .with(many(choice(args)))
5663        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
5664            let mut library = None;
5665            let mut analysis_type = None;
5666            let mut max = None;
5667            let mut min = None;
5668            let mut max_library = None;
5669            let mut min_library = None;
5670            let mut object_list = None;
5671            let mut condition = None;
5672            for x in xs {
5673                match x {
5674                    CommandArg::Library(x) => library = Some(x),
5675                    CommandArg::AnalysisType(x) => analysis_type = Some(x),
5676                    CommandArg::MaxStr(x) => max = Some(x),
5677                    CommandArg::MinStr(x) => min = Some(x),
5678                    CommandArg::MaxLibrary(x) => max_library = Some(x),
5679                    CommandArg::MinLibrary(x) => min_library = Some(x),
5680                    CommandArg::ObjectList(x) => object_list = Some(x),
5681                    CommandArg::String(x) => condition = Some(x),
5682                    _ => unreachable!(),
5683                }
5684            }
5685            Ok(Command::SetOperatingConditions(SetOperatingConditions {
5686                library,
5687                analysis_type,
5688                max,
5689                min,
5690                max_library,
5691                min_library,
5692                object_list,
5693                condition,
5694            }))
5695        })
5696}
5697
5698#[test]
5699fn test_set_operating_conditions() {
5700    let mut parser = command();
5701    let tgt =
5702        "set_operating_conditions -library a -analysis_type a -max a -min a -max_library a -min_library a -object_list a a";
5703    let ret = parser.parse(tgt).unwrap().0;
5704    assert_eq!(
5705        Command::SetOperatingConditions(SetOperatingConditions {
5706            library: Some(Object::String(ObjectString {
5707                strings: vec![String::from("a")]
5708            })),
5709            analysis_type: Some(String::from("a")),
5710            max: Some(String::from("a")),
5711            min: Some(String::from("a")),
5712            max_library: Some(Object::String(ObjectString {
5713                strings: vec![String::from("a")]
5714            })),
5715            min_library: Some(Object::String(ObjectString {
5716                strings: vec![String::from("a")]
5717            })),
5718            object_list: Some(Object::String(ObjectString {
5719                strings: vec![String::from("a")]
5720            })),
5721            condition: Some(String::from("a")),
5722        }),
5723        ret
5724    );
5725    assert_eq!(tgt, format!("{}", ret));
5726}
5727
5728// -----------------------------------------------------------------------------
5729
5730/// A type containing information of `set_output_delay`
5731#[derive(Clone, Debug, Default, PartialEq)]
5732pub struct SetOutputDelay {
5733    pub clock: Option<Object>,
5734    pub reference_pin: Option<Object>,
5735    pub clock_fall: bool,
5736    pub level_sensitive: bool,
5737    pub rise: bool,
5738    pub fall: bool,
5739    pub max: bool,
5740    pub min: bool,
5741    pub add_delay: bool,
5742    pub network_latency_included: bool,
5743    pub source_latency_included: bool,
5744    pub delay_value: f64,
5745    pub port_pin_list: Object,
5746}
5747
5748impl fmt::Display for SetOutputDelay {
5749    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5750        let mut args = String::from("");
5751        if let Some(clock) = &self.clock {
5752            args.push_str(&format!(" -clock {}", clock));
5753        }
5754        if let Some(reference_pin) = &self.reference_pin {
5755            args.push_str(&format!(" -reference_pin {}", reference_pin));
5756        }
5757        if self.clock_fall {
5758            args.push_str(" -clock_fall");
5759        }
5760        if self.level_sensitive {
5761            args.push_str(" -level_sensitive");
5762        }
5763        if self.rise {
5764            args.push_str(" -rise");
5765        }
5766        if self.fall {
5767            args.push_str(" -fall");
5768        }
5769        if self.max {
5770            args.push_str(" -max");
5771        }
5772        if self.min {
5773            args.push_str(" -min");
5774        }
5775        if self.add_delay {
5776            args.push_str(" -add_delay");
5777        }
5778        if self.network_latency_included {
5779            args.push_str(" -network_latency_included");
5780        }
5781        if self.source_latency_included {
5782            args.push_str(" -source_latency_included");
5783        }
5784        args.push_str(&format!(" {}", self.delay_value));
5785        args.push_str(&format!(" {}", self.port_pin_list));
5786        write!(f, "set_output_delay{}", args)
5787    }
5788}
5789
5790fn set_output_delay<I>() -> impl Parser<Input = I, Output = Command>
5791where
5792    I: Stream<Item = char>,
5793    I::Error: ParseError<I::Item, I::Range, I::Position>,
5794{
5795    let command = symbol("set_output_delay");
5796    let clock = symbol("-clock")
5797        .with(parser(object))
5798        .map(|x| CommandArg::ClockObj(x));
5799    let reference_pin = symbol("-reference_pin")
5800        .with(parser(object))
5801        .map(|x| CommandArg::ReferencePin(x));
5802    let clock_fall = symbol("-clock_fall").map(|_| CommandArg::ClockFall);
5803    let level_sensitive = symbol("-level_sensitive").map(|_| CommandArg::LevelSensitive);
5804    let rise = symbol("-rise").map(|_| CommandArg::Rise);
5805    let fall = symbol("-fall").map(|_| CommandArg::Fall);
5806    let max = symbol("-max").map(|_| CommandArg::Max);
5807    let min = symbol("-min").map(|_| CommandArg::Min);
5808    let add_delay = symbol("-add_delay").map(|_| CommandArg::AddDelay);
5809    let network_latency_included =
5810        symbol("-network_latency_included").map(|_| CommandArg::NetworkLatencyIncluded);
5811    let source_latency_included =
5812        symbol("-source_latency_included").map(|_| CommandArg::SourceLatencyIncluded);
5813    let delay_value = float().map(|x| CommandArg::Value(x));
5814    let port_pin_list = parser(object).map(|x| CommandArg::Object(x));
5815    let args = (
5816        attempt(clock),
5817        attempt(reference_pin),
5818        attempt(clock_fall),
5819        attempt(level_sensitive),
5820        attempt(rise),
5821        attempt(fall),
5822        attempt(max),
5823        attempt(min),
5824        attempt(add_delay),
5825        attempt(network_latency_included),
5826        attempt(source_latency_included),
5827        attempt(delay_value),
5828        attempt(port_pin_list),
5829    );
5830    command
5831        .with(many(choice(args)))
5832        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
5833            let mut clock = None;
5834            let mut reference_pin = None;
5835            let mut clock_fall = false;
5836            let mut level_sensitive = false;
5837            let mut rise = false;
5838            let mut fall = false;
5839            let mut max = false;
5840            let mut min = false;
5841            let mut add_delay = false;
5842            let mut network_latency_included = false;
5843            let mut source_latency_included = false;
5844            let mut delay_value = None;
5845            let mut port_pin_list = None;
5846            for x in xs {
5847                match x {
5848                    CommandArg::ClockObj(x) => clock = Some(x),
5849                    CommandArg::ReferencePin(x) => reference_pin = Some(x),
5850                    CommandArg::ClockFall => clock_fall = true,
5851                    CommandArg::LevelSensitive => level_sensitive = true,
5852                    CommandArg::Rise => rise = true,
5853                    CommandArg::Fall => fall = true,
5854                    CommandArg::Max => max = true,
5855                    CommandArg::Min => min = true,
5856                    CommandArg::AddDelay => add_delay = true,
5857                    CommandArg::NetworkLatencyIncluded => network_latency_included = true,
5858                    CommandArg::SourceLatencyIncluded => source_latency_included = true,
5859                    CommandArg::Value(x) => delay_value = Some(x),
5860                    CommandArg::Object(x) => port_pin_list = Some(x),
5861                    _ => unreachable!(),
5862                }
5863            }
5864            let delay_value = delay_value.ok_or(AndThenError::<I>::message_static_message(
5865                "set_output_delay:delay_value",
5866            ))?;
5867            let port_pin_list = port_pin_list.ok_or(AndThenError::<I>::message_static_message(
5868                "set_output_delay:port_pin_list",
5869            ))?;
5870            Ok(Command::SetOutputDelay(SetOutputDelay {
5871                clock,
5872                reference_pin,
5873                clock_fall,
5874                level_sensitive,
5875                rise,
5876                fall,
5877                max,
5878                min,
5879                add_delay,
5880                network_latency_included,
5881                source_latency_included,
5882                delay_value,
5883                port_pin_list,
5884            }))
5885        })
5886}
5887
5888#[test]
5889fn test_set_output_delay() {
5890    let mut parser = command();
5891    let tgt = "set_output_delay -clock a -reference_pin a -clock_fall -level_sensitive -rise -fall -max -min -add_delay -network_latency_included -source_latency_included 0.1 a";
5892    let ret = parser.parse(tgt).unwrap().0;
5893    assert_eq!(
5894        Command::SetOutputDelay(SetOutputDelay {
5895            clock: Some(Object::String(ObjectString {
5896                strings: vec![String::from("a")]
5897            })),
5898            reference_pin: Some(Object::String(ObjectString {
5899                strings: vec![String::from("a")]
5900            })),
5901            clock_fall: true,
5902            level_sensitive: true,
5903            rise: true,
5904            fall: true,
5905            min: true,
5906            max: true,
5907            add_delay: true,
5908            network_latency_included: true,
5909            source_latency_included: true,
5910            delay_value: 0.1,
5911            port_pin_list: Object::String(ObjectString {
5912                strings: vec![String::from("a")]
5913            }),
5914        }),
5915        ret
5916    );
5917    assert_eq!(tgt, format!("{}", ret));
5918}
5919
5920// -----------------------------------------------------------------------------
5921
5922/// A type containing information of `set_port_fanout_number`
5923#[derive(Clone, Debug, Default, PartialEq)]
5924pub struct SetPortFanoutNumber {
5925    pub value: f64,
5926    pub port_list: Object,
5927}
5928
5929impl fmt::Display for SetPortFanoutNumber {
5930    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5931        let mut args = String::from("");
5932        args.push_str(&format!(" {}", self.value));
5933        args.push_str(&format!(" {}", self.port_list));
5934        write!(f, "set_port_fanout_number{}", args)
5935    }
5936}
5937
5938fn set_port_fanout_number<I>() -> impl Parser<Input = I, Output = Command>
5939where
5940    I: Stream<Item = char>,
5941    I::Error: ParseError<I::Item, I::Range, I::Position>,
5942{
5943    let command = symbol("set_port_fanout_number");
5944    let value = float().map(|x| CommandArg::Value(x));
5945    let port_list = parser(object).map(|x| CommandArg::Object(x));
5946    let args = (attempt(value), attempt(port_list));
5947    command
5948        .with(many(choice(args)))
5949        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
5950            let mut value = None;
5951            let mut port_list = None;
5952            for x in xs {
5953                match x {
5954                    CommandArg::Value(x) => value = Some(x),
5955                    CommandArg::Object(x) => port_list = Some(x),
5956                    _ => unreachable!(),
5957                }
5958            }
5959            let value = value.ok_or(AndThenError::<I>::message_static_message(
5960                "set_port_fanout_number:value",
5961            ))?;
5962            let port_list = port_list.ok_or(AndThenError::<I>::message_static_message(
5963                "set_port_fanout_number:port_list",
5964            ))?;
5965            Ok(Command::SetPortFanoutNumber(SetPortFanoutNumber {
5966                value,
5967                port_list,
5968            }))
5969        })
5970}
5971
5972#[test]
5973fn test_set_port_fanout_number() {
5974    let mut parser = command();
5975    let tgt = "set_port_fanout_number 0.1 a";
5976    let ret = parser.parse(tgt).unwrap().0;
5977    assert_eq!(
5978        Command::SetPortFanoutNumber(SetPortFanoutNumber {
5979            value: 0.1,
5980            port_list: Object::String(ObjectString {
5981                strings: vec![String::from("a")]
5982            }),
5983        }),
5984        ret
5985    );
5986    assert_eq!(tgt, format!("{}", ret));
5987}
5988
5989// -----------------------------------------------------------------------------
5990
5991/// A type containing information of `set_propagated_clock`
5992#[derive(Clone, Debug, Default, PartialEq)]
5993pub struct SetPropagatedClock {
5994    pub object_list: Object,
5995}
5996
5997impl fmt::Display for SetPropagatedClock {
5998    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5999        let mut args = String::from("");
6000        args.push_str(&format!(" {}", self.object_list));
6001        write!(f, "set_propagated_clock{}", args)
6002    }
6003}
6004
6005fn set_propagated_clock<I>() -> impl Parser<Input = I, Output = Command>
6006where
6007    I: Stream<Item = char>,
6008    I::Error: ParseError<I::Item, I::Range, I::Position>,
6009{
6010    let command = symbol("set_propagated_clock");
6011    let object_list = parser(object).map(|x| CommandArg::Object(x));
6012    let args = (attempt(object_list),);
6013    command
6014        .with(many(choice(args)))
6015        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6016            let mut object_list = None;
6017            for x in xs {
6018                match x {
6019                    CommandArg::Object(x) => object_list = Some(x),
6020                    _ => unreachable!(),
6021                }
6022            }
6023            let object_list = object_list.ok_or(AndThenError::<I>::message_static_message(
6024                "set_propagated_clock:object_list",
6025            ))?;
6026            Ok(Command::SetPropagatedClock(SetPropagatedClock {
6027                object_list,
6028            }))
6029        })
6030}
6031
6032#[test]
6033fn test_set_propagated_clock() {
6034    let mut parser = command();
6035    let tgt = "set_propagated_clock a";
6036    let ret = parser.parse(tgt).unwrap().0;
6037    assert_eq!(
6038        Command::SetPropagatedClock(SetPropagatedClock {
6039            object_list: Object::String(ObjectString {
6040                strings: vec![String::from("a")]
6041            }),
6042        }),
6043        ret
6044    );
6045    assert_eq!(tgt, format!("{}", ret));
6046}
6047
6048// -----------------------------------------------------------------------------
6049
6050/// A type containing information of `set_resistance`
6051#[derive(Clone, Debug, Default, PartialEq)]
6052pub struct SetResistance {
6053    pub min: bool,
6054    pub max: bool,
6055    pub value: f64,
6056    pub net_list: Object,
6057}
6058
6059impl fmt::Display for SetResistance {
6060    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6061        let mut args = String::from("");
6062        if self.min {
6063            args.push_str(" -min");
6064        }
6065        if self.max {
6066            args.push_str(" -max");
6067        }
6068        args.push_str(&format!(" {}", self.value));
6069        args.push_str(&format!(" {}", self.net_list));
6070        write!(f, "set_resistance{}", args)
6071    }
6072}
6073
6074fn set_resistance<I>() -> impl Parser<Input = I, Output = Command>
6075where
6076    I: Stream<Item = char>,
6077    I::Error: ParseError<I::Item, I::Range, I::Position>,
6078{
6079    let command = symbol("set_resistance");
6080    let min = symbol("-min").map(|_| CommandArg::Min);
6081    let max = symbol("-max").map(|_| CommandArg::Max);
6082    let value = float().map(|x| CommandArg::Value(x));
6083    let net_list = parser(object).map(|x| CommandArg::Object(x));
6084    let args = (
6085        attempt(min),
6086        attempt(max),
6087        attempt(value),
6088        attempt(net_list),
6089    );
6090    command
6091        .with(many(choice(args)))
6092        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6093            let mut min = false;
6094            let mut max = false;
6095            let mut value = None;
6096            let mut net_list = None;
6097            for x in xs {
6098                match x {
6099                    CommandArg::Min => min = true,
6100                    CommandArg::Max => max = true,
6101                    CommandArg::Value(x) => value = Some(x),
6102                    CommandArg::Object(x) => net_list = Some(x),
6103                    _ => unreachable!(),
6104                }
6105            }
6106            let value = value.ok_or(AndThenError::<I>::message_static_message(
6107                "set_resistance:value",
6108            ))?;
6109            let net_list = net_list.ok_or(AndThenError::<I>::message_static_message(
6110                "set_resistance:net_list",
6111            ))?;
6112            Ok(Command::SetResistance(SetResistance {
6113                min,
6114                max,
6115                value,
6116                net_list,
6117            }))
6118        })
6119}
6120
6121#[test]
6122fn test_set_resistance() {
6123    let mut parser = command();
6124    let tgt = "set_resistance -min -max 0.1 a";
6125    let ret = parser.parse(tgt).unwrap().0;
6126    assert_eq!(
6127        Command::SetResistance(SetResistance {
6128            min: true,
6129            max: true,
6130            value: 0.1,
6131            net_list: Object::String(ObjectString {
6132                strings: vec![String::from("a")]
6133            }),
6134        }),
6135        ret
6136    );
6137    assert_eq!(tgt, format!("{}", ret));
6138}
6139
6140// -----------------------------------------------------------------------------
6141
6142/// A type containing information of `set_sense`
6143#[derive(Clone, Debug, Default, PartialEq)]
6144pub struct SetSense {
6145    pub r#type: Option<String>,
6146    pub non_unate: bool,
6147    pub positive: bool,
6148    pub negative: bool,
6149    pub clock_leaf: bool,
6150    pub stop_propagation: bool,
6151    pub pulse: Option<String>,
6152    pub clocks: Option<Object>,
6153    pub pin_list: Object,
6154}
6155
6156impl fmt::Display for SetSense {
6157    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6158        let mut args = String::from("");
6159        if let Some(r#type) = &self.r#type {
6160            args.push_str(&format!(" -type {}", r#type));
6161        }
6162        if self.non_unate {
6163            args.push_str(" -non_unate");
6164        }
6165        if self.positive {
6166            args.push_str(" -positive");
6167        }
6168        if self.negative {
6169            args.push_str(" -negative");
6170        }
6171        if self.clock_leaf {
6172            args.push_str(" -clock_leaf");
6173        }
6174        if self.stop_propagation {
6175            args.push_str(" -stop_propagation");
6176        }
6177        if let Some(pulse) = &self.pulse {
6178            args.push_str(&format!(" -pulse {}", pulse));
6179        }
6180        if let Some(clocks) = &self.clocks {
6181            args.push_str(&format!(" -clocks {}", clocks));
6182        }
6183        args.push_str(&format!(" {}", self.pin_list));
6184        write!(f, "set_sense{}", args)
6185    }
6186}
6187
6188fn set_sense<I>() -> impl Parser<Input = I, Output = Command>
6189where
6190    I: Stream<Item = char>,
6191    I::Error: ParseError<I::Item, I::Range, I::Position>,
6192{
6193    let command = symbol("set_sense");
6194    let r#type = symbol("-type").with(item()).map(|x| CommandArg::Type(x));
6195    let non_unate = symbol("-non_unate").map(|_| CommandArg::NonUnate);
6196    let positive = symbol("-positive").map(|_| CommandArg::Positive);
6197    let negative = symbol("-negative").map(|_| CommandArg::Negative);
6198    let clock_leaf = symbol("-clock_leaf").map(|_| CommandArg::ClockLeaf);
6199    let stop_propagation = symbol("-stop_propagation").map(|_| CommandArg::StopPropagation);
6200    let pulse = symbol("-pulse").with(item()).map(|x| CommandArg::Pulse(x));
6201    let clocks = symbol("-clocks")
6202        .with(parser(object))
6203        .map(|x| CommandArg::Clocks(x));
6204    let pin_list = parser(object).map(|x| CommandArg::Object(x));
6205    let args = (
6206        attempt(r#type),
6207        attempt(non_unate),
6208        attempt(positive),
6209        attempt(negative),
6210        attempt(clock_leaf),
6211        attempt(stop_propagation),
6212        attempt(pulse),
6213        attempt(clocks),
6214        attempt(pin_list),
6215    );
6216    command
6217        .with(many(choice(args)))
6218        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6219            let mut r#type = None;
6220            let mut non_unate = false;
6221            let mut positive = false;
6222            let mut negative = false;
6223            let mut clock_leaf = false;
6224            let mut stop_propagation = false;
6225            let mut pulse = None;
6226            let mut clocks = None;
6227            let mut pin_list = None;
6228            for x in xs {
6229                match x {
6230                    CommandArg::Type(x) => r#type = Some(x),
6231                    CommandArg::NonUnate => non_unate = true,
6232                    CommandArg::Positive => positive = true,
6233                    CommandArg::Negative => negative = true,
6234                    CommandArg::ClockLeaf => clock_leaf = true,
6235                    CommandArg::StopPropagation => stop_propagation = true,
6236                    CommandArg::Pulse(x) => pulse = Some(x),
6237                    CommandArg::Clocks(x) => clocks = Some(x),
6238                    CommandArg::Object(x) => pin_list = Some(x),
6239                    _ => unreachable!(),
6240                }
6241            }
6242            let pin_list = pin_list.ok_or(AndThenError::<I>::message_static_message(
6243                "set_sense:pin_list",
6244            ))?;
6245            Ok(Command::SetSense(SetSense {
6246                r#type,
6247                non_unate,
6248                positive,
6249                negative,
6250                clock_leaf,
6251                stop_propagation,
6252                pulse,
6253                clocks,
6254                pin_list,
6255            }))
6256        })
6257}
6258
6259#[test]
6260fn test_set_sense() {
6261    let mut parser = command();
6262    let tgt =
6263        "set_sense -type clock -non_unate -positive -negative -clock_leaf -stop_propagation -pulse a -clocks clk pin";
6264    let ret = parser.parse(tgt).unwrap().0;
6265    assert_eq!(
6266        Command::SetSense(SetSense {
6267            r#type: Some(String::from("clock")),
6268            non_unate: true,
6269            positive: true,
6270            negative: true,
6271            clock_leaf: true,
6272            stop_propagation: true,
6273            pulse: Some(String::from("a")),
6274            clocks: Some(Object::String(ObjectString {
6275                strings: vec![String::from("clk")]
6276            })),
6277            pin_list: Object::String(ObjectString {
6278                strings: vec![String::from("pin")]
6279            }),
6280        }),
6281        ret
6282    );
6283    assert_eq!(tgt, format!("{}", ret));
6284}
6285
6286// -----------------------------------------------------------------------------
6287
6288/// A type containing information of `set_timing_derate`
6289#[derive(Clone, Debug, Default, PartialEq)]
6290pub struct SetTimingDerate {
6291    pub cell_delay: bool,
6292    pub cell_check: bool,
6293    pub net_delay: bool,
6294    pub data: bool,
6295    pub clock: bool,
6296    pub early: bool,
6297    pub late: bool,
6298    pub rise: bool,
6299    pub fall: bool,
6300    pub r#static: bool,
6301    pub dynamic: bool,
6302    pub increment: bool,
6303    pub derate_value: f64,
6304    pub object_list: Option<Object>,
6305}
6306
6307impl fmt::Display for SetTimingDerate {
6308    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6309        let mut args = String::from("");
6310        if self.cell_delay {
6311            args.push_str(" -cell_delay");
6312        }
6313        if self.cell_check {
6314            args.push_str(" -cell_check");
6315        }
6316        if self.net_delay {
6317            args.push_str(" -net_delay");
6318        }
6319        if self.data {
6320            args.push_str(" -data");
6321        }
6322        if self.clock {
6323            args.push_str(" -clock");
6324        }
6325        if self.early {
6326            args.push_str(" -early");
6327        }
6328        if self.late {
6329            args.push_str(" -late");
6330        }
6331        if self.rise {
6332            args.push_str(" -rise");
6333        }
6334        if self.fall {
6335            args.push_str(" -fall");
6336        }
6337        if self.r#static {
6338            args.push_str(" -static");
6339        }
6340        if self.dynamic {
6341            args.push_str(" -dynamic");
6342        }
6343        if self.increment {
6344            args.push_str(" -increment");
6345        }
6346        args.push_str(&format!(" {}", self.derate_value));
6347        if let Some(object_list) = &self.object_list {
6348            args.push_str(&format!(" {}", object_list));
6349        }
6350        write!(f, "set_timing_derate{}", args)
6351    }
6352}
6353
6354fn set_timing_derate<I>() -> impl Parser<Input = I, Output = Command>
6355where
6356    I: Stream<Item = char>,
6357    I::Error: ParseError<I::Item, I::Range, I::Position>,
6358{
6359    let command = symbol("set_timing_derate");
6360    let cell_delay = symbol("-cell_delay").map(|_| CommandArg::CellDelay);
6361    let cell_check = symbol("-cell_check").map(|_| CommandArg::CellCheck);
6362    let net_delay = symbol("-net_delay").map(|_| CommandArg::NetDelay);
6363    let data = symbol("-data").map(|_| CommandArg::Data);
6364    let clock = symbol("-clock").map(|_| CommandArg::Clock);
6365    let early = symbol("-early").map(|_| CommandArg::Early);
6366    let late = symbol("-late").map(|_| CommandArg::Late);
6367    let rise = symbol("-rise").map(|_| CommandArg::Rise);
6368    let fall = symbol("-fall").map(|_| CommandArg::Fall);
6369    let r#static = symbol("-static").map(|_| CommandArg::Static);
6370    let dynamic = symbol("-dynamic").map(|_| CommandArg::Dynamic);
6371    let increment = symbol("-increment").map(|_| CommandArg::Increment);
6372    let derate_value = float().map(|x| CommandArg::Value(x));
6373    let object_list = parser(object).map(|x| CommandArg::Object(x));
6374    let args = (
6375        attempt(cell_delay),
6376        attempt(cell_check),
6377        attempt(net_delay),
6378        attempt(data),
6379        attempt(clock),
6380        attempt(early),
6381        attempt(late),
6382        attempt(rise),
6383        attempt(fall),
6384        attempt(r#static),
6385        attempt(dynamic),
6386        attempt(increment),
6387        attempt(derate_value),
6388        attempt(object_list),
6389    );
6390    command
6391        .with(many(choice(args)))
6392        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6393            let mut cell_delay = false;
6394            let mut cell_check = false;
6395            let mut net_delay = false;
6396            let mut data = false;
6397            let mut clock = false;
6398            let mut early = false;
6399            let mut late = false;
6400            let mut rise = false;
6401            let mut fall = false;
6402            let mut r#static = false;
6403            let mut dynamic = false;
6404            let mut increment = false;
6405            let mut derate_value = None;
6406            let mut object_list = None;
6407            for x in xs {
6408                match x {
6409                    CommandArg::CellDelay => cell_delay = true,
6410                    CommandArg::CellCheck => cell_check = true,
6411                    CommandArg::NetDelay => net_delay = true,
6412                    CommandArg::Data => data = true,
6413                    CommandArg::Clock => clock = true,
6414                    CommandArg::Early => early = true,
6415                    CommandArg::Late => late = true,
6416                    CommandArg::Rise => rise = true,
6417                    CommandArg::Fall => fall = true,
6418                    CommandArg::Static => r#static = true,
6419                    CommandArg::Dynamic => dynamic = true,
6420                    CommandArg::Increment => increment = true,
6421                    CommandArg::Value(x) => derate_value = Some(x),
6422                    CommandArg::Object(x) => object_list = Some(x),
6423                    _ => unreachable!(),
6424                }
6425            }
6426            let derate_value = derate_value.ok_or(AndThenError::<I>::message_static_message(
6427                "set_timing_derate:derate_value",
6428            ))?;
6429            Ok(Command::SetTimingDerate(SetTimingDerate {
6430                cell_delay,
6431                cell_check,
6432                net_delay,
6433                data,
6434                clock,
6435                early,
6436                late,
6437                rise,
6438                fall,
6439                r#static,
6440                dynamic,
6441                increment,
6442                derate_value,
6443                object_list,
6444            }))
6445        })
6446}
6447
6448#[test]
6449fn test_set_timing_derate() {
6450    let mut parser = command();
6451    let tgt = "set_timing_derate -cell_delay -cell_check -net_delay -data -clock -early -late -rise -fall -static -dynamic -increment 0.1 a";
6452    let ret = parser.parse(tgt).unwrap().0;
6453    assert_eq!(
6454        Command::SetTimingDerate(SetTimingDerate {
6455            cell_delay: true,
6456            cell_check: true,
6457            net_delay: true,
6458            data: true,
6459            clock: true,
6460            early: true,
6461            late: true,
6462            rise: true,
6463            fall: true,
6464            r#static: true,
6465            dynamic: true,
6466            increment: true,
6467            derate_value: 0.1,
6468            object_list: Some(Object::String(ObjectString {
6469                strings: vec![String::from("a")]
6470            })),
6471        }),
6472        ret
6473    );
6474    assert_eq!(tgt, format!("{}", ret));
6475}
6476
6477// -----------------------------------------------------------------------------
6478
6479/// A type containing information of `set_units`
6480#[derive(Clone, Debug, Default, PartialEq)]
6481pub struct SetUnits {
6482    pub capacitance: Option<UnitValue>,
6483    pub resistance: Option<UnitValue>,
6484    pub time: Option<UnitValue>,
6485    pub voltage: Option<UnitValue>,
6486    pub current: Option<UnitValue>,
6487    pub power: Option<UnitValue>,
6488}
6489
6490impl fmt::Display for SetUnits {
6491    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6492        let mut args = String::from("");
6493        if let Some(capacitance) = &self.capacitance {
6494            args.push_str(&format!(" -capacitance {}", capacitance));
6495        }
6496        if let Some(resistance) = &self.resistance {
6497            args.push_str(&format!(" -resistance {}", resistance));
6498        }
6499        if let Some(time) = &self.time {
6500            args.push_str(&format!(" -time {}", time));
6501        }
6502        if let Some(voltage) = &self.voltage {
6503            args.push_str(&format!(" -voltage {}", voltage));
6504        }
6505        if let Some(current) = &self.current {
6506            args.push_str(&format!(" -current {}", current));
6507        }
6508        if let Some(power) = &self.power {
6509            args.push_str(&format!(" -power {}", power));
6510        }
6511        write!(f, "set_units{}", args)
6512    }
6513}
6514
6515/// UnitValue
6516#[derive(Clone, Debug, Default, PartialEq)]
6517pub struct UnitValue {
6518    pub unit: String,
6519    pub value: f64,
6520}
6521
6522impl fmt::Display for UnitValue {
6523    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6524        if self.value == 1.0 {
6525            write!(f, "{}", self.unit)
6526        } else {
6527            write!(f, "{}{}", self.value, self.unit)
6528        }
6529    }
6530}
6531
6532fn unit_value<I>() -> impl Parser<Input = I, Output = UnitValue>
6533where
6534    I: Stream<Item = char>,
6535    I::Error: ParseError<I::Item, I::Range, I::Position>,
6536{
6537    let unit_value = optional(float()).and(item()).map(|(x, y)| match x {
6538        Some(x) => UnitValue { value: x, unit: y },
6539        None => UnitValue {
6540            value: 1.0,
6541            unit: y,
6542        },
6543    });
6544    unit_value
6545}
6546
6547fn set_units<I>() -> impl Parser<Input = I, Output = Command>
6548where
6549    I: Stream<Item = char>,
6550    I::Error: ParseError<I::Item, I::Range, I::Position>,
6551{
6552    let command = attempt(symbol("set_units")).or(symbol("set_unit"));
6553    let capacitance = symbol("-capacitance")
6554        .with(unit_value())
6555        .map(|x| CommandArg::Capacitance(x));
6556    let resistance = symbol("-resistance")
6557        .with(unit_value())
6558        .map(|x| CommandArg::Resistance(x));
6559    let time = symbol("-time")
6560        .with(unit_value())
6561        .map(|x| CommandArg::Time(x));
6562    let voltage = symbol("-voltage")
6563        .with(unit_value())
6564        .map(|x| CommandArg::VoltageUV(x));
6565    let current = symbol("-current")
6566        .with(unit_value())
6567        .map(|x| CommandArg::Current(x));
6568    let power = symbol("-power")
6569        .with(unit_value())
6570        .map(|x| CommandArg::Power(x));
6571    let args = (
6572        attempt(capacitance),
6573        attempt(resistance),
6574        attempt(time),
6575        attempt(voltage),
6576        attempt(current),
6577        attempt(power),
6578    );
6579    command
6580        .with(many(choice(args)))
6581        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6582            let mut capacitance = None;
6583            let mut resistance = None;
6584            let mut time = None;
6585            let mut voltage = None;
6586            let mut current = None;
6587            let mut power = None;
6588            for x in xs {
6589                match x {
6590                    CommandArg::Capacitance(x) => capacitance = Some(x),
6591                    CommandArg::Resistance(x) => resistance = Some(x),
6592                    CommandArg::Time(x) => time = Some(x),
6593                    CommandArg::VoltageUV(x) => voltage = Some(x),
6594                    CommandArg::Current(x) => current = Some(x),
6595                    CommandArg::Power(x) => power = Some(x),
6596                    _ => unreachable!(),
6597                }
6598            }
6599            Ok(Command::SetUnits(SetUnits {
6600                capacitance,
6601                resistance,
6602                time,
6603                voltage,
6604                current,
6605                power,
6606            }))
6607        })
6608}
6609
6610#[test]
6611fn test_set_units() {
6612    let mut parser = command();
6613    let tgt =
6614        "set_units -capacitance 1.2pF -resistance 10MOhm -time ns -voltage V -current mA -power mW";
6615    let ret = parser.parse(tgt).unwrap().0;
6616    assert_eq!(
6617        Command::SetUnits(SetUnits {
6618            capacitance: Some(UnitValue {
6619                value: 1.2,
6620                unit: String::from("pF")
6621            }),
6622            resistance: Some(UnitValue {
6623                value: 10.0,
6624                unit: String::from("MOhm")
6625            }),
6626            time: Some(UnitValue {
6627                value: 1.0,
6628                unit: String::from("ns")
6629            }),
6630            voltage: Some(UnitValue {
6631                value: 1.0,
6632                unit: String::from("V")
6633            }),
6634            current: Some(UnitValue {
6635                value: 1.0,
6636                unit: String::from("mA")
6637            }),
6638            power: Some(UnitValue {
6639                value: 1.0,
6640                unit: String::from("mW")
6641            }),
6642        }),
6643        ret
6644    );
6645    assert_eq!(tgt, format!("{}", ret));
6646}
6647
6648// -----------------------------------------------------------------------------
6649
6650/// A type containing information of `set sdc_version`
6651#[derive(Clone, Debug, Default, PartialEq)]
6652pub struct SetSdcVersion {
6653    pub version: f64,
6654}
6655
6656impl fmt::Display for SetSdcVersion {
6657    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6658        let mut args = String::from("");
6659        args.push_str(&format!(" {}", self.version));
6660        write!(f, "set sdc_version{}", args)
6661    }
6662}
6663
6664fn set_sdc_version<I>() -> impl Parser<Input = I, Output = Command>
6665where
6666    I: Stream<Item = char>,
6667    I::Error: ParseError<I::Item, I::Range, I::Position>,
6668{
6669    let command = symbol("set").with(symbol("sdc_version"));
6670    let version = float().map(|x| Command::SetSdcVersion(SetSdcVersion { version: x }));
6671    command.with(version)
6672}
6673
6674#[test]
6675fn test_set_sdc_version() {
6676    let mut parser = command();
6677    let tgt = "set sdc_version 2.1";
6678    let ret = parser.parse(tgt).unwrap().0;
6679    assert_eq!(Command::SetSdcVersion(SetSdcVersion { version: 2.1 }), ret);
6680    assert_eq!(tgt, format!("{}", ret));
6681}
6682
6683// -----------------------------------------------------------------------------
6684
6685/// A type containing information of `set_voltage`
6686#[derive(Clone, Debug, Default, PartialEq)]
6687pub struct SetVoltage {
6688    pub min: Option<f64>,
6689    pub object_list: Option<Object>,
6690    pub max_case_voltage: f64,
6691}
6692
6693impl fmt::Display for SetVoltage {
6694    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6695        let mut args = String::from("");
6696        if let Some(min) = &self.min {
6697            args.push_str(&format!(" -min {}", min));
6698        }
6699        if let Some(object_list) = &self.object_list {
6700            args.push_str(&format!(" -object_list {}", object_list));
6701        }
6702        args.push_str(&format!(" {}", self.max_case_voltage));
6703        write!(f, "set_voltage{}", args)
6704    }
6705}
6706
6707fn set_voltage<I>() -> impl Parser<Input = I, Output = Command>
6708where
6709    I: Stream<Item = char>,
6710    I::Error: ParseError<I::Item, I::Range, I::Position>,
6711{
6712    let command = symbol("set_voltage");
6713    let min = symbol("-min").with(float()).map(|x| CommandArg::MinVal(x));
6714    let object_list = symbol("-object_list")
6715        .with(parser(object))
6716        .map(|x| CommandArg::ObjectList(x));
6717    let max_case_voltage = float().map(|x| CommandArg::Value(x));
6718    let args = (
6719        attempt(min),
6720        attempt(object_list),
6721        attempt(max_case_voltage),
6722    );
6723    command
6724        .with(many(choice(args)))
6725        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6726            let mut min = None;
6727            let mut object_list = None;
6728            let mut max_case_voltage = None;
6729            for x in xs {
6730                match x {
6731                    CommandArg::MinVal(x) => min = Some(x),
6732                    CommandArg::ObjectList(x) => object_list = Some(x),
6733                    CommandArg::Value(x) => max_case_voltage = Some(x),
6734                    _ => unreachable!(),
6735                }
6736            }
6737            let max_case_voltage = max_case_voltage.ok_or(
6738                AndThenError::<I>::message_static_message("set_voltage:max_case_voltage"),
6739            )?;
6740            Ok(Command::SetVoltage(SetVoltage {
6741                min,
6742                object_list,
6743                max_case_voltage,
6744            }))
6745        })
6746}
6747
6748#[test]
6749fn test_set_voltage() {
6750    let mut parser = command();
6751    let tgt = "set_voltage -min 0.1 -object_list a 0.1";
6752    let ret = parser.parse(tgt).unwrap().0;
6753    assert_eq!(
6754        Command::SetVoltage(SetVoltage {
6755            min: Some(0.1),
6756            object_list: Some(Object::String(ObjectString {
6757                strings: vec![String::from("a")]
6758            })),
6759            max_case_voltage: 0.1,
6760        }),
6761        ret
6762    );
6763    assert_eq!(tgt, format!("{}", ret));
6764}
6765
6766// -----------------------------------------------------------------------------
6767
6768/// A type containing information of `set_wire_load_min_block_size`
6769#[derive(Clone, Debug, Default, PartialEq)]
6770pub struct SetWireLoadMinBlockSize {
6771    pub size: f64,
6772}
6773
6774impl fmt::Display for SetWireLoadMinBlockSize {
6775    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6776        let mut args = String::from("");
6777        args.push_str(&format!(" {}", self.size));
6778        write!(f, "set_wire_load_min_block_size{}", args)
6779    }
6780}
6781
6782fn set_wire_load_min_block_size<I>() -> impl Parser<Input = I, Output = Command>
6783where
6784    I: Stream<Item = char>,
6785    I::Error: ParseError<I::Item, I::Range, I::Position>,
6786{
6787    let command = symbol("set_wire_load_min_block_size");
6788    let size = float().map(|x| CommandArg::Value(x));
6789    let args = (attempt(size),);
6790    command
6791        .with(many(choice(args)))
6792        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6793            let mut size = None;
6794            for x in xs {
6795                match x {
6796                    CommandArg::Value(x) => size = Some(x),
6797                    _ => unreachable!(),
6798                }
6799            }
6800            let size = size.ok_or(AndThenError::<I>::message_static_message(
6801                "set_wire_load_min_block_size:size",
6802            ))?;
6803            Ok(Command::SetWireLoadMinBlockSize(SetWireLoadMinBlockSize {
6804                size,
6805            }))
6806        })
6807}
6808
6809#[test]
6810fn test_set_wire_load_min_block_size() {
6811    let mut parser = command();
6812    let tgt = "set_wire_load_min_block_size 0.1";
6813    let ret = parser.parse(tgt).unwrap().0;
6814    assert_eq!(
6815        Command::SetWireLoadMinBlockSize(SetWireLoadMinBlockSize { size: 0.1 }),
6816        ret
6817    );
6818    assert_eq!(tgt, format!("{}", ret));
6819}
6820
6821// -----------------------------------------------------------------------------
6822
6823/// A type containing information of `set_wire_load_mode`
6824#[derive(Clone, Debug, Default, PartialEq)]
6825pub struct SetWireLoadMode {
6826    pub mode_name: String,
6827}
6828
6829impl fmt::Display for SetWireLoadMode {
6830    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6831        let mut args = String::from("");
6832        args.push_str(&format!(" {}", self.mode_name));
6833        write!(f, "set_wire_load_mode{}", args)
6834    }
6835}
6836
6837fn set_wire_load_mode<I>() -> impl Parser<Input = I, Output = Command>
6838where
6839    I: Stream<Item = char>,
6840    I::Error: ParseError<I::Item, I::Range, I::Position>,
6841{
6842    let command = symbol("set_wire_load_mode");
6843    let mode_name = item().map(|x| CommandArg::String(x));
6844    let args = (attempt(mode_name),);
6845    command
6846        .with(many(choice(args)))
6847        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6848            let mut mode_name = None;
6849            for x in xs {
6850                match x {
6851                    CommandArg::String(x) => mode_name = Some(x),
6852                    _ => unreachable!(),
6853                }
6854            }
6855            let mode_name = mode_name.ok_or(AndThenError::<I>::message_static_message(
6856                "set_wire_load_mode:mode_name",
6857            ))?;
6858            Ok(Command::SetWireLoadMode(SetWireLoadMode { mode_name }))
6859        })
6860}
6861
6862#[test]
6863fn test_set_wire_load_mode() {
6864    let mut parser = command();
6865    let tgt = "set_wire_load_mode a";
6866    let ret = parser.parse(tgt).unwrap().0;
6867    assert_eq!(
6868        Command::SetWireLoadMode(SetWireLoadMode {
6869            mode_name: String::from("a")
6870        }),
6871        ret
6872    );
6873    assert_eq!(tgt, format!("{}", ret));
6874}
6875
6876// -----------------------------------------------------------------------------
6877
6878/// A type containing information of `set_wire_load_model`
6879#[derive(Clone, Debug, Default, PartialEq)]
6880pub struct SetWireLoadModel {
6881    pub name: String,
6882    pub library: Option<Object>,
6883    pub min: bool,
6884    pub max: bool,
6885    pub object_list: Option<Object>,
6886}
6887
6888impl fmt::Display for SetWireLoadModel {
6889    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6890        let mut args = String::from("");
6891        args.push_str(&format!(" -name {}", self.name));
6892        if let Some(library) = &self.library {
6893            args.push_str(&format!(" -library {}", library));
6894        }
6895        if self.min {
6896            args.push_str(" -min");
6897        }
6898        if self.max {
6899            args.push_str(" -max");
6900        }
6901        if let Some(object_list) = &self.object_list {
6902            args.push_str(&format!(" {}", object_list));
6903        }
6904        write!(f, "set_wire_load_model{}", args)
6905    }
6906}
6907
6908fn set_wire_load_model<I>() -> impl Parser<Input = I, Output = Command>
6909where
6910    I: Stream<Item = char>,
6911    I::Error: ParseError<I::Item, I::Range, I::Position>,
6912{
6913    let command = symbol("set_wire_load_model");
6914    let name = symbol("-name").with(item()).map(|x| CommandArg::Name(x));
6915    let library = symbol("-library")
6916        .with(parser(object))
6917        .map(|x| CommandArg::Library(x));
6918    let min = symbol("-min").map(|_| CommandArg::Min);
6919    let max = symbol("-max").map(|_| CommandArg::Max);
6920    let object_list = parser(object).map(|x| CommandArg::Object(x));
6921    let args = (
6922        attempt(name),
6923        attempt(library),
6924        attempt(min),
6925        attempt(max),
6926        attempt(object_list),
6927    );
6928    command
6929        .with(many(choice(args)))
6930        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
6931            let mut name = None;
6932            let mut library = None;
6933            let mut min = false;
6934            let mut max = false;
6935            let mut object_list = None;
6936            for x in xs {
6937                match x {
6938                    CommandArg::Name(x) => name = Some(x),
6939                    CommandArg::Library(x) => library = Some(x),
6940                    CommandArg::Min => min = true,
6941                    CommandArg::Max => max = true,
6942                    CommandArg::Object(x) => object_list = Some(x),
6943                    _ => unreachable!(),
6944                }
6945            }
6946            let name = name.ok_or(AndThenError::<I>::message_static_message(
6947                "set_wire_load_model:name",
6948            ))?;
6949            Ok(Command::SetWireLoadModel(SetWireLoadModel {
6950                name,
6951                library,
6952                min,
6953                max,
6954                object_list,
6955            }))
6956        })
6957}
6958
6959#[test]
6960fn test_set_wire_load_model() {
6961    let mut parser = command();
6962    let tgt = "set_wire_load_model -name a -library a -min -max a";
6963    let ret = parser.parse(tgt).unwrap().0;
6964    assert_eq!(
6965        Command::SetWireLoadModel(SetWireLoadModel {
6966            name: String::from("a"),
6967            library: Some(Object::String(ObjectString {
6968                strings: vec![String::from("a")]
6969            })),
6970            min: true,
6971            max: true,
6972            object_list: Some(Object::String(ObjectString {
6973                strings: vec![String::from("a")]
6974            })),
6975        }),
6976        ret
6977    );
6978    assert_eq!(tgt, format!("{}", ret));
6979}
6980
6981// -----------------------------------------------------------------------------
6982
6983/// A type containing information of `set_wire_load_selection_group`
6984#[derive(Clone, Debug, Default, PartialEq)]
6985pub struct SetWireLoadSelectionGroup {
6986    pub library: Option<Object>,
6987    pub min: bool,
6988    pub max: bool,
6989    pub group_name: String,
6990    pub object_list: Option<Object>,
6991}
6992
6993impl fmt::Display for SetWireLoadSelectionGroup {
6994    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6995        let mut args = String::from("");
6996        if let Some(library) = &self.library {
6997            args.push_str(&format!(" -library {}", library));
6998        }
6999        if self.min {
7000            args.push_str(" -min");
7001        }
7002        if self.max {
7003            args.push_str(" -max");
7004        }
7005        args.push_str(&format!(" {}", self.group_name));
7006        if let Some(object_list) = &self.object_list {
7007            args.push_str(&format!(" {}", object_list));
7008        }
7009        write!(f, "set_wire_load_selection_group{}", args)
7010    }
7011}
7012
7013fn set_wire_load_selection_group<I>() -> impl Parser<Input = I, Output = Command>
7014where
7015    I: Stream<Item = char>,
7016    I::Error: ParseError<I::Item, I::Range, I::Position>,
7017{
7018    let command = symbol("set_wire_load_selection_group");
7019    let library = symbol("-library")
7020        .with(parser(object))
7021        .map(|x| CommandArg::Library(x));
7022    let min = symbol("-min").map(|_| CommandArg::Min);
7023    let max = symbol("-max").map(|_| CommandArg::Max);
7024    let group_name = item().map(|x| CommandArg::String(x));
7025    let object_list = parser(object).map(|x| CommandArg::Object(x));
7026    let args = (
7027        attempt(library),
7028        attempt(min),
7029        attempt(max),
7030        attempt(group_name),
7031        attempt(object_list),
7032    );
7033    command
7034        .with(many(choice(args)))
7035        .and_then::<_, _, AndThenError<I>, _>(|xs: Vec<_>| {
7036            let mut library = None;
7037            let mut min = false;
7038            let mut max = false;
7039            let mut group_name = None;
7040            let mut object_list = None;
7041            for x in xs {
7042                match x {
7043                    CommandArg::Library(x) => library = Some(x),
7044                    CommandArg::Min => min = true,
7045                    CommandArg::Max => max = true,
7046                    CommandArg::String(x) => group_name = Some(x),
7047                    CommandArg::Object(x) => object_list = Some(x),
7048                    _ => unreachable!(),
7049                }
7050            }
7051            let group_name = group_name.ok_or(AndThenError::<I>::message_static_message(
7052                "set_wire_load_selection_group:group_name",
7053            ))?;
7054            Ok(Command::SetWireLoadSelectionGroup(
7055                SetWireLoadSelectionGroup {
7056                    library,
7057                    min,
7058                    max,
7059                    group_name,
7060                    object_list,
7061                },
7062            ))
7063        })
7064}
7065
7066#[test]
7067fn test_set_wire_load_selection_group() {
7068    let mut parser = command();
7069    let tgt = "set_wire_load_selection_group -library a -min -max a [all_clocks]";
7070    let ret = parser.parse(tgt).unwrap().0;
7071    assert_eq!(
7072        Command::SetWireLoadSelectionGroup(SetWireLoadSelectionGroup {
7073            library: Some(Object::String(ObjectString {
7074                strings: vec![String::from("a")]
7075            })),
7076            min: true,
7077            max: true,
7078            group_name: String::from("a"),
7079            object_list: Some(Object::AllClocks(AllClocks {})),
7080        }),
7081        ret
7082    );
7083    assert_eq!(tgt, format!("{}", ret));
7084}
7085
7086// -----------------------------------------------------------------------------
7087
7088fn unknown<I>() -> impl Parser<Input = I, Output = Command>
7089where
7090    I: Stream<Item = char>,
7091    I::Error: ParseError<I::Item, I::Range, I::Position>,
7092{
7093    let command = many1(none_of("\n".chars())).map(|x| Command::Unknown(x));
7094    command
7095}
7096
7097// -----------------------------------------------------------------------------
7098
7099fn whitespace<I>() -> impl Parser<Input = I, Output = Command>
7100where
7101    I: Stream<Item = char>,
7102    I::Error: ParseError<I::Item, I::Range, I::Position>,
7103{
7104    let command = lex(space()).map(|_| Command::Whitespace);
7105    command
7106}