this repo has no description

filter parser updates?

+18
parser/command_parser.d.ts
··· 1 + export interface Part { 2 + type: 'text'; 3 + value: string; 4 + reconstruct: () => string; 5 + } 6 + 7 + export interface Command { 8 + type: 'add' | 'filter' | 'done'; 9 + description: string; 10 + attributes: string[]; 11 + filters: string[]; 12 + project: string; 13 + tags: string; 14 + parts: Part[]; 15 + reconstruct: () => string; 16 + } 17 + 18 + export function parse(input: string): Command;
+54
parser/filter_go.peg
··· 1 + { 2 + package parser 3 + 4 + type IdFilter struct { 5 + Ids []int 6 + } 7 + } 8 + 9 + Filter <- first:(IdRange / SingleId) rest:(',' (IdRange / SingleId))* { 10 + var ids []int 11 + first := toIntSlice(first) 12 + ids = append(ids, first...) 13 + 14 + if rest != nil { 15 + for _, r := range rest.([]interface{}) { 16 + restIds := toIntSlice(r.([]interface{})[1]) 17 + ids = append(ids, restIds...) 18 + } 19 + } 20 + 21 + return &IdFilter{Ids: ids}, nil 22 + } 23 + 24 + IdRange <- start:Integer '-' end:Integer { 25 + start := start.(int) 26 + end := end.(int) 27 + var ids []int 28 + for i := start; i <= end; i++ { 29 + ids = append(ids, i) 30 + } 31 + return ids, nil 32 + } 33 + 34 + SingleId <- id:Integer { 35 + return []int{id.(int)}, nil 36 + } 37 + 38 + Integer <- [0-9]+ { 39 + val := string(c.text) 40 + n, _ := strconv.Atoi(val) 41 + return n, nil 42 + } 43 + 44 + _ <- [ \t]* 45 + 46 + { 47 + func toIntSlice(v interface{}) []int { 48 + if slice, ok := v.([]int); ok { 49 + return slice 50 + } 51 + return nil 52 + } 53 + } 54 +
+31
parser/filter_js.peg
··· 1 + { 2 + function makeIdFilter(ids) { 3 + return { 4 + type: 'id_filter', 5 + ids: ids.flat(), 6 + reconstruct: function() { 7 + return this.ids.join(','); 8 + } 9 + }; 10 + } 11 + } 12 + 13 + Filter = first:(IdRange / SingleId) rest:("," (IdRange / SingleId))* { 14 + return makeIdFilter([first, ...rest.map(r => r[1])]); 15 + } 16 + 17 + IdRange = start:Integer "-" end:Integer { 18 + const ids = []; 19 + for (let i = start; i <= end; i++) { 20 + ids.push(i); 21 + } 22 + return ids; 23 + } 24 + 25 + SingleId = id:Integer { 26 + return [id]; 27 + } 28 + 29 + Integer = digits:[0-9]+ { 30 + return parseInt(digits.join(''), 10); 31 + }