How to use Serialize method of compiler Package

Best Syzkaller code snippet using compiler.Serialize

search_test.go

Source:search_test.go Github

copy

Full Screen

...17import "testing"18import "strings"19import "reflect"20import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"21func checkQuerySerialize(t *testing.T, query Query) {22 folder := NewRAMFolder("")23 outStream, _ := folder.OpenOut("foo")24 query.serialize(outStream)25 outStream.Close()26 inStream, _ := folder.OpenIn("foo")27 dupe := clownfish.GetClass(query).MakeObj().(Query).deserialize(inStream)28 if !query.Equals(dupe) {29 t.Errorf("Unsuccessful serialization round trip -- expected '%v', got '%v'",30 query.ToString(), dupe.ToString())31 }32}33func checkQueryDumpLoad(t *testing.T, query Query) {34 dupe := clownfish.GetClass(query).MakeObj().(Query)35 dupe = dupe.Load(query.Dump()).(Query)36 if !query.Equals(dupe) {37 t.Errorf("Unsuccessful Dump/Load round trip -- expected '%v', got '%v'",38 query.ToString(), dupe.ToString())39 }40}41func checkQueryEquals(t *testing.T, query Query) {42 if !query.Equals(query) {43 t.Error("Equals self")44 }45 if query.Equals("blah") {46 t.Error("Equals against Go string")47 }48}49func checkQueryMakeCompiler(t *testing.T, query Query) {50 index := createTestIndex("foo", "bar", "baz")51 searcher, _ := OpenIndexSearcher(index)52 compiler, err := query.MakeCompiler(searcher, 1.0, false)53 if _, ok := compiler.(Compiler); !ok || err != nil {54 t.Error("MakeCompiler for %v failed: %v", query, err)55 }56}57// Test whether ToString() yields a string which contains "foo".58func checkQueryToStringHasFoo(t *testing.T, query Query) {59 if got := query.ToString(); !strings.Contains(got, "foo") {60 t.Errorf("Unexpected stringification: '%v'", got)61 }62}63func TestTermQueryMisc(t *testing.T) {64 query := NewTermQuery("content", "foo")65 checkQuerySerialize(t, query)66 checkQueryDumpLoad(t, query)67 checkQueryEquals(t, query)68 checkQueryMakeCompiler(t, query)69 checkQueryToStringHasFoo(t, query)70}71func TestTermQueryAccessors(t *testing.T) {72 query := NewTermQuery("content", "foo")73 if got := query.GetField(); got != "content" {74 t.Errorf("Expected 'content', got '%v'", got)75 }76 if got := query.GetTerm().(string); got != "foo" {77 t.Errorf("Expected 'foo', got '%v'", got)78 }79}80func TestTermCompilerMisc(t *testing.T) {81 folder := createTestIndex("foo", "bar", "baz")82 searcher, _ := OpenIndexSearcher(folder)83 query := NewTermQuery("content", "foo")84 compiler := NewTermCompiler(query, searcher, 1.0)85 checkQuerySerialize(t, compiler) 86 checkQueryEquals(t, compiler)87 checkQueryToStringHasFoo(t, compiler)88 segReaders := searcher.GetReader().SegReaders()89 matcher, err := compiler.MakeMatcher(segReaders[0].(SegReader), false)90 if matcher == nil || err != nil {91 t.Errorf("MakeMatcher: %v", err)92 }93}94func TestTermCompilerWeighting(t *testing.T) {95 index := createTestIndex("foo", "bar", "baz")96 searcher, _ := OpenIndexSearcher(index)97 query := NewTermQuery("content", "foo")98 compiler := NewTermCompiler(query, searcher, 1.0)99 _ = compiler.SumOfSquaredWeights()100 _ = compiler.GetWeight()101 compiler.ApplyNormFactor(10.0)102}103func TestPhraseQueryMisc(t *testing.T) {104 terms := []interface{}{"foo", "bar"}105 query := NewPhraseQuery("content", terms)106 checkQuerySerialize(t, query)107 checkQueryDumpLoad(t, query)108 checkQueryEquals(t, query)109 checkQueryMakeCompiler(t, query)110 checkQueryToStringHasFoo(t, query)111}112func TestPhraseQueryAccessors(t *testing.T) {113 terms := []interface{}{"foo", "bar"}114 query := NewPhraseQuery("content", terms)115 if field := query.GetField(); field != "content" {116 t.Errorf("Expected 'content', got '%v'", field)117 }118 if got := query.GetTerms(); !reflect.DeepEqual(terms, got) {119 t.Errorf("Expected '%v', got '%v'", terms, got)120 }121}122func TestPhraseCompilerMisc(t *testing.T) {123 folder := createTestIndex("foo", "bar", "baz")124 searcher, _ := OpenIndexSearcher(folder)125 terms := []interface{}{"foo", "bar"}126 query := NewPhraseQuery("content", terms)127 compiler := NewPhraseCompiler(query, searcher, 1.0)128 checkQuerySerialize(t, compiler) 129 checkQueryEquals(t, compiler)130 checkQueryToStringHasFoo(t, compiler)131}132func TestPhraseCompilerWeighting(t *testing.T) {133 index := createTestIndex("foo", "bar", "baz")134 searcher, _ := OpenIndexSearcher(index)135 terms := []interface{}{"foo", "bar"}136 query := NewPhraseQuery("content", terms)137 compiler := NewPhraseCompiler(query, searcher, 1.0)138 _ = compiler.SumOfSquaredWeights()139 _ = compiler.GetWeight()140 compiler.ApplyNormFactor(10.0)141}142func TestANDQueryBasics(t *testing.T) {143 children := []Query{144 NewTermQuery("content", "foo"),145 NewTermQuery("content", "bar"),146 }147 query := NewANDQuery(children)148 checkQuerySerialize(t, query)149 checkQueryDumpLoad(t, query)150 checkQueryEquals(t, query)151 checkQueryMakeCompiler(t, query)152 checkQueryToStringHasFoo(t, query)153}154func TestORQueryBasics(t *testing.T) {155 children := []Query{156 NewTermQuery("content", "foo"),157 NewTermQuery("content", "bar"),158 }159 query := NewORQuery(children)160 checkQuerySerialize(t, query)161 checkQueryDumpLoad(t, query)162 checkQueryEquals(t, query)163 checkQueryMakeCompiler(t, query)164 checkQueryToStringHasFoo(t, query)165}166func TestReqOptQueryBasics(t *testing.T) {167 req := NewTermQuery("content", "foo")168 opt := NewTermQuery("content", "bar")169 query := NewRequiredOptionalQuery(req, opt)170 checkQuerySerialize(t, query)171 checkQueryDumpLoad(t, query)172 checkQueryEquals(t, query)173 checkQueryMakeCompiler(t, query)174 checkQueryToStringHasFoo(t, query)175}176func TestReqOptQueryAccessors(t *testing.T) {177 req := NewTermQuery("content", "foo")178 opt := NewTermQuery("content", "bar")179 query := NewRequiredOptionalQuery(req, opt)180 if query.GetRequiredQuery().TOPTR() != req.TOPTR() {181 t.Errorf("GetRequiredQuery")182 }183 if query.GetOptionalQuery().TOPTR() != opt.TOPTR() {184 t.Errorf("GetOptionalQuery")185 }186}187func TestNOTQueryBasics(t *testing.T) {188 negated := NewTermQuery("content", "foo")189 query := NewNOTQuery(negated)190 checkQuerySerialize(t, query)191 checkQueryDumpLoad(t, query)192 checkQueryEquals(t, query)193 checkQueryMakeCompiler(t, query)194 checkQueryToStringHasFoo(t, query)195}196func TestNOTQueryAccessors(t *testing.T) {197 negated := NewTermQuery("content", "foo")198 query := NewNOTQuery(negated)199 if query.GetNegatedQuery().TOPTR() != negated.TOPTR() {200 t.Errorf("GetNegatedQuery")201 }202}203func TestMatchAllQueryBasics(t *testing.T) {204 query := NewMatchAllQuery()205 checkQuerySerialize(t, query)206 checkQueryDumpLoad(t, query)207 checkQueryEquals(t, query)208 checkQueryMakeCompiler(t, query)209}210func TestNOMatchQueryBasics(t *testing.T) {211 query := NewNoMatchQuery()212 checkQuerySerialize(t, query)213 checkQueryDumpLoad(t, query)214 checkQueryEquals(t, query)215 checkQueryMakeCompiler(t, query)216}217func TestRangeQueryBasics(t *testing.T) {218 query := NewRangeQuery("content", "fab", "foo", true, true)219 checkQuerySerialize(t, query)220 checkQueryDumpLoad(t, query)221 checkQueryEquals(t, query)222 checkQueryMakeCompiler(t, query)223 checkQueryToStringHasFoo(t, query)224}225func TestLeafQueryBasics(t *testing.T) {226 query := NewLeafQuery("content", "foo")227 checkQuerySerialize(t, query)228 checkQueryDumpLoad(t, query)229 checkQueryEquals(t, query)230 checkQueryToStringHasFoo(t, query)231}232func checkMatcher(t *testing.T, matcher Matcher, supportsScore bool) {233 if got := matcher.Next(); got != 42 {234 t.Error("Next: %d", got)235 }236 if got := matcher.GetDocID(); got != 42 {237 t.Error("GetDocID: %d", got)238 }239 if supportsScore {240 if score := matcher.Score(); score != 2 {241 t.Error("Score: %f", score)...

Full Screen

Full Screen

serializer.go

Source:serializer.go Github

copy

Full Screen

...8 "github.com/marianogappa/predictions/core"9 "github.com/marianogappa/predictions/printer"10 "github.com/rs/zerolog/log"11)12// PredictionSerializer is the component that serializes a Prediction to a string representation, to be persisted or13// returned in an API call.14type PredictionSerializer struct {15 mkt *core.IMarket16}17// NewPredictionSerializer constructs a PredictionSerializer.18func NewPredictionSerializer(market *core.IMarket) PredictionSerializer {19 return PredictionSerializer{mkt: market}20}21// PreSerialize serializes a Prediction to a compiler.Prediction, but doesn't take the extra step of serializing it to a22// JSON []byte.23func (s PredictionSerializer) PreSerialize(p *core.Prediction) (compiler.Prediction, error) {24 pp, err := marshalPrePredict(p.PrePredict)25 if err != nil {26 return compiler.Prediction{}, err27 }28 pd, err := marshalPredict(p.Predict)29 if err != nil {30 return compiler.Prediction{}, err31 }32 return compiler.Prediction{33 UUID: p.UUID,34 Version: p.Version,35 CreatedAt: p.CreatedAt,36 Reporter: p.Reporter,37 PostAuthor: p.PostAuthor,38 PostAuthorURL: p.PostAuthorURL,39 PostedAt: p.PostedAt,40 PostURL: p.PostURL,41 Given: marshalGiven(p.Given),42 PrePredict: pp,43 Predict: pd,44 PredictionState: marshalPredictionState(p.State),45 Type: p.Type.String(),46 Paused: p.Paused,47 Hidden: p.Hidden,48 Deleted: p.Deleted,49 }, nil50}51// PreSerializeForDB serializes a Prediction to a compiler.Prediction, but doesn't take the extra step of serializing it52// to a JSON []byte.53func (s PredictionSerializer) PreSerializeForDB(p *core.Prediction) (compiler.Prediction, error) {54 pp, err := marshalPrePredict(p.PrePredict)55 if err != nil {56 return compiler.Prediction{}, err57 }58 pd, err := marshalPredict(p.Predict)59 if err != nil {60 return compiler.Prediction{}, err61 }62 return compiler.Prediction{63 UUID: p.UUID,64 Version: p.Version,65 CreatedAt: p.CreatedAt,66 Reporter: p.Reporter,67 PostAuthor: p.PostAuthor,68 PostAuthorURL: p.PostAuthorURL,69 PostedAt: p.PostedAt,70 PostURL: p.PostURL,71 Given: marshalGiven(p.Given),72 PrePredict: pp,73 Predict: pd,74 PredictionState: marshalPredictionState(p.State),75 Type: p.Type.String(),76 }, nil77}78// Serialize serializes a Prediction to a JSON []byte. It is meant to be used for persisting, but must not be used79// by the API. There's a separate PreSerializeForAPI method for that purpose.80func (s PredictionSerializer) Serialize(p *core.Prediction) ([]byte, error) {81 pre, err := s.PreSerialize(p)82 if err != nil {83 return nil, err84 }85 return json.Marshal(pre)86}87// SerializeForDB serializes a Prediction to a JSON []byte. It is meant to be used for persisting, but must only be used88// by the DB.89func (s PredictionSerializer) SerializeForDB(p *core.Prediction) ([]byte, error) {90 pre, err := s.PreSerializeForDB(p)91 if err != nil {92 return nil, err93 }94 return json.Marshal(pre)95}96// PreSerializeForAPI serializes a Prediction to a compiler.Prediction, but doesn't take the extra step of serializing97// it to a JSON []byte. It is meant to be used only by the API.98func (s PredictionSerializer) PreSerializeForAPI(p *core.Prediction, includeSummary bool) (compiler.Prediction, error) {99 pred := compiler.Prediction{100 UUID: p.UUID,101 Version: p.Version,102 CreatedAt: p.CreatedAt,103 Reporter: p.Reporter,104 PostAuthor: p.PostAuthor,105 PostAuthorURL: p.PostAuthorURL,106 PostedAt: p.PostedAt,107 PostURL: p.PostURL,108 PredictionState: marshalPredictionState(p.State),109 Type: p.Type.String(),110 PredictionText: printer.NewPredictionPrettyPrinter(*p).String(),111 Summary: compiler.PredictionSummary{},112 Paused: p.Paused,113 Hidden: p.Hidden,114 Deleted: p.Deleted,115 }116 if includeSummary && s.mkt != nil {117 var err error118 pred.Summary, err = s.BuildPredictionMarketSummary(*p)119 if err != nil {120 log.Error().Err(err).Msg("compiler.PreSerializeForAPI: writing summary failed")121 return pred, err122 }123 }124 return pred, nil125}126// SerializeForAPI serializes a Prediction to a JSON []byte. It is meant to be used only by the API.127func (s PredictionSerializer) SerializeForAPI(p *core.Prediction, includeSummary bool) ([]byte, error) {128 pred, err := s.PreSerializeForAPI(p, includeSummary)129 if err != nil {130 return nil, err131 }132 return json.Marshal(pred)133}134func marshalInnerCondition(c *core.Condition) string {135 if c.Operator == "BETWEEN" {136 return fmt.Sprintf(`%v BETWEEN %v AND %v`, c.Operands[0].Str, c.Operands[1].Str, c.Operands[2].Str)137 }138 return fmt.Sprintf(`%v %v %v`, c.Operands[0].Str, c.Operator, c.Operands[1].Str)139}140func marshalGiven(given map[string]*core.Condition) map[string]compiler.Condition {141 result := map[string]compiler.Condition{}142 for key, cond := range given {143 c := compiler.Condition{144 Condition: marshalInnerCondition(cond),145 FromISO8601: core.ISO8601(time.Unix(int64(cond.FromTs), 0).Format(time.RFC3339)),146 ToISO8601: core.ISO8601(time.Unix(int64(cond.ToTs), 0).Format(time.RFC3339)),147 ToDuration: cond.ToDuration,148 Assumed: cond.Assumed,149 ErrorMarginRatio: cond.ErrorMarginRatio,150 State: compiler.ConditionState{151 Status: cond.State.Status.String(),152 LastTs: cond.State.LastTs,153 LastTicks: cond.State.LastTicks,154 Value: cond.State.Value.String(),155 },156 }157 result[key] = c158 }159 return result160}161func marshalBoolExpr(b *core.BoolExpr, nestLevel int) (*string, error) {162 if b == nil {163 return nil, nil164 }165 var prefix, suffix string166 if nestLevel > 0 {167 prefix = "("168 suffix = ")"169 }170 switch b.Operator {171 case core.LITERAL:172 return &b.Literal.Name, nil173 case core.AND, core.OR:174 operator := " and "175 if b.Operator == core.OR {176 operator = " or "177 }178 operands := []string{}179 for _, operand := range b.Operands {180 s, err := marshalBoolExpr(operand, nestLevel+1)181 if err != nil {182 return nil, err183 }184 if s == nil {185 continue186 }187 operands = append(operands, *s)188 }189 s := fmt.Sprintf("%v%v%v", prefix, strings.Join(operands, operator), suffix)190 return &s, nil191 case core.NOT:192 operand, err := marshalBoolExpr(b.Operands[0], nestLevel+1)193 if err != nil {194 return nil, err195 }196 s := fmt.Sprintf("%vnot %v%v", prefix, *operand, suffix)197 return &s, nil198 }199 return nil, fmt.Errorf("marshalBoolExpr: unknown operator '%v'", b.Operator)200}201func marshalPrePredict(pp core.PrePredict) (*compiler.PrePredict, error) {202 wrongIf, err := marshalBoolExpr(pp.WrongIf, 0)203 if err != nil {204 return nil, err205 }206 annulledIf, err := marshalBoolExpr(pp.AnnulledIf, 0)207 if err != nil {208 return nil, err209 }210 predictIf, err := marshalBoolExpr(pp.Predict, 0)211 if err != nil {212 return nil, err213 }214 result := &compiler.PrePredict{215 WrongIf: wrongIf,216 AnnulledIf: annulledIf,217 Predict: predictIf,218 AnnulledIfPredictIsFalse: pp.AnnulledIfPredictIsFalse,219 IgnoreUndecidedIfPredictIsDefined: pp.IgnoreUndecidedIfPredictIsDefined,220 }221 return result, nil222}223func marshalPredict(p core.Predict) (compiler.Predict, error) {224 wrongIf, err := marshalBoolExpr(p.WrongIf, 0)225 if err != nil {226 return compiler.Predict{}, err227 }228 annulledIf, err := marshalBoolExpr(p.AnnulledIf, 0)229 if err != nil {230 return compiler.Predict{}, err231 }232 predictIf, err := marshalBoolExpr(&p.Predict, 0)233 if err != nil {234 return compiler.Predict{}, err235 }236 result := compiler.Predict{237 WrongIf: wrongIf,238 AnnulledIf: annulledIf,239 Predict: *predictIf,240 IgnoreUndecidedIfPredictIsDefined: p.IgnoreUndecidedIfPredictIsDefined,241 }242 return result, nil243}244func marshalPredictionState(ps core.PredictionState) compiler.PredictionState {245 return compiler.PredictionState{246 Status: ps.Status.String(),247 LastTs: ps.LastTs,248 Value: ps.Value.String(),249 }250}251// AccountSerializer is the component that serializes an Account to a string representation, to be persisted or returned252// in an API call.253type AccountSerializer struct{}254// NewAccountSerializer constructs an AccountSerializer.255func NewAccountSerializer() AccountSerializer {256 return AccountSerializer{}257}258// Account is the struct that represents a post author's social media account.259type Account struct {260 URL string `json:"url"`261 AccountType string `json:"accountType"`262 Handle string `json:"handle"`263 FollowerCount int `json:"followerCount"`264 Thumbnails []string `json:"thumbnails"`265 Name string `json:"name"`266 Description string `json:"description"`267 CreatedAt string `json:"createdAt,omitempty"`268}269// PreSerialize serializes an Account to a compiler.Account, but doesn't take the extra step of serializing it to a270// JSON []byte.271func (s AccountSerializer) PreSerialize(p *core.Account) (Account, error) {272 thumbs := []string{}273 for _, thumb := range p.Thumbnails {274 thumbs = append(thumbs, thumb.String())275 }276 createdAt := ""277 if p.CreatedAt != nil {278 createdAt = p.CreatedAt.Format(time.RFC3339)279 }280 return Account{281 URL: p.URL.String(),282 AccountType: p.AccountType,283 Handle: p.Handle,284 FollowerCount: p.FollowerCount,285 Thumbnails: thumbs,286 Name: p.Name,287 Description: p.Description,288 CreatedAt: createdAt,289 }, nil290}291// Serialize serializes an Account to a JSON []byte.292func (s AccountSerializer) Serialize(p *core.Account) ([]byte, error) {293 acc, err := s.PreSerialize(p)294 if err != nil {295 return nil, err296 }297 return json.Marshal(acc)298}...

Full Screen

Full Screen

compile.go

Source:compile.go Github

copy

Full Screen

1package lex2import (3 "fmt"4 "log"5 "strings"6 "github.com/inspirer/textmapper/tm-go/status"7 "github.com/inspirer/textmapper/tm-go/util/container"8)9type Pattern struct {10 Name string11 RE *Regexp12 Text string // of RE13 Origin status.SourceNode14}15type inst struct {16 consume symlist // An empty list means we cannot advance to the next instruction.17 links []int // Relative offsets of other instructions that should be considered at the same time.18 rule *Rule // The rule to be accepted.19 trace trace // core() instructions only: the trace of this instruction20}21func (i inst) core() bool {22 return i.rule != nil || len(i.consume) != 023}24func (i inst) String() string {25 var sb strings.Builder26 i.trace.toString(&sb)27 return sb.String()28}29type trace struct {30 pattern *Pattern // The pattern that produced a given instruction.31 offset int // The corresponding offset in pattern.Text.32 caller *trace // The last pattern in this chain is a Rule.33}34func (t *trace) toString(sb *strings.Builder) {35 if t.caller != nil {36 t.caller.toString(sb)37 sb.WriteString(" -> ")38 } else {39 sb.WriteString(t.pattern.Name)40 sb.WriteString(": ")41 }42 fmt.Fprintf(sb, "/%v<STATE>%v/", t.pattern.Text[:t.offset], t.pattern.Text[t.offset:])43}44// reCompiler translates a set of regular expressions into a single list of instructions.45type reCompiler struct {46 sets []charset47 out []inst48 consume []int49 runes map[rune]int // index in sets50 inExternal map[string]bool51 err error52}53func newCompiler() *reCompiler {54 return &reCompiler{55 runes: make(map[rune]int),56 inExternal: make(map[string]bool),57 }58}59func (c *reCompiler) addPattern(p *Pattern, action int, rule *Rule) (int, error) {60 c.err = nil61 ret := c.next()62 t := trace{pattern: p}63 c.serialize(p.RE, rule.Resolver, t)64 t.offset = len(t.pattern.Text)65 accept := c.emit(nil, t)66 c.out[accept].rule = rule67 transitiveClosure(c.out[ret:])68 for _, delta := range c.out[ret].links {69 dst := ret + delta70 if c.out[dst].rule != nil {71 c.errorf("`%v` accepts empty text", p.Name)72 break73 }74 }75 return ret, c.err76}77func (c *reCompiler) compile() (ins []inst, inputMap []RangeEntry) {78 symlists, inputMap := compressCharsets(c.sets)79 for i, id := range c.consume {80 if id >= 0 {81 c.out[i].consume = symlists[id]82 }83 }84 for src := range c.out {85 nlinks := c.out[src].links[:0]86 for _, delta := range c.out[src].links {87 if c.out[src+delta].core() {88 nlinks = append(nlinks, delta)89 }90 }91 c.out[src].links = nlinks92 }93 return c.out, inputMap94}95func (c *reCompiler) serialize(re *Regexp, resolver Resolver, t trace) {96 if c.err != nil {97 return98 }99 switch re.op {100 case opLiteral:101 for i, r := range re.text {102 t.offset = re.offset + i103 c.emit(charset{r, r}, t)104 }105 case opCharClass:106 t.offset = re.offset107 c.emit(re.charset, t)108 case opExternal:109 t.offset = re.offset110 if re.text == "eoi" {111 eoi := c.emit(nil, t)112 c.out[eoi].consume = symlist{EOI}113 return114 }115 if _, ok := c.inExternal[re.text]; ok {116 c.errorf("named patterns cannot recursively depend on each other (in %s)", re.text)117 return118 }119 pattern := resolver.Resolve(re.text)120 if pattern == nil {121 c.errorf("cannot find named pattern: %s", re.text)122 return123 }124 c.inExternal[re.text] = true125 child := trace{pattern: pattern, caller: &t}126 c.serialize(pattern.RE, resolver, child)127 delete(c.inExternal, re.text)128 case opRepeat:129 if re.min > 16 || re.max > 16 {130 c.errorf("cannot expand the regexp, too many entities to repeat (max. 16)")131 return132 }133 barrier := c.emit(nil, trace{})134 c.link(barrier, c.next())135 var last int136 for i := 0; i < re.min; i++ {137 last = c.next()138 c.serialize(re.sub[0], resolver, t)139 }140 if re.max == -1 {141 if re.min == 0 {142 last = c.next()143 c.serialize(re.sub[0], resolver, t)144 }145 barrier := c.emit(nil, trace{})146 c.link(barrier, last)147 c.link(barrier, c.next())148 if re.min == 0 {149 c.link(last, c.next())150 }151 } else if re.max > re.min {152 var subs []int153 for i := re.max - re.min; i > 0; i-- {154 subs = append(subs, c.next())155 c.serialize(re.sub[0], resolver, t)156 }157 barrier := c.emit(nil, trace{})158 for _, sub := range subs {159 c.link(sub, c.next())160 }161 c.link(barrier, c.next())162 }163 case opAlternate:164 alt := c.emit(nil, trace{})165 var ends []int166 for _, s := range re.sub {167 c.link(alt, c.next())168 c.serialize(s, resolver, t)169 ends = append(ends, c.emit(nil, trace{}))170 }171 for _, end := range ends {172 c.link(end, c.next())173 }174 case opConcat:175 for _, s := range re.sub {176 c.serialize(s, resolver, t)177 }178 default:179 log.Fatal("unknown regexp operation")180 }181}182func (c *reCompiler) errorf(format string, a ...interface{}) {183 if c.err == nil {184 c.err = fmt.Errorf(format, a...)185 }186}187func (c *reCompiler) next() int {188 return len(c.out)189}190func (c *reCompiler) link(src, dst int) {191 c.out[src].links = append(c.out[src].links, dst-src)192}193func (c *reCompiler) emit(cs charset, t trace) int {194 c.out = append(c.out, inst{trace: t})195 id := -1196 if len(cs) != 0 {197 if len(cs) == 2 && cs[0] == cs[1] {198 r := cs[0]199 var ok bool200 id, ok = c.runes[r]201 if !ok {202 id = len(c.sets)203 c.sets = append(c.sets, []rune{r, r})204 c.runes[r] = id205 }206 } else {207 id = len(c.sets)208 c.sets = append(c.sets, cs)209 }210 }211 c.consume = append(c.consume, id)212 return len(c.out) - 1213}214func transitiveClosure(code []inst) {215 seen := container.NewBitSet(len(code))216 var visit func(int, int)217 visit = func(origin, src int) {218 for _, delta := range code[src].links {219 dst := src + delta220 if !seen.Get(dst) {221 code[origin].links = append(code[origin].links, dst-origin)222 seen.Set(dst)223 visit(origin, dst)224 }225 }226 }227 for src, ins := range code {228 if len(ins.links) == 0 {229 continue230 }231 seen.ClearAll(len(code))232 seen.Set(src)233 for _, delta := range ins.links {234 seen.Set(src + delta)235 }236 for _, delta := range ins.links {237 visit(src, src+delta)238 }239 }240}...

Full Screen

Full Screen

Serialize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 req := new(plugin.CodeGeneratorRequest)5 req.FileToGenerate = append(req.FileToGenerate, "2.proto")6 fileDescriptorProto := new(descriptor.FileDescriptorProto)7 fileDescriptorProto.Name = proto.String("2.proto")8 req.ProtoFile = append(req.ProtoFile, fileDescriptorProto)9 data, err := proto.Marshal(req)10 if err != nil {11 fmt.Println("error in serializing the request object")12 }13 fmt.Println(data)14}

