How to use EOF method of prog Package

Best Syzkaller code snippet using prog.EOF

parser_test.go

Source:parser_test.go Github

copy

Full Screen

...27 {"[1,]", "List", "[1]", 1, 1},28 {"[1, 2]", "List", "[1, 2]", 1, 1},29 {"[1, 2,]", "List", "[1, 2]", 1, 1},30 {"[a+b, f(),]", "List", "[(a + b), f()]", 1, 1},31 {"[", "", "expected ] and not EOF", 1, 2},32 {"[1 2", "", "expected , between list elements", 1, 4},33 {"[,]", "", "expected expression, not ,", 1, 2},34 // Maps35 {`{}`, "Map", `{}`, 1, 1},36 {`{"a": 1}`, "Map", `{"a": 1}`, 1, 1},37 {`{x: 1}`, "Map", `{x: 1}`, 1, 1},38 {`{x: 1,}`, "Map", `{x: 1}`, 1, 1},39 {`{x: 1, b: 2}`, "Map", `{x: 1, b: 2}`, 1, 1},40 {`{x: 1, b: 2,}`, "Map", `{x: 1, b: 2}`, 1, 1},41 {`{x + y: 1, "a" + f(): g() / 4,}`, "Map", `{(x + y): 1, ("a" + f()): (g() / 4)}`, 1, 1},42 {`{x, 1}`, "", `expected : and not ,`, 1, 3},43 {`{x: 1: b: 2}`, "", `expected , between map items`, 1, 6},44 {`{`, "", `expected } and not EOF`, 1, 2},45 {`{x: 1 b`, "", `expected , between map items`, 1, 7},46 {`{,}`, "", `expected expression, not ,`, 1, 2},47 // Function expressions48 {"func() {}", "FunctionExpression", "func() {}", 1, 1},49 {"func(a) {}", "FunctionExpression", "func(a) {}", 1, 1},50 {"func(a,) {}", "FunctionExpression", "func(a) {}", 1, 1},51 {"func(a...) {}", "FunctionExpression", "func(a...) {}", 1, 1},52 {"func(a, b) {}", "FunctionExpression", "func(a, b) {}", 1, 1},53 {"func(a, b...) {}", "FunctionExpression", "func(a, b...) {}", 1, 1},54 {"func(a, b...,) {}", "FunctionExpression", "func(a, b...) {}", 1, 1},55 {"func(a, b,) {}", "FunctionExpression", "func(a, b) {}", 1, 1},56 {"func(a, b,) { return 0 }", "FunctionExpression", "func(a, b) {\n return 0\n}", 1, 1},57 {"func(a: b) {}", "", "expected , between parameters", 1, 7},58 {"func(a..., b) {}", "", "can only have ... after last parameter", 1, 12},59 {"func(,) {}", "", "expected name and not ,", 1, 6},60 {"func(", "", "expected ) and not EOF", 1, 6},61 // Grouping62 {"(1 + 2)", "Binary", "(1 + 2)", 1, 4},63 {"(1 + 2) * 3", "Binary", "((1 + 2) * 3)", 1, 9},64 {"(((1) + 2))", "Binary", "(1 + 2)", 1, 7},65 {"(1 + 2]", "", "expected ) and not ]", 1, 7},66 {"(1 +", "", "expected expression, not EOF", 1, 5},67 {"(1 + 2", "", "expected ) and not EOF", 1, 7},68 // Subscript and dot expressions69 {`a.b`, "Subscript", `a["b"]`, 1, 2},70 {`a.b.c`, "Subscript", `a["b"]["c"]`, 1, 4},71 {`a.b["c"]`, "Subscript", `a["b"]["c"]`, 1, 4},72 {`a["b"].c`, "Subscript", `a["b"]["c"]`, 1, 7},73 {`a["b"]["c"]`, "Subscript", `a["b"]["c"]`, 1, 7},74 {`a.`, "", `expected name and not EOF`, 1, 3},75 {`a.1`, "", `expected name and not int`, 1, 3},76 {`a[...]`, "", `expected expression, not ...`, 1, 3},77 // Function calls78 {"f()", "Call", "f()", 1, 2},79 {"f(a)", "Call", "f(a)", 1, 2},80 {"f(a,)", "Call", "f(a)", 1, 2},81 {"f(a, b)", "Call", "f(a, b)", 1, 2},82 {"f(a, b,)", "Call", "f(a, b)", 1, 2},83 {"f(a...)", "Call", "f(a...)", 1, 2},84 {"f(a...,)", "Call", "f(a...)", 1, 2},85 {"f(a, b...)", "Call", "f(a, b...)", 1, 2},86 {"f(a, b, c...)", "Call", "f(a, b, c...)", 1, 2},87 {"f(,)", "", "expected expression, not ,", 1, 3},88 {"f(a b)", "", "expected , between arguments", 1, 5},89 {"f(a..., b)", "", "can only have ... after last argument", 1, 9},90 {"f(a,", "", "expected ) and not EOF", 1, 5},91 // Negative (unary minus)92 {"-3", "Unary", "(-3)", 1, 1},93 {"--3", "Unary", "(-(-3))", 1, 1},94 {"-(a + b)", "Unary", "(-(a + b))", 1, 1},95 {"-", "", "expected expression, not EOF", 1, 2},96 // Multiplication97 {"1 * 2", "Binary", "(1 * 2)", 1, 3},98 {"1 * 2 * 3", "Binary", "((1 * 2) * 3)", 1, 7},99 {"1 * (2 * 3)", "Binary", "(1 * (2 * 3))", 1, 3},100 {"1 + 2 * 3", "Binary", "(1 + (2 * 3))", 1, 3},101 {"1 * 2 + 3", "Binary", "((1 * 2) + 3)", 1, 7},102 {"1 * -2", "Binary", "(1 * (-2))", 1, 3},103 {"-1 * 2", "Binary", "((-1) * 2)", 1, 4},104 {"1 *", "", "expected expression, not EOF", 1, 4},105 // Division (same precedence as multiplication)106 {"1 / 2", "Binary", "(1 / 2)", 1, 3},107 {"1 / 2 / 3", "Binary", "((1 / 2) / 3)", 1, 7},108 {"1 / (2 / 3)", "Binary", "(1 / (2 / 3))", 1, 3},109 {"1 + 2 / 3", "Binary", "(1 + (2 / 3))", 1, 3},110 {"1 / 2 + 3", "Binary", "((1 / 2) + 3)", 1, 7},111 {"1 / -2", "Binary", "(1 / (-2))", 1, 3},112 {"-1 / 2", "Binary", "((-1) / 2)", 1, 4},113 {"1 /", "", "expected expression, not EOF", 1, 4},114 // Modulo (same precedence as multiplication)115 {"1 % 2", "Binary", "(1 % 2)", 1, 3},116 {"1 % 2 % 3", "Binary", "((1 % 2) % 3)", 1, 7},117 {"1 % (2 % 3)", "Binary", "(1 % (2 % 3))", 1, 3},118 {"1 + 2 % 3", "Binary", "(1 + (2 % 3))", 1, 3},119 {"1 % 2 + 3", "Binary", "((1 % 2) + 3)", 1, 7},120 {"1 % -2", "Binary", "(1 % (-2))", 1, 3},121 {"-1 % 2", "Binary", "((-1) % 2)", 1, 4},122 {"1 %", "", "expected expression, not EOF", 1, 4},123 // Addition124 {"1 + 2", "Binary", "(1 + 2)", 1, 3},125 {"1 + 2 + 3", "Binary", "((1 + 2) + 3)", 1, 7},126 {"1 + (2 + 3)", "Binary", "(1 + (2 + 3))", 1, 3},127 {"1 < 2 + 3", "Binary", "(1 < (2 + 3))", 1, 3},128 {"1 + 2 < 3", "Binary", "((1 + 2) < 3)", 1, 7},129 {"1 +", "", "expected expression, not EOF", 1, 4},130 // Subtraction (same precedence as addition)131 {"1 - 2", "Binary", "(1 - 2)", 1, 3},132 {"1 - 2 - 3", "Binary", "((1 - 2) - 3)", 1, 7},133 {"1 - (2 - 3)", "Binary", "(1 - (2 - 3))", 1, 3},134 {"1 < 2 - 3", "Binary", "(1 < (2 - 3))", 1, 3},135 {"1 - 2 < 3", "Binary", "((1 - 2) < 3)", 1, 7},136 {"1 -", "", "expected expression, not EOF", 1, 4},137 // Less than138 {"1 < 2", "Binary", "(1 < 2)", 1, 3},139 {"1 < 2 < 3", "Binary", "((1 < 2) < 3)", 1, 7},140 {"1 < (2 < 3)", "Binary", "(1 < (2 < 3))", 1, 3},141 {"1 == 2 < 3", "Binary", "(1 == (2 < 3))", 1, 3},142 {"1 < 2 == 3", "Binary", "((1 < 2) == 3)", 1, 7},143 {"1 <", "", "expected expression, not EOF", 1, 4},144 // Less than or equal (same precedence as less than)145 {"1 <= 2", "Binary", "(1 <= 2)", 1, 3},146 {"1 <= 2 <= 3", "Binary", "((1 <= 2) <= 3)", 1, 8},147 {"1 <= (2 <= 3)", "Binary", "(1 <= (2 <= 3))", 1, 3},148 {"1 == 2 <= 3", "Binary", "(1 == (2 <= 3))", 1, 3},149 {"1 <= 2 == 3", "Binary", "((1 <= 2) == 3)", 1, 8},150 {"1 <=", "", "expected expression, not EOF", 1, 5},151 // Greater than (same precedence as less than)152 {"1 > 2", "Binary", "(1 > 2)", 1, 3},153 {"1 > 2 > 3", "Binary", "((1 > 2) > 3)", 1, 7},154 {"1 > (2 > 3)", "Binary", "(1 > (2 > 3))", 1, 3},155 {"1 == 2 > 3", "Binary", "(1 == (2 > 3))", 1, 3},156 {"1 > 2 == 3", "Binary", "((1 > 2) == 3)", 1, 7},157 {"1 >", "", "expected expression, not EOF", 1, 4},158 // Greater than or equal (same precedence as less than)159 {"1 >= 2", "Binary", "(1 >= 2)", 1, 3},160 {"1 >= 2 >= 3", "Binary", "((1 >= 2) >= 3)", 1, 8},161 {"1 >= (2 >= 3)", "Binary", "(1 >= (2 >= 3))", 1, 3},162 {"1 == 2 >= 3", "Binary", "(1 == (2 >= 3))", 1, 3},163 {"1 >= 2 == 3", "Binary", "((1 >= 2) == 3)", 1, 8},164 {"1 >=", "", "expected expression, not EOF", 1, 5},165 // The "in" operator (same precedence as less than)166 {"1 in 2", "Binary", "(1 in 2)", 1, 3},167 {"1 in 2 in 3", "Binary", "((1 in 2) in 3)", 1, 8},168 {"1 in (2 in 3)", "Binary", "(1 in (2 in 3))", 1, 3},169 {"1 == 2 in 3", "Binary", "(1 == (2 in 3))", 1, 3},170 {"1 in 2 == 3", "Binary", "((1 in 2) == 3)", 1, 8},171 {"1 in", "", "expected expression, not EOF", 1, 5},172 // Equals173 {"1 == 2", "Binary", "(1 == 2)", 1, 3},174 {"1 == 2 == 3", "Binary", "((1 == 2) == 3)", 1, 8},175 {"1 == (2 == 3)", "Binary", "(1 == (2 == 3))", 1, 3},176 {"1 == not 2", "", "expected expression, not not", 1, 6},177 {"not 1 == 2", "Unary", "(not (1 == 2))", 1, 1},178 {"1 ==", "", "expected expression, not EOF", 1, 5},179 // Not equals (same precedence as equals)180 {"1 != 2", "Binary", "(1 != 2)", 1, 3},181 {"1 != 2 != 3", "Binary", "((1 != 2) != 3)", 1, 8},182 {"1 != (2 != 3)", "Binary", "(1 != (2 != 3))", 1, 3},183 {"1 != not 2", "", "expected expression, not not", 1, 6},184 {"not 1 != 2", "Unary", "(not (1 != 2))", 1, 1},185 {"1 !=", "", "expected expression, not EOF", 1, 5},186 // Logical not187 {"not 1", "Unary", "(not 1)", 1, 1},188 {"not not 1", "Unary", "(not (not 1))", 1, 1},189 {"not 1 and not 2", "Binary", "((not 1) and (not 2))", 1, 7},190 {"not", "", "expected expression, not EOF", 1, 4},191 // Logical and192 {"1 and 2", "Binary", "(1 and 2)", 1, 3},193 {"1 and 2 and 3", "Binary", "((1 and 2) and 3)", 1, 9},194 {"1 and (2 and 3)", "Binary", "(1 and (2 and 3))", 1, 3},195 {"1 or 2 and 3", "Binary", "(1 or (2 and 3))", 1, 3},196 {"1 and 2 or 3", "Binary", "((1 and 2) or 3)", 1, 9},197 {"1 and", "", "expected expression, not EOF", 1, 6},198 // Logical or199 {"1 or 2", "Binary", "(1 or 2)", 1, 3},200 {"1 or 2 or 3", "Binary", "((1 or 2) or 3)", 1, 8},201 {"1 or (2 or 3)", "Binary", "(1 or (2 or 3))", 1, 3},202 {"1 or", "", "expected expression, not EOF", 1, 5},203 // Crazy expression with everything in it204 {205 `f(1 or 2, 3 and 4, not 5, 6==7, 8!=9, a<b, c<=d, e>f, g>=h, i in j, q*r, s/t, u%v, -w, x(), y.z, A["B"], true, false, nil, [], {})`,206 "Call",207 `f((1 or 2), (3 and 4), (not 5), (6 == 7), (8 != 9), (a < b), (c <= d), (e > f), (g >= h), (i in j), (q * r), (s / t), (u % v), (-w), x(), y["z"], A["B"], true, false, nil, [], {})`,208 1,209 2,210 },211 // Miscellaneous expressions212 {"a + b // add things", "Binary", "(a + b)", 1, 3},213 {"a\n+\nb", "Binary", "(a + b)", 2, 1},214 {"", "", "expected expression, not EOF", 1, 1},215 {"if true { print(1) }", "", "expected expression, not if", 1, 1},216 }217 for _, test := range tests {218 testName := test.source219 if len(testName) > 20 {220 testName = testName[:20]221 }222 t.Run(testName, func(t *testing.T) {223 expr, err := parser.ParseExpression([]byte(test.source))224 if err != nil {225 parseError, ok := err.(parser.Error)226 if !ok {227 t.Fatalf("unexpected parse error type %T", err)228 }229 if test.typeName != "" {230 t.Fatalf("expected error, got %q", test.typeName)231 }232 output := parseError.Message233 if output != test.output {234 t.Fatalf("expected %q, got %q", test.output, output)235 }236 if parseError.Position.Line != test.line || parseError.Position.Column != test.column {237 t.Fatalf("expected %d:%d, got %d:%d", test.line, test.column,238 parseError.Position.Line, parseError.Position.Column)239 }240 } else {241 exprType := reflect.TypeOf(expr)242 shortName := exprType.String()[8:]243 if shortName != test.typeName {244 t.Fatalf("expected type %q, got %q", test.typeName, shortName)245 }246 exprString := fmt.Sprintf("%s", expr)247 if exprString != test.output {248 t.Fatalf("expected %s, got %s", test.output, exprString)249 }250 if expr.Position().Line != test.line || expr.Position().Column != test.column {251 t.Fatalf("expected %d:%d, got %d:%d", test.line, test.column,252 expr.Position().Line, expr.Position().Column)253 }254 }255 })256 }257}258func TestParseProgram(t *testing.T) {259 tests := []struct {260 source string261 output string262 line int263 column int264 }{265 // If statements266 {"if a { f() }", `if a {267 f()268}`, 1, 1},269 {"if a { f() g() }", `if a {270 f()271 g()272}`, 1, 1},273 {"if a == 0 { f() }", `if (a == 0) {274 f()275}`, 1, 1},276 {"if a { f() } else { g() }", `if a {277 f()278} else {279 g()280}`, 1, 1},281 {"if a { f() } else if b { g() } else { h() }", `if a {282 f()283} else {284 if b {285 g()286 } else {287 h()288 }289}`, 1, 1},290 {"if a { f() } if b { g() }", `if a {291 f()292}293if b {294 g()295}`, 1, 1},296 {"if a { f() } else while b { g() }", "expected { or if after else, not while", 1, 19},297 {"if a {", "expected } and not EOF", 1, 7},298 {"if", "expected expression, not EOF", 1, 3},299 // While statements300 {"while a { f() }", `while a {301 f()302}`, 1, 1},303 {"while a == 0 { f() g() }", `while (a == 0) {304 f()305 g()306}`, 1, 1},307 {"while a {", "expected } and not EOF", 1, 10},308 {"while", "expected expression, not EOF", 1, 6},309 // For statements310 {"for a in c + d { e() }", `for a in (c + d) {311 e()312}`, 1, 1},313 {"for a in b { c() d() }", `for a in b {314 c()315 d()316}`, 1, 1},317 {"for 12 in a { }", "expected name and not int", 1, 5},318 {"for a if b { }", "expected in and not if", 1, 7},319 {"for a in b c()", "expected { and not name", 1, 12},320 {"for a in b {", "expected } and not EOF", 1, 13},321 {"for", "expected name and not EOF", 1, 4},322 // Return statements (return outside of function is legal according323 // to the parser, but causes a runtime error)324 {"return a", "return a", 1, 1},325 {"func() { return 1 }", `func() {326 return 1327}`, 1, 1},328 {"func() { return a + b }", `func() {329 return (a + b)330}`, 1, 1},331 {"func() { return }", "expected expression, not }", 1, 17},332 {"func() { return if }", "expected expression, not if", 1, 17},333 // Function definitions (function expression is kinda useless at the334 // statement level -- does nothing but is valid syntax)335 {"func() {}", "func() {}", 1, 1},336 {"func add(a, b) { return a + b }", `func add(a, b) {337 return (a + b)338}`, 1, 1},339 {"func go() { print(1) print(2) }", `func go() {340 print(1)341 print(2)342}`, 1, 1},343 {`func outside() {344 func inner() {}345 return inner346}`, `func outside() {347 func inner() {}348 return inner349}`, 1, 1},350 {"func f(a) {}", "func f(a) {}", 1, 1},351 {"func f(a,) {}", "func f(a) {}", 1, 1},352 {"func f(a...) {}", "func f(a...) {}", 1, 1},353 {"func f(a, b) {}", "func f(a, b) {}", 1, 1},354 {"func f(a, b...) {}", "func f(a, b...) {}", 1, 1},355 {"func f(a, b...,) {}", "func f(a, b...) {}", 1, 1},356 {"func f(a, b,) {}", "func f(a, b) {}", 1, 1},357 {"func f(a, b,) { return 0 }", "func f(a, b) {\n return 0\n}", 1, 1},358 {"func f(a: b) {}", "expected , between parameters", 1, 9},359 {"func f(a..., b) {}", "can only have ... after last parameter", 1, 14},360 {"func f(,) {}", "expected name and not ,", 1, 8},361 {"func f(", "expected ) and not EOF", 1, 8},362 // Assignments363 {"a = 1", "a = 1", 1, 3},364 {"a = 1 b = 2", "a = 1\nb = 2", 1, 3},365 {"a = 1\nb = 2", "a = 1\nb = 2", 1, 3},366 {"a = 1 + 2", "a = (1 + 2)", 1, 3},367 {`x.y = 3`, `x["y"] = 3`, 1, 5},368 {`x["y"] = 3`, `x["y"] = 3`, 1, 8},369 {"(a + b) = 3", "expected name, subscript, or dot expression on left side of =", 1, 9},370 // Comments, expression statements, multiline programs, etc371 {"", "", 0, 0},372 {"// just a comment", "", 0, 0},373 {"// foo\nif a {}", "if a {\n \n}", 2, 1},374 {"print(1234)", "print(1234)", 1, 1},375 {`...

Full Screen

Full Screen

re1.go

Source:re1.go Github

copy

Full Screen

1// Package re1 implements a very simple regular expression language.2// The language is inspired by plan9 regular expressions3// (https://9fans.github.io/plan9port/man/man7/regexp.html),4// rsc's regexp blog posts (https://swtch.com/~rsc/regexp),5// and nominally by the much more sohpistocated RE2 library6// (https://github.com/google/re2).7//8// The grammar is:9// regexp = choice.10// choice = concat [ "|" choice ].11// concat = repeat [ concat ].12// repeat = term { "*" | "+" | "?" }.13// term = "." | "^" | "$" | "(" regexp ")" | charclass | literal.14// charclass = "[" [ "^" ] ( classlit [ "-" classlit ] ) { classlit [ "-" classlit ] } "]".15// A literal is any non-meta rune or a rune preceded by \.16// A classlit is any non-"]", non-"-" rune or a rune preceded by \.17//18// The meta characters are:19// | choice20// * zero or more, greedy21// + one or more, greedy22// ? zero or one23// . any non-newline rune24// ^ beginning of file or line25// $ end of file or line26// () capturing group27// [] character class (^ negates, - is a range)28// \n newline29// \t tab30// \ otherwise is the literal of the following rune31// or is \ itself if there is no following rune.32package re133import (34 "errors"35 "io"36 "strings"37 "unicode/utf8"38)39// Regexp is a compiled regular expression.40type Regexp struct {41 prog []instr42 ncap int43 class [][][2]rune44 source string45}46// Opts are compile-time options. The zero value is default.47type Opts struct {48 // Reverse compiles the expression for reverse matching.49 // This swaps the order of concatenations, and it swaps ^ and $.50 Reverse bool51 // Delimiter specifies a rune that delimits parsing if unescaped.52 Delimiter rune53 // ID is a user-specfied ID to identify the the regexp.54 // This is used to distinguish which regexp matched55 // when concatenating multiple regexps into one.56 ID int57}58// New compiles a regular expression.59// The expression is terminated by the end of the string,60// an un-escaped newline,61// or an un-escaped delimiter (if set in opts).62func New(t string, opts Opts) (*Regexp, string, error) {63 src := t64 switch re, t, err := choice(t, 0, opts); {65 case err != nil:66 return nil, "", err67 case re == nil:68 re = &Regexp{}69 fallthrough70 default:71 re = groupProg(re)72 re.prog = append(re.prog, instr{op: match, arg: opts.ID})73 re.source = src74 return re, t, nil75 }76}77const (78 any = -iota79 bol80 eol81 class // arg is class index82 nclass // arg is class index83 jmp // arg is jump offset84 fork // arg is low-priority fork offset (high-priority is 1)85 rfork // arg is high-priority fork offset (low-priority is 1)86 save // arg is save-to index87 match // arg is the id of the matching regexp88)89type instr struct {90 op int91 arg int92}93func choice(t0 string, depth int, opts Opts) (*Regexp, string, error) {94 switch left, t, err := concat(t0, depth, opts); {95 case err != nil:96 return nil, "", err97 case peek(t) != '|':98 return left, t, nil99 case left == nil:100 return nil, "", errors.New("unexpected |")101 default:102 _, t = next(t) // eat |103 var right *Regexp104 if right, t, err = choice(t, depth, opts); err != nil {105 return nil, "", err106 }107 return choiceProg(left, right), t, nil108 }109}110func concat(t string, depth int, opts Opts) (*Regexp, string, error) {111 left, t, err := repeat(t, depth, opts)112 if left == nil || err != nil {113 return left, t, err114 }115 var right *Regexp116 switch right, t, err = concat(t, depth, opts); {117 case err != nil:118 return nil, "", err119 case right != nil:120 left = catProg(left, right, opts.Reverse)121 fallthrough122 default:123 return left, t, err124 }125}126func repeat(t string, depth int, opts Opts) (*Regexp, string, error) {127 left, t, err := term(t, depth, opts)128 if left == nil || err != nil {129 return left, t, err130 }131 for strings.ContainsRune("*+?", peek(t)) {132 var r rune133 r, t = next(t)134 left = repProg(left, r)135 }136 return left, t, nil137}138func term(t0 string, depth int, opts Opts) (*Regexp, string, error) {139 switch r, t := next(t0); r {140 case eof, '\n', opts.Delimiter:141 return nil, t, nil142 case '\\':143 r, t = esc(t)144 fallthrough145 default:146 return opProg(int(r)), t, nil147 case '.':148 return opProg(any), t, nil149 case '^':150 if opts.Reverse {151 return opProg(eol), t, nil152 }153 return opProg(bol), t, nil154 case '$':155 if opts.Reverse {156 return opProg(bol), t, nil157 }158 return opProg(eol), t, nil159 case '(':160 return group(t, depth, opts)161 case '[':162 return charclass(t)163 case '|':164 return nil, t0, nil165 case ')':166 if depth == 0 {167 return nil, t, errors.New("unopened )")168 }169 return nil, t0, nil170 case '*', '+', '?':171 return nil, "", errors.New("unexpected " + string([]rune{r}))172 }173}174func group(t string, depth int, opts Opts) (*Regexp, string, error) {175 left, t, err := choice(t, depth+1, opts)176 switch r, t := next(t); {177 case err != nil:178 return nil, "", err179 case r != ')':180 return nil, "", errors.New("unclosed (")181 case left == nil:182 left = &Regexp{}183 fallthrough184 default:185 return groupProg(left), t, nil186 }187}188func charclass(t string) (*Regexp, string, error) {189 op := class190 if peek(t) == '^' {191 _, t = next(t) // eat ^192 op = nclass193 }194 var r, p rune195 var cl [][2]rune196 for len(t) > 0 {197 switch r, t = next(t); r {198 case ']':199 if p != 0 {200 cl = append(cl, [2]rune{p, p})201 }202 if len(cl) == 0 {203 return nil, "", errors.New("empty charclass")204 }205 return charClassProg(op, cl), t, nil206 case '-':207 if p == 0 || peek(t) == ']' || peek(t) == '-' {208 return nil, "", errors.New("bad range")209 }210 r, t = next(t)211 if r == '\\' {212 r, t = esc(t)213 }214 if p >= r {215 return nil, "", errors.New("bad range")216 }217 cl = append(cl, [2]rune{p, r})218 p = 0219 case '\\':220 r, t = esc(t)221 fallthrough222 default:223 if p != 0 {224 cl = append(cl, [2]rune{p, p})225 }226 p = r227 }228 }229 return nil, "", errors.New("unclosed [")230}231func choiceProg(left, right *Regexp) *Regexp {232 prog := make([]instr, 0, 2+len(left.prog)+len(right.prog))233 prog = append(prog, instr{op: fork, arg: len(left.prog) + 2})234 prog = append(prog, left.prog...)235 left.prog = append(prog, instr{op: jmp, arg: len(right.prog) + 1})236 return catProg(left, right, false)237}238func catProg(left, right *Regexp, rev bool) *Regexp {239 for i := range right.prog {240 instr := &right.prog[i]241 if instr.op == save {242 instr.arg += left.ncap * 2243 }244 }245 if rev {246 left, right = right, left247 }248 for _, instr := range right.prog {249 if instr.op == class || instr.op == nclass {250 instr.arg += len(left.class)251 }252 left.prog = append(left.prog, instr)253 }254 left.ncap += right.ncap255 left.class = append(left.class, right.class...)256 return left257}258func repProg(left *Regexp, op rune) *Regexp {259 prog := make([]instr, 0, len(left.prog)+2)260 switch op {261 case '+':262 prog = append(left.prog, instr{op: rfork, arg: -len(left.prog)})263 case '*':264 prog = []instr{{op: fork, arg: len(left.prog) + 2}}265 prog = append(prog, left.prog...)266 prog = append(prog, instr{op: rfork, arg: -len(prog) + 1})267 case '?':268 prog = []instr{{op: fork, arg: len(left.prog) + 1}}269 prog = append(prog, left.prog...)270 }271 left.prog = prog272 return left273}274func groupProg(left *Regexp) *Regexp {275 prog := make([]instr, 0, len(left.prog)+2)276 prog = append(prog, instr{op: save, arg: 0})277 for _, instr := range left.prog {278 if instr.op == save {279 instr.arg += 2280 }281 prog = append(prog, instr)282 }283 left.prog = append(prog, instr{op: save, arg: 1})284 left.ncap++285 return left286}287func charClassProg(op int, cl [][2]rune) *Regexp {288 return &Regexp{prog: []instr{{op: op}}, class: [][][2]rune{cl}}289}290func opProg(op int) *Regexp { return &Regexp{prog: []instr{{op: op}}} }291const eof = -1292func next(t string) (rune, string) {293 if len(t) == 0 {294 return eof, ""295 }296 r, w := utf8.DecodeRuneInString(t)297 return r, t[w:]298}299func peek(t string) rune {300 r, _ := next(t)301 return r302}303func esc(t string) (rune, string) {304 var r rune305 switch r, t = next(t); r {306 case eof:307 r = '\\'308 case 'n':309 r = '\n'310 case 't':311 r = '\t'312 }313 return r, t314}315// Find returns nil on no match or a slice with pairs of int64s for each sub-expression match (0 is the full match) and the last element is the matching regexp ID.316func (re *Regexp) Find(rr io.RuneReader) []int64 { return run(newVM(re, rr)) }317type vm struct {318 re *Regexp319 rr io.RuneReader320 at, lim int64321 c, n rune // cur and next rune.322 seen []int64 // at for which each pc was last add()ed.323 cur, next []thread324 free [][]int64325 match []int64326}327type thread struct {328 pc int329 mem []int64330}331func newVM(re *Regexp, rr io.RuneReader) *vm {332 v := &vm{re: re, rr: rr, lim: -1, c: eof, n: eof}333 v.seen = make([]int64, len(re.prog))334 for i := range v.seen {335 v.seen[i] = -1336 }337 read(v)338 return v339}340func newMem(v *vm, init []int64) (m []int64) {341 if n := len(v.free); n > 0 {342 m, v.free = v.free[n-1], v.free[:n-1]343 } else {344 m = make([]int64, 2*v.re.ncap+1 /* match ID */)345 }346 if init != nil {347 copy(m, init)348 return m349 }350 for i := range m {351 m[i] = -1352 }353 return m354}355func run(v *vm) []int64 {356 for {357 if v.match == nil {358 add(v, 0, newMem(v, nil))359 }360 if v.lim >= 0 && v.at >= v.lim {361 // Check this after add() to allow empty regexps to match empty.362 return v.match363 }364 read(v)365 v.cur, v.next = v.next, v.cur[:0]366 for _, t := range v.cur {367 step(v, t.pc, t.mem)368 }369 if v.c == eof || (v.match != nil && len(v.next) == 0) {370 return v.match371 }372 }373}374func read(v *vm) {375 if v.n != eof {376 v.at += int64(utf8.RuneLen(v.n))377 }378 v.c = v.n379 var err error380 if v.n, _, err = v.rr.ReadRune(); err != nil {381 v.n = eof382 }383}384func step(v *vm, pc int, mem []int64) {385 if !accepts(v, v.re.prog[pc]) {386 v.free = append(v.free, mem)387 return388 }389 add(v, pc+1, mem)390}391func accepts(v *vm, instr instr) bool {392 switch instr.op {393 case any:394 return v.c != '\n' && v.c != eof395 case class, nclass:396 cl := v.re.class[instr.arg]397 return classAccepts(v.c, cl, instr.op == nclass)398 default:399 return int(v.c) == instr.op400 }401}402func classAccepts(r rune, class [][2]rune, neg bool) bool {403 if r == eof {404 return false405 }406 for _, c := range class {407 if c[0] <= r && r <= c[1] {408 return !neg409 }410 }411 return neg412}413func add(v *vm, pc int, mem []int64) {414 if v.seen[pc] == v.at {415 v.free = append(v.free, mem)416 return417 }418 v.seen[pc] = v.at419 _add(v, pc, mem)420}421func _add(v *vm, pc int, mem []int64) {422 switch instr := v.re.prog[pc]; instr.op {423 default:424 v.next = append(v.next, thread{pc: pc, mem: mem})425 case jmp:426 add(v, pc+instr.arg, mem)427 case fork:428 clone := newMem(v, mem)429 add(v, pc+1, mem)430 add(v, pc+instr.arg, clone)431 case rfork:432 clone := newMem(v, mem)433 add(v, pc+instr.arg, mem)434 add(v, pc+1, clone)435 case save:436 mem[instr.arg] = v.at437 add(v, pc+1, mem)438 case bol:439 if v.c != eof && v.c != '\n' {440 v.free = append(v.free, mem)441 return442 }443 add(v, pc+1, mem)444 case eol:445 if v.n != eof && v.n != '\n' {446 v.free = append(v.free, mem)447 return448 }449 add(v, pc+1, mem)450 case match:451 mem[len(mem)-1] = int64(instr.arg)452 setMatch(v, mem)453 }454}455func setMatch(v *vm, mem []int64) {456 switch {457 case v.match == nil:458 v.match = mem459 case mem[0] <= v.match[0] && mem[1] > v.match[1]:460 v.free = append(v.free, v.match)461 v.match = mem462 default:463 v.free = append(v.free, mem)464 }465}...

Full Screen

Full Screen

intcode.go

Source:intcode.go Github

copy

Full Screen

...19 log.Fatal(err)20 }21 defer file.Close()22 scanner := bufio.NewScanner(file)23 splitComma := func(data []byte, atEOF bool) (advance int, token []byte, err error) {24 dataLen := len(data)25 // Return nothing if at end of file and no data passed26 if atEOF && dataLen == 0 {27 return 0, nil, nil28 }29 // Find next separator and return token30 if i := bytes.IndexByte(data, ','); i >= 0 {31 return i + 1, data[0:i], nil32 }33 // If we're at EOF, we have a final, non-terminated line. Return it.34 if atEOF {35 return dataLen, data, nil36 }37 // Request more data.38 return 0, nil, nil39 }40 scanner.Split(splitComma)41 for scanner.Scan() {42 n, err := strconv.ParseInt(scanner.Text(), 10, 64)43 if err != nil {44 fmt.Println(err)45 }46 initProg = append(initProg, n)47 }48}...

Full Screen

Full Screen

EOF

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 for {4 _, err := fmt.Scan(&i)5 if err != nil {6 fmt.Println("EOF")7 os.Exit(0)8 }9 fmt.Println(i)10 }11}

Full Screen

Full Screen

EOF

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 for {4 if i > 10 {5 }6 fmt.Println(i)7 }8 fmt.Println("End of the program")9 os.Exit(0)10}11import (12func main() {13 for i <= 10 {14 fmt.Println(i)15 }16 fmt.Println("End of the program")17 os.Exit(0)18}19import (20func main() {21 for {22 fmt.Println(i)23 if i > 10 {24 }25 }26 fmt.Println("End of the program")27 os.Exit(0)28}29import (30func main() {31 for {32 if i > 10 {33 }34 fmt.Println(i)35 }36 fmt.Println("End of the program")37 os.Exit(0)38}39import (40func main() {41 for i <= 10 {42 fmt.Println(i)43 }44 fmt.Println("End of the program")45 os.Exit(0)46}47import (48func main() {49 for {50 fmt.Println(i)51 if i > 10 {52 }53 }54 fmt.Println("End of the program")55 os.Exit(0)56}57import (58func main() {59 for {60 if i > 10 {61 }

Full Screen

Full Screen

EOF

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Enter a string: ")4 fmt.Scanln(&input)5 fmt.Println("You entered: ", input)6 fmt.Println("Enter a string: ")7 fmt.Scanln(&input)8 fmt.Println("You entered: ", input)9 fmt.Println("Enter a string: ")10 fmt.Scanln(&input)11 fmt.Println("You entered: ", input)12 fmt.Println("Enter a string: ")13 fmt.Scanln(&input)14 fmt.Println("You entered: ", input)15 fmt.Println("Enter a string: ")16 fmt.Scanln(&input)17 fmt.Println("You entered: ", input)18 fmt.Println("Enter a string: ")19 fmt.Scanln(&input)20 fmt.Println("You entered: ", input)21 fmt.Println("Enter a string: ")22 fmt.Scanln(&input)23 fmt.Println("You entered: ", input)24 fmt.Println("Enter a string: ")25 fmt.Scanln(&input)26 fmt.Println("You entered: ", input)27 fmt.Println("Enter a string: ")28 fmt.Scanln(&input)29 fmt.Println("You entered: ", input)30 fmt.Println("Enter a string: ")31 fmt.Scanln(&input)32 fmt.Println("You entered: ", input)33 fmt.Println("Enter a string: ")34 fmt.Scanln(&input)35 fmt.Println("You entered: ", input)36 for {37 fmt.Println("Enter a string:")38 n, err := fmt.Scanln(&input)39 if n == 0 || err != nil {40 fmt.Println("Exiting")41 os.Exit(1)42 }43 fmt.Println("You entered: ", input)44 }45}

Full Screen

Full Screen

EOF

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 for {4 fmt.Print("Enter text : ")5 reader := bufio.NewReader(os.Stdin)6 s, _ = reader.ReadString('\n')7 fmt.Println(s)8 }9}10import (11func main() {12 for {13 fmt.Print("Enter text : ")14 reader := bufio.NewReader(os.Stdin)15 s, _ = reader.ReadString('\n')16 fmt.Println(s)17 }18}19import (20func main() {21 for {22 fmt.Print("Enter text : ")23 reader := bufio.NewReader(os.Stdin)24 s, _ = reader.ReadString('\n')25 fmt.Println(s)26 }27}28import (29func main() {30 for {31 fmt.Print("Enter text : ")32 reader := bufio.NewReader(os.Stdin)33 s, _ = reader.ReadString('\n')34 fmt.Println(s)35 }36}37import (38func main() {39 for {40 fmt.Print("Enter text : ")41 reader := bufio.NewReader(os.Stdin)42 s, _ = reader.ReadString('\n')43 fmt.Println(s)44 }45}46import (47func main() {48 for {49 fmt.Print("Enter text : ")50 reader := bufio.NewReader(os.Stdin)51 s, _ = reader.ReadString('\n')52 fmt.Println(s)53 }54}55import (56func main() {57 for {58 fmt.Print("

Full Screen

Full Screen

EOF

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 fmt.Println(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)5 fmt.Println("Enter a number:")6 fmt.Scan(&num)7 if num == 1 {8 fmt.Println("Entered number is 1")9 } else {10 fmt.Println("Entered number is not 1")11 }12 fmt.Println("Enter a number:")13 fmt.Scan(&num1)14 if num1 == 1 {15 fmt.Println("Entered number is 1")16 } else {17 fmt.Println("Entered number is not 1")18 }19 fmt.Println("Enter a number:")20 fmt.Scan(&num2)21 if num2 == 1 {22 fmt.Println("Entered number is 1")23 } else {24 fmt.Println("Entered number is not 1")25 }26 fmt.Println("Enter a number:")27 fmt.Scan(&num3)28 if num3 == 1 {29 fmt.Println("Entered number is 1")30 } else {31 fmt.Println("Entered number is not 1")32 }33 fmt.Println("Enter a number:")34 fmt.Scan(&num4)35 if num4 == 1 {36 fmt.Println("Entered number is 1")37 } else {38 fmt.Println("Entered number is not 1")39 }40 fmt.Println("Enter a number:")41 fmt.Scan(&num5)42 if num5 == 1 {43 fmt.Println("Entered number

Full Screen

Full Screen

EOF

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "os"3func main() {4 fmt.Println("Enter the text to be entered")5 for {6 _, err := fmt.Scan(&s)7 if err == os.EOF {8 }9 fmt.Println(s)10 }11}12import "fmt"13import "os"14func main() {15 fmt.Println("Enter the text to be entered")16 for {17 _, err := fmt.Scan(&s)18 if err == os.EOF {19 }20 fmt.Println(s)21 }22}23import "fmt"24import "os"25func main() {26 fmt.Println("Enter the text to be entered")27 for {28 _, err := fmt.Scan(&s)29 if err == os.EOF {30 }31 fmt.Println(s)32 }33}34import "fmt"35import "os"36func main() {37 fmt.Println("Enter the text to be entered")38 for {39 _, err := fmt.Scan(&s)40 if err == os.EOF {41 }42 fmt.Println(s)43 }44}45import "fmt"46import "os"47func main() {48 fmt.Println("Enter the text to be entered")49 for {50 _, err := fmt.Scan(&s)51 if err == os.EOF {52 }53 fmt.Println(s)54 }55}56import "fmt"57import "os"58func main() {59 fmt.Println("Enter the text to be entered")60 for {61 _, err := fmt.Scan(&s)62 if err == os.EOF {63 }64 fmt.Println(s)65 }66}67import "fmt"68import "os"69func main() {70 fmt.Println("Enter the text to be entered

Full Screen

Full Screen

EOF

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 input := bufio.NewScanner(os.Stdin)4 for input.Scan() {5 fmt.Println(input.Text())6 }7}

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