MCPcopy Create free account
hub / github.com/docopt/docopt.go / flat

Method flat

docopt.go:820–846  ·  view source on GitHub ↗
(types patternType)

Source from the content-addressed store, hash-verified

818}
819
820func (p *pattern) flat(types patternType) (patternList, error) {
821 if p.t&patternLeaf != 0 {
822 if types == patternDefault {
823 types = patternAll
824 }
825 if p.t&types != 0 {
826 return patternList{p}, nil
827 }
828 return patternList{}, nil
829 }
830
831 if p.t&patternBranch != 0 {
832 if p.t&types != 0 {
833 return patternList{p}, nil
834 }
835 result := patternList{}
836 for _, child := range p.children {
837 childFlat, err := child.flat(types)
838 if err != nil {
839 return nil, err
840 }
841 result = append(result, childFlat...)
842 }
843 return result, nil
844 }
845 return nil, newError("unknown pattern type: %d, %d", p.t, types)
846}
847
848func (p *pattern) fix() error {
849 err := p.fixIdentities(nil)

Callers 3

fixIdentitiesMethod · 0.95
parseFunction · 0.80
TestPatternFlatFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestPatternFlatFunction · 0.64