Full Screen

Full Screen

Serialize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := otto.New()4 vm.Run(`5 function add(a, b) {6 return a + b;7 }8 serialized, err := vm.Compile("add", "add(1, 2)")9 if err != nil {

Full Screen

Full Screen

Serialize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 compiler := otto.New()4 compiler.Run(`5 function add(a, b) {6 return a + b;7 }8 serialized, err := compiler.Compile("add(40, 2)")9 if err != nil {10 panic(err)11 }12 fmt.Println(serialized)13}14import (15func main() {16 compiler := otto.New()17 compiler.Run(`18 function add(a, b) {19 return a + b;20 }21 value, err := compiler.Run("add(40, 2)")22 if err != nil {23 panic(err)24 }25 fmt.Println(value)26}27import (28func main() {29 compiler := otto.New()30 compiler.Run(`31 function add(a, b) {32 return a + b;33 }34 value, err := compiler.Run("add(40, 2)")35 if err != nil {36 panic(err)37 }38 fmt.Println(value)39}40import (41func main() {42 compiler := otto.New()43 compiler.Run(`44 function add(a, b) {45 return a + b;46 }47 value, err := compiler.Run("add(40, 2)")48 if err != nil {49 panic(err)50 }51 fmt.Println(value)52}53import (54func main() {55 compiler := otto.New()56 compiler.Run(`57 function add(a, b) {58 return a + b;59 }

Full Screen

Full Screen

Serialize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var code = []byte{0x60, 0x10, 0x60, 0x0f, 0x01}4 var compiler = vm.NewEVMCompiler()5 var bytecode, err = compiler.Compile(code)6 if err != nil {7 fmt.Println(err)8 } else {9 fmt.Printf("%x", bytecode)10 }11}

Full Screen

Full Screen

Serialize

Using AI Code Generation

copy

Full Screen

1compiler.Serialize("2.exe");2compiler.Deserialize("2.exe");3compiler.Execute();4compiler.Execute();5compiler.Execute();6compiler.Execute();7compiler.Execute();8compiler.Execute();9compiler.Execute();10compiler.Execute();11compiler.Execute();12compiler.Execute();13compiler.Execute();14compiler.Execute();15compiler.Execute();16compiler.Execute();17compiler.Execute();18compiler.Execute();19compiler.Execute();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful