How to use TryConsume method of kconfig Package

Best Syzkaller code snippet using kconfig.TryConsume

kconfig.go

Source:kconfig.go Github

copy

Full Screen

...144}145func (kp *kconfigParser) parseFile() {146 for kp.nextLine() {147 kp.parseLine()148 if kp.TryConsume("#") {149 _ = kp.ConsumeLine()150 }151 }152 kp.endCurrent()153}154func (kp *kconfigParser) parseLine() {155 if kp.eol() {156 return157 }158 if kp.helpIdent != 0 {159 if kp.identLevel() >= kp.helpIdent {160 _ = kp.ConsumeLine()161 return162 }163 kp.helpIdent = 0164 }165 if kp.TryConsume("#") {166 _ = kp.ConsumeLine()167 return168 }169 if kp.TryConsume("$") {170 _ = kp.Shell()171 return172 }173 ident := kp.Ident()174 if kp.TryConsume("=") || kp.TryConsume(":=") {175 // Macro definition, see:176 // https://www.kernel.org/doc/html/latest/kbuild/kconfig-macro-language.html177 // We don't use this for anything now.178 kp.ConsumeLine()179 return180 }181 kp.parseMenu(ident)182}183func (kp *kconfigParser) parseMenu(cmd string) {184 switch cmd {185 case "source":186 file, ok := kp.TryQuotedString()187 if !ok {188 file = kp.ConsumeLine()189 }190 kp.includeSource(file)191 case "mainmenu":192 kp.pushCurrent(&Menu{193 Kind: MenuConfig,194 prompts: []prompt{{text: kp.QuotedString()}},195 })196 case "comment":197 kp.newCurrent(&Menu{198 Kind: MenuComment,199 prompts: []prompt{{text: kp.QuotedString()}},200 })201 case "menu":202 kp.pushCurrent(&Menu{203 Kind: MenuGroup,204 prompts: []prompt{{text: kp.QuotedString()}},205 })206 case "if":207 kp.pushCurrent(&Menu{208 Kind: MenuGroup,209 visibleIf: kp.parseExpr(),210 })211 case "choice":212 kp.pushCurrent(&Menu{213 Kind: MenuChoice,214 })215 case "endmenu", "endif", "endchoice":216 kp.popCurrent()217 case "config", "menuconfig":218 kp.newCurrent(&Menu{219 Kind: MenuConfig,220 Name: kp.Ident(),221 })222 default:223 kp.parseConfigType(cmd)224 }225}226func (kp *kconfigParser) parseConfigType(typ string) {227 cur := kp.current()228 switch typ {229 case "tristate":230 cur.Type = TypeTristate231 kp.tryParsePrompt()232 case "def_tristate":233 cur.Type = TypeTristate234 kp.parseDefaultValue()235 case "bool":236 cur.Type = TypeBool237 kp.tryParsePrompt()238 case "def_bool":239 cur.Type = TypeBool240 kp.parseDefaultValue()241 case "int":242 cur.Type = TypeInt243 kp.tryParsePrompt()244 case "def_int":245 cur.Type = TypeInt246 kp.parseDefaultValue()247 case "hex":248 cur.Type = TypeHex249 kp.tryParsePrompt()250 case "def_hex":251 cur.Type = TypeHex252 kp.parseDefaultValue()253 case "string":254 cur.Type = TypeString255 kp.tryParsePrompt()256 case "def_string":257 cur.Type = TypeString258 kp.parseDefaultValue()259 default:260 kp.parseProperty(typ)261 }262}263func (kp *kconfigParser) parseProperty(prop string) {264 cur := kp.current()265 switch prop {266 case "prompt":267 kp.tryParsePrompt()268 case "depends":269 kp.MustConsume("on")270 cur.dependsOn = exprAnd(cur.dependsOn, kp.parseExpr())271 case "visible":272 kp.MustConsume("if")273 cur.visibleIf = exprAnd(cur.visibleIf, kp.parseExpr())274 case "select", "imply":275 _ = kp.Ident()276 if kp.TryConsume("if") {277 _ = kp.parseExpr()278 }279 case "option":280 // It can be 'option foo', or 'option bar="BAZ"'.281 kp.ConsumeLine()282 case "modules":283 case "optional":284 case "default":285 kp.parseDefaultValue()286 case "range":287 _, _ = kp.parseExpr(), kp.parseExpr() // from, to288 if kp.TryConsume("if") {289 _ = kp.parseExpr()290 }291 case "help", "---help---":292 // Help rules are tricky: end of help is identified by smaller indentation level293 // as would be rendered on a terminal with 8-column tabs setup, minus empty lines.294 for kp.nextLine() {295 if kp.eol() {296 continue297 }298 kp.helpIdent = kp.identLevel()299 kp.ConsumeLine()300 break301 }302 default:303 kp.failf("unknown line")304 }305}306func (kp *kconfigParser) includeSource(file string) {307 kp.newCurrent(nil)308 file = kp.expandString(file)309 file = filepath.Join(kp.baseDir, file)310 data, err := ioutil.ReadFile(file)311 if err != nil {312 kp.failf("%v", err)313 return314 }315 kp.includes = append(kp.includes, kp.parser)316 kp.parser = newParser(data, file)317 kp.parseFile()318 err = kp.err319 kp.parser = kp.includes[len(kp.includes)-1]320 kp.includes = kp.includes[:len(kp.includes)-1]321 if kp.err == nil {322 kp.err = err323 }324}325func (kp *kconfigParser) pushCurrent(m *Menu) {326 kp.endCurrent()327 kp.cur = m328 kp.stack = append(kp.stack, m)329}330func (kp *kconfigParser) popCurrent() {331 kp.endCurrent()332 if len(kp.stack) < 2 {333 kp.failf("unbalanced endmenu")334 return335 }336 last := kp.stack[len(kp.stack)-1]337 kp.stack = kp.stack[:len(kp.stack)-1]338 top := kp.stack[len(kp.stack)-1]339 last.Parent = top340 top.Elems = append(top.Elems, last)341}342func (kp *kconfigParser) newCurrent(m *Menu) {343 kp.endCurrent()344 kp.cur = m345}346func (kp *kconfigParser) current() *Menu {347 if kp.cur == nil {348 kp.failf("config property outside of config")349 return &Menu{}350 }351 return kp.cur352}353func (kp *kconfigParser) endCurrent() {354 if kp.cur == nil {355 return356 }357 if len(kp.stack) == 0 {358 kp.failf("unbalanced endmenu")359 return360 }361 top := kp.stack[len(kp.stack)-1]362 if top != kp.cur {363 kp.cur.Parent = top364 top.Elems = append(top.Elems, kp.cur)365 }366 kp.cur = nil367}368func (kp *kconfigParser) tryParsePrompt() {369 if str, ok := kp.TryQuotedString(); ok {370 prompt := prompt{371 text: str,372 }373 if kp.TryConsume("if") {374 prompt.cond = kp.parseExpr()375 }376 kp.current().prompts = append(kp.current().prompts, prompt)377 }378}379func (kp *kconfigParser) parseDefaultValue() {380 def := defaultVal{val: kp.parseExpr()}381 if kp.TryConsume("if") {382 def.cond = kp.parseExpr()383 }384 kp.current().defaults = append(kp.current().defaults, def)385}386func (kp *kconfigParser) expandString(str string) string {387 str = strings.Replace(str, "$(SRCARCH)", kp.target.KernelHeaderArch, -1)388 str = strings.Replace(str, "$SRCARCH", kp.target.KernelHeaderArch, -1)389 return str390}...

Full Screen

Full Screen

expr.go

Source:expr.go Github

copy

Full Screen

...110// This is somewhat strange semantics and here it is implemented as simply being left-associative.111// For now it does not matter since we do not evaluate expressions.112func (p *parser) parseExpr() expr {113 ex := p.parseExprAnd()114 for p.TryConsume("||") {115 ex = &exprBin{116 op: opOr,117 lex: ex,118 rex: p.parseExprAnd(),119 }120 }121 return ex122}123func (p *parser) parseExprAnd() expr {124 ex := p.parseExprCmp()125 for p.TryConsume("&&") {126 ex = &exprBin{127 op: opAnd,128 lex: ex,129 rex: p.parseExprCmp(),130 }131 }132 return ex133}134func (p *parser) parseExprCmp() expr {135 ex := p.parseExprTerm()136 for {137 op := opNop138 switch {139 case p.TryConsume("="):140 op = opEq141 case p.TryConsume("!="):142 op = opNe143 case p.TryConsume("<="):144 op = opLe145 case p.TryConsume(">="):146 op = opGe147 case p.TryConsume("<"):148 op = opLt149 case p.TryConsume(">"):150 op = opGt151 }152 if op == opNop {153 break154 }155 ex = &exprBin{156 op: op,157 lex: ex,158 rex: p.parseExprTerm(),159 }160 }161 return ex162}163func (p *parser) parseExprTerm() expr {164 if p.TryConsume("$") {165 return &exprShell{166 cmd: p.Shell(),167 }168 }169 if str, ok := p.TryQuotedString(); ok {170 return &exprString{171 val: str,172 }173 }174 if p.TryConsume("!") {175 return &exprNot{176 ex: p.parseExprTerm(),177 }178 }179 if p.TryConsume("(") {180 ex := p.parseExpr()181 p.MustConsume(")")182 return ex183 }184 return &exprIdent{185 name: p.Ident(),186 }187}...

Full Screen

Full Screen

TryConsume

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "github.com/andlabs/ui"3import "github.com/andlabs/ui/winmanifest"4func main() {5 ui.Main(func() {6 ui.OnShouldQuit(func() bool {7 ui.Quit()8 })9 win := ui.NewWindow("Hello, world!", 200, 100, false)10 win.SetMargined(true)11 entry := ui.NewEntry()12 button := ui.NewButton("Click")13 vbox := ui.NewVerticalBox()14 vbox.SetPadded(true)15 vbox.Append(entry, false)16 vbox.Append(button, false)17 win.SetChild(vbox)18 button.OnClicked(func() {19 fmt.Println(entry.Text())20 })21 win.OnClosing(func(*ui.Window) bool {22 ui.Quit()23 })24 win.Show()25 })26}27import "fmt"28import "github.com/andlabs/ui"29import "github.com/andlabs/ui/winmanifest"30func main() {31 ui.Main(func() {32 ui.OnShouldQuit(func() bool {33 ui.Quit()34 })35 win := ui.NewWindow("Hello, world!", 200, 100, false)36 win.SetMargined(true)37 entry := ui.NewEntry()38 button := ui.NewButton("Click")39 vbox := ui.NewVerticalBox()40 vbox.SetPadded(true)41 vbox.Append(entry, false)42 vbox.Append(button, false)43 win.SetChild(vbox)44 button.OnClicked(func() {45 fmt.Println(entry.Text())46 })47 win.OnClosing(func(*ui.Window) bool {48 ui.Quit()49 })50 win.Show()51 })52}53import "fmt"54import "github.com/andlabs/ui"55import "github.com/andlabs/ui/winmanifest"56func main() {57 ui.Main(func() {58 ui.OnShouldQuit(func() bool {59 ui.Quit()60 })61 win := ui.NewWindow("Hello, world!", 200, 100, false)62 win.SetMargined(true)63 entry := ui.NewEntry()64 button := ui.NewButton("Click")

Full Screen

Full Screen

TryConsume

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 k := kconfig.NewKconfig()4 k.LoadConfigFile("/home/abc/def/ghi.config")5 k.TryConsume("abc")6 k.TryConsume("def")7 k.TryConsume("ghi")8 k.TryConsume("jkl")9 k.TryConsume("mno")10 k.TryConsume("pqr")11 k.TryConsume("stu")12 k.TryConsume("vwx")13 k.TryConsume("yza")14 k.TryConsume("bcd")15 k.TryConsume("efg")16 k.TryConsume("hij")17 k.TryConsume("klm")18 k.TryConsume("nop")19 k.TryConsume("qrs")20 k.TryConsume("tuv")21 k.TryConsume("wxy")22 k.TryConsume("zab")23 k.TryConsume("cde")24 k.TryConsume("fgh")25 k.TryConsume("ijk")26 k.TryConsume("lmn")27 k.TryConsume("opq")28 k.TryConsume("rst")29 k.TryConsume("uvw")30 k.TryConsume("xyz")31 k.TryConsume("abc")32 k.TryConsume("def")33 k.TryConsume("ghi")34 k.TryConsume("jkl")35 k.TryConsume("mno")36 k.TryConsume("pqr")37 k.TryConsume("stu")38 k.TryConsume("vwx")39 k.TryConsume("yza")40 k.TryConsume("bcd")41 k.TryConsume("efg")42 k.TryConsume("hij")43 k.TryConsume("klm")44 k.TryConsume("nop")45 k.TryConsume("qrs")46 k.TryConsume("tuv")47 k.TryConsume("wxy")48 k.TryConsume("zab")49 k.TryConsume("cde")50 k.TryConsume("fgh")51 k.TryConsume("ijk")52 k.TryConsume("lmn")53 k.TryConsume("opq")54 k.TryConsume("rst")55 k.TryConsume("uvw")56 k.TryConsume("xyz")57 k.TryConsume("abc

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful