How to use accept method of parser Package

Best Gauge code snippet using parser.accept

expression.go

Source:expression.go Github

copy

Full Screen

...50 return p.Expression()51}52func (p *EXPRESSION) Expression() bool {53 // Expression <- (Op / Grouping) EndOfFile54 accept := false55 accept = true56 start := p.ParserData.Pos()57 {58 save := p.ParserData.Pos()59 {60 save := p.ParserData.Pos()61 accept = p.Op()62 if !accept {63 accept = p.Grouping()64 if !accept {65 }66 }67 if !accept {68 p.ParserData.Seek(save)69 }70 }71 if accept {72 accept = p.EndOfFile()73 if accept {74 }75 }76 if !accept {77 if p.LastError < p.ParserData.Pos() {78 p.LastError = p.ParserData.Pos()79 }80 p.ParserData.Seek(save)81 }82 }83 if accept && start != p.ParserData.Pos() {84 if start < p.IgnoreRange.A || p.IgnoreRange.A == 0 {85 p.IgnoreRange.A = start86 }87 p.IgnoreRange.B = p.ParserData.Pos()88 }89 return accept90}91func (p *EXPRESSION) Op() bool {92 // Op <- ShiftRight / ShiftLeft / AndNot / Mask / Add / Sub / Mul / BooleanOp93 accept := false94 accept = true95 start := p.ParserData.Pos()96 {97 save := p.ParserData.Pos()98 accept = p.ShiftRight()99 if !accept {100 accept = p.ShiftLeft()101 if !accept {102 accept = p.AndNot()103 if !accept {104 accept = p.Mask()105 if !accept {106 accept = p.Add()107 if !accept {108 accept = p.Sub()109 if !accept {110 accept = p.Mul()111 if !accept {112 accept = p.BooleanOp()113 if !accept {114 }115 }116 }117 }118 }119 }120 }121 }122 if !accept {123 p.ParserData.Seek(save)124 }125 }126 if accept && start != p.ParserData.Pos() {127 if start < p.IgnoreRange.A || p.IgnoreRange.A == 0 {128 p.IgnoreRange.A = start129 }130 p.IgnoreRange.B = p.ParserData.Pos()131 }132 return accept133}134func (p *EXPRESSION) BooleanOp() bool {135 // BooleanOp <- Eq / Lt / Gt / Le / Ge / Ne136 accept := false137 accept = true138 start := p.ParserData.Pos()139 {140 save := p.ParserData.Pos()141 accept = p.Eq()142 if !accept {143 accept = p.Lt()144 if !accept {145 accept = p.Gt()146 if !accept {147 accept = p.Le()148 if !accept {149 accept = p.Ge()150 if !accept {151 accept = p.Ne()152 if !accept {153 }154 }155 }156 }157 }158 }159 if !accept {160 p.ParserData.Seek(save)161 }162 }163 if accept && start != p.ParserData.Pos() {164 if start < p.IgnoreRange.A || p.IgnoreRange.A == 0 {165 p.IgnoreRange.A = start166 }167 p.IgnoreRange.B = p.ParserData.Pos()168 }169 return accept170}171func (p *EXPRESSION) ShiftRight() bool {172 // ShiftRight <- Grouping ">>" Grouping173 accept := false174 accept = true175 start := p.ParserData.Pos()176 {177 save := p.ParserData.Pos()178 accept = p.Grouping()179 if accept {180 {181 accept = true182 s := p.ParserData.Pos()183 if p.ParserData.Read() != '>' || p.ParserData.Read() != '>' {184 p.ParserData.Seek(s)185 accept = false186 }187 }188 if accept {189 accept = p.Grouping()190 if accept {191 }192 }193 }194 if !accept {195 if p.LastError < p.ParserData.Pos() {196 p.LastError = p.ParserData.Pos()197 }198 p.ParserData.Seek(save)199 }200 }201 end := p.ParserData.Pos()202 if accept {203 node := p.Root.Cleanup(start, end)204 node.Name = "ShiftRight"205 node.P = p206 node.Range = node.Range.Clip(p.IgnoreRange)207 p.Root.Append(node)208 } else {209 p.Root.Discard(start)210 }211 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {212 p.IgnoreRange = text.Region{}213 }214 return accept215}216func (p *EXPRESSION) ShiftLeft() bool {217 // ShiftLeft <- Grouping "<<" Grouping218 accept := false219 accept = true220 start := p.ParserData.Pos()221 {222 save := p.ParserData.Pos()223 accept = p.Grouping()224 if accept {225 {226 accept = true227 s := p.ParserData.Pos()228 if p.ParserData.Read() != '<' || p.ParserData.Read() != '<' {229 p.ParserData.Seek(s)230 accept = false231 }232 }233 if accept {234 accept = p.Grouping()235 if accept {236 }237 }238 }239 if !accept {240 if p.LastError < p.ParserData.Pos() {241 p.LastError = p.ParserData.Pos()242 }243 p.ParserData.Seek(save)244 }245 }246 end := p.ParserData.Pos()247 if accept {248 node := p.Root.Cleanup(start, end)249 node.Name = "ShiftLeft"250 node.P = p251 node.Range = node.Range.Clip(p.IgnoreRange)252 p.Root.Append(node)253 } else {254 p.Root.Discard(start)255 }256 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {257 p.IgnoreRange = text.Region{}258 }259 return accept260}261func (p *EXPRESSION) Mask() bool {262 // Mask <- Grouping '&' Grouping263 accept := false264 accept = true265 start := p.ParserData.Pos()266 {267 save := p.ParserData.Pos()268 accept = p.Grouping()269 if accept {270 if p.ParserData.Read() != '&' {271 p.ParserData.UnRead()272 accept = false273 } else {274 accept = true275 }276 if accept {277 accept = p.Grouping()278 if accept {279 }280 }281 }282 if !accept {283 if p.LastError < p.ParserData.Pos() {284 p.LastError = p.ParserData.Pos()285 }286 p.ParserData.Seek(save)287 }288 }289 end := p.ParserData.Pos()290 if accept {291 node := p.Root.Cleanup(start, end)292 node.Name = "Mask"293 node.P = p294 node.Range = node.Range.Clip(p.IgnoreRange)295 p.Root.Append(node)296 } else {297 p.Root.Discard(start)298 }299 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {300 p.IgnoreRange = text.Region{}301 }302 return accept303}304func (p *EXPRESSION) Add() bool {305 // Add <- Grouping '+' Grouping306 accept := false307 accept = true308 start := p.ParserData.Pos()309 {310 save := p.ParserData.Pos()311 accept = p.Grouping()312 if accept {313 if p.ParserData.Read() != '+' {314 p.ParserData.UnRead()315 accept = false316 } else {317 accept = true318 }319 if accept {320 accept = p.Grouping()321 if accept {322 }323 }324 }325 if !accept {326 if p.LastError < p.ParserData.Pos() {327 p.LastError = p.ParserData.Pos()328 }329 p.ParserData.Seek(save)330 }331 }332 end := p.ParserData.Pos()333 if accept {334 node := p.Root.Cleanup(start, end)335 node.Name = "Add"336 node.P = p337 node.Range = node.Range.Clip(p.IgnoreRange)338 p.Root.Append(node)339 } else {340 p.Root.Discard(start)341 }342 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {343 p.IgnoreRange = text.Region{}344 }345 return accept346}347func (p *EXPRESSION) Sub() bool {348 // Sub <- Grouping '-' Grouping349 accept := false350 accept = true351 start := p.ParserData.Pos()352 {353 save := p.ParserData.Pos()354 accept = p.Grouping()355 if accept {356 if p.ParserData.Read() != '-' {357 p.ParserData.UnRead()358 accept = false359 } else {360 accept = true361 }362 if accept {363 accept = p.Grouping()364 if accept {365 }366 }367 }368 if !accept {369 if p.LastError < p.ParserData.Pos() {370 p.LastError = p.ParserData.Pos()371 }372 p.ParserData.Seek(save)373 }374 }375 end := p.ParserData.Pos()376 if accept {377 node := p.Root.Cleanup(start, end)378 node.Name = "Sub"379 node.P = p380 node.Range = node.Range.Clip(p.IgnoreRange)381 p.Root.Append(node)382 } else {383 p.Root.Discard(start)384 }385 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {386 p.IgnoreRange = text.Region{}387 }388 return accept389}390func (p *EXPRESSION) Mul() bool {391 // Mul <- Grouping '*' Grouping392 accept := false393 accept = true394 start := p.ParserData.Pos()395 {396 save := p.ParserData.Pos()397 accept = p.Grouping()398 if accept {399 if p.ParserData.Read() != '*' {400 p.ParserData.UnRead()401 accept = false402 } else {403 accept = true404 }405 if accept {406 accept = p.Grouping()407 if accept {408 }409 }410 }411 if !accept {412 if p.LastError < p.ParserData.Pos() {413 p.LastError = p.ParserData.Pos()414 }415 p.ParserData.Seek(save)416 }417 }418 end := p.ParserData.Pos()419 if accept {420 node := p.Root.Cleanup(start, end)421 node.Name = "Mul"422 node.P = p423 node.Range = node.Range.Clip(p.IgnoreRange)424 p.Root.Append(node)425 } else {426 p.Root.Discard(start)427 }428 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {429 p.IgnoreRange = text.Region{}430 }431 return accept432}433func (p *EXPRESSION) AndNot() bool {434 // AndNot <- Grouping "&^" Grouping435 accept := false436 accept = true437 start := p.ParserData.Pos()438 {439 save := p.ParserData.Pos()440 accept = p.Grouping()441 if accept {442 {443 accept = true444 s := p.ParserData.Pos()445 if p.ParserData.Read() != '&' || p.ParserData.Read() != '^' {446 p.ParserData.Seek(s)447 accept = false448 }449 }450 if accept {451 accept = p.Grouping()452 if accept {453 }454 }455 }456 if !accept {457 if p.LastError < p.ParserData.Pos() {458 p.LastError = p.ParserData.Pos()459 }460 p.ParserData.Seek(save)461 }462 }463 end := p.ParserData.Pos()464 if accept {465 node := p.Root.Cleanup(start, end)466 node.Name = "AndNot"467 node.P = p468 node.Range = node.Range.Clip(p.IgnoreRange)469 p.Root.Append(node)470 } else {471 p.Root.Discard(start)472 }473 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {474 p.IgnoreRange = text.Region{}475 }476 return accept477}478func (p *EXPRESSION) Eq() bool {479 // Eq <- Grouping "==" Grouping480 accept := false481 accept = true482 start := p.ParserData.Pos()483 {484 save := p.ParserData.Pos()485 accept = p.Grouping()486 if accept {487 {488 accept = true489 s := p.ParserData.Pos()490 if p.ParserData.Read() != '=' || p.ParserData.Read() != '=' {491 p.ParserData.Seek(s)492 accept = false493 }494 }495 if accept {496 accept = p.Grouping()497 if accept {498 }499 }500 }501 if !accept {502 if p.LastError < p.ParserData.Pos() {503 p.LastError = p.ParserData.Pos()504 }505 p.ParserData.Seek(save)506 }507 }508 end := p.ParserData.Pos()509 if accept {510 node := p.Root.Cleanup(start, end)511 node.Name = "Eq"512 node.P = p513 node.Range = node.Range.Clip(p.IgnoreRange)514 p.Root.Append(node)515 } else {516 p.Root.Discard(start)517 }518 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {519 p.IgnoreRange = text.Region{}520 }521 return accept522}523func (p *EXPRESSION) Ne() bool {524 // Ne <- Grouping "!=" Grouping525 accept := false526 accept = true527 start := p.ParserData.Pos()528 {529 save := p.ParserData.Pos()530 accept = p.Grouping()531 if accept {532 {533 accept = true534 s := p.ParserData.Pos()535 if p.ParserData.Read() != '!' || p.ParserData.Read() != '=' {536 p.ParserData.Seek(s)537 accept = false538 }539 }540 if accept {541 accept = p.Grouping()542 if accept {543 }544 }545 }546 if !accept {547 if p.LastError < p.ParserData.Pos() {548 p.LastError = p.ParserData.Pos()549 }550 p.ParserData.Seek(save)551 }552 }553 end := p.ParserData.Pos()554 if accept {555 node := p.Root.Cleanup(start, end)556 node.Name = "Ne"557 node.P = p558 node.Range = node.Range.Clip(p.IgnoreRange)559 p.Root.Append(node)560 } else {561 p.Root.Discard(start)562 }563 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {564 p.IgnoreRange = text.Region{}565 }566 return accept567}568func (p *EXPRESSION) Lt() bool {569 // Lt <- Grouping '<' Grouping570 accept := false571 accept = true572 start := p.ParserData.Pos()573 {574 save := p.ParserData.Pos()575 accept = p.Grouping()576 if accept {577 if p.ParserData.Read() != '<' {578 p.ParserData.UnRead()579 accept = false580 } else {581 accept = true582 }583 if accept {584 accept = p.Grouping()585 if accept {586 }587 }588 }589 if !accept {590 if p.LastError < p.ParserData.Pos() {591 p.LastError = p.ParserData.Pos()592 }593 p.ParserData.Seek(save)594 }595 }596 end := p.ParserData.Pos()597 if accept {598 node := p.Root.Cleanup(start, end)599 node.Name = "Lt"600 node.P = p601 node.Range = node.Range.Clip(p.IgnoreRange)602 p.Root.Append(node)603 } else {604 p.Root.Discard(start)605 }606 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {607 p.IgnoreRange = text.Region{}608 }609 return accept610}611func (p *EXPRESSION) Le() bool {612 // Le <- Grouping "<=" Grouping613 accept := false614 accept = true615 start := p.ParserData.Pos()616 {617 save := p.ParserData.Pos()618 accept = p.Grouping()619 if accept {620 {621 accept = true622 s := p.ParserData.Pos()623 if p.ParserData.Read() != '<' || p.ParserData.Read() != '=' {624 p.ParserData.Seek(s)625 accept = false626 }627 }628 if accept {629 accept = p.Grouping()630 if accept {631 }632 }633 }634 if !accept {635 if p.LastError < p.ParserData.Pos() {636 p.LastError = p.ParserData.Pos()637 }638 p.ParserData.Seek(save)639 }640 }641 end := p.ParserData.Pos()642 if accept {643 node := p.Root.Cleanup(start, end)644 node.Name = "Le"645 node.P = p646 node.Range = node.Range.Clip(p.IgnoreRange)647 p.Root.Append(node)648 } else {649 p.Root.Discard(start)650 }651 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {652 p.IgnoreRange = text.Region{}653 }654 return accept655}656func (p *EXPRESSION) Gt() bool {657 // Gt <- Grouping '>' Grouping658 accept := false659 accept = true660 start := p.ParserData.Pos()661 {662 save := p.ParserData.Pos()663 accept = p.Grouping()664 if accept {665 if p.ParserData.Read() != '>' {666 p.ParserData.UnRead()667 accept = false668 } else {669 accept = true670 }671 if accept {672 accept = p.Grouping()673 if accept {674 }675 }676 }677 if !accept {678 if p.LastError < p.ParserData.Pos() {679 p.LastError = p.ParserData.Pos()680 }681 p.ParserData.Seek(save)682 }683 }684 end := p.ParserData.Pos()685 if accept {686 node := p.Root.Cleanup(start, end)687 node.Name = "Gt"688 node.P = p689 node.Range = node.Range.Clip(p.IgnoreRange)690 p.Root.Append(node)691 } else {692 p.Root.Discard(start)693 }694 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {695 p.IgnoreRange = text.Region{}696 }697 return accept698}699func (p *EXPRESSION) Ge() bool {700 // Ge <- Grouping ">=" Grouping701 accept := false702 accept = true703 start := p.ParserData.Pos()704 {705 save := p.ParserData.Pos()706 accept = p.Grouping()707 if accept {708 {709 accept = true710 s := p.ParserData.Pos()711 if p.ParserData.Read() != '>' || p.ParserData.Read() != '=' {712 p.ParserData.Seek(s)713 accept = false714 }715 }716 if accept {717 accept = p.Grouping()718 if accept {719 }720 }721 }722 if !accept {723 if p.LastError < p.ParserData.Pos() {724 p.LastError = p.ParserData.Pos()725 }726 p.ParserData.Seek(save)727 }728 }729 end := p.ParserData.Pos()730 if accept {731 node := p.Root.Cleanup(start, end)732 node.Name = "Ge"733 node.P = p734 node.Range = node.Range.Clip(p.IgnoreRange)735 p.Root.Append(node)736 } else {737 p.Root.Discard(start)738 }739 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {740 p.IgnoreRange = text.Region{}741 }742 return accept743}744func (p *EXPRESSION) Grouping() bool {745 // Grouping <- Spacing? ('(' Op ')' / Constant / DotIdentifier) Spacing?746 accept := false747 accept = true748 start := p.ParserData.Pos()749 {750 save := p.ParserData.Pos()751 accept = p.Spacing()752 accept = true753 if accept {754 {755 save := p.ParserData.Pos()756 {757 save := p.ParserData.Pos()758 if p.ParserData.Read() != '(' {759 p.ParserData.UnRead()760 accept = false761 } else {762 accept = true763 }764 if accept {765 accept = p.Op()766 if accept {767 if p.ParserData.Read() != ')' {768 p.ParserData.UnRead()769 accept = false770 } else {771 accept = true772 }773 if accept {774 }775 }776 }777 if !accept {778 if p.LastError < p.ParserData.Pos() {779 p.LastError = p.ParserData.Pos()780 }781 p.ParserData.Seek(save)782 }783 }784 if !accept {785 accept = p.Constant()786 if !accept {787 accept = p.DotIdentifier()788 if !accept {789 }790 }791 }792 if !accept {793 p.ParserData.Seek(save)794 }795 }796 if accept {797 accept = p.Spacing()798 accept = true799 if accept {800 }801 }802 }803 if !accept {804 if p.LastError < p.ParserData.Pos() {805 p.LastError = p.ParserData.Pos()806 }807 p.ParserData.Seek(save)808 }809 }810 if accept && start != p.ParserData.Pos() {811 if start < p.IgnoreRange.A || p.IgnoreRange.A == 0 {812 p.IgnoreRange.A = start813 }814 p.IgnoreRange.B = p.ParserData.Pos()815 }816 return accept817}818func (p *EXPRESSION) DotIdentifier() bool {819 // DotIdentifier <- Identifier ('.' Identifier)*820 accept := false821 accept = true822 start := p.ParserData.Pos()823 {824 save := p.ParserData.Pos()825 accept = p.Identifier()826 if accept {827 {828 accept = true829 for accept {830 {831 save := p.ParserData.Pos()832 if p.ParserData.Read() != '.' {833 p.ParserData.UnRead()834 accept = false835 } else {836 accept = true837 }838 if accept {839 accept = p.Identifier()840 if accept {841 }842 }843 if !accept {844 if p.LastError < p.ParserData.Pos() {845 p.LastError = p.ParserData.Pos()846 }847 p.ParserData.Seek(save)848 }849 }850 }851 accept = true852 }853 if accept {854 }855 }856 if !accept {857 if p.LastError < p.ParserData.Pos() {858 p.LastError = p.ParserData.Pos()859 }860 p.ParserData.Seek(save)861 }862 }863 end := p.ParserData.Pos()864 if accept {865 node := p.Root.Cleanup(start, end)866 node.Name = "DotIdentifier"867 node.P = p868 node.Range = node.Range.Clip(p.IgnoreRange)869 p.Root.Append(node)870 } else {871 p.Root.Discard(start)872 }873 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {874 p.IgnoreRange = text.Region{}875 }876 return accept877}878func (p *EXPRESSION) Identifier() bool {879 // Identifier <- [A-Z] [_A-Za-z0-9]*880 accept := false881 accept = true882 start := p.ParserData.Pos()883 {884 save := p.ParserData.Pos()885 c := p.ParserData.Read()886 if c >= 'A' && c <= 'Z' {887 accept = true888 } else {889 p.ParserData.UnRead()890 accept = false891 }892 if accept {893 {894 accept = true895 for accept {896 {897 save := p.ParserData.Pos()898 c := p.ParserData.Read()899 if c >= 'A' && c <= 'Z' {900 accept = true901 } else {902 p.ParserData.UnRead()903 accept = false904 }905 if !accept {906 c := p.ParserData.Read()907 if c >= 'a' && c <= 'z' {908 accept = true909 } else {910 p.ParserData.UnRead()911 accept = false912 }913 if !accept {914 c := p.ParserData.Read()915 if c >= '0' && c <= '9' {916 accept = true917 } else {918 p.ParserData.UnRead()919 accept = false920 }921 if !accept {922 {923 accept = false924 c := p.ParserData.Read()925 if c == '_' {926 accept = true927 } else {928 p.ParserData.UnRead()929 }930 }931 if !accept {932 }933 }934 }935 }936 if !accept {937 p.ParserData.Seek(save)938 }939 }940 }941 accept = true942 }943 if accept {944 }945 }946 if !accept {947 if p.LastError < p.ParserData.Pos() {948 p.LastError = p.ParserData.Pos()949 }950 p.ParserData.Seek(save)951 }952 }953 end := p.ParserData.Pos()954 if accept {955 node := p.Root.Cleanup(start, end)956 node.Name = "Identifier"957 node.P = p958 node.Range = node.Range.Clip(p.IgnoreRange)959 p.Root.Append(node)960 } else {961 p.Root.Discard(start)962 }963 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {964 p.IgnoreRange = text.Region{}965 }966 return accept967}968func (p *EXPRESSION) Constant() bool {969 // Constant <- ("0x" [a-fA-F0-9]+) / [0-9]+970 accept := false971 accept = true972 start := p.ParserData.Pos()973 {974 save := p.ParserData.Pos()975 {976 save := p.ParserData.Pos()977 {978 accept = true979 s := p.ParserData.Pos()980 if p.ParserData.Read() != '0' || p.ParserData.Read() != 'x' {981 p.ParserData.Seek(s)982 accept = false983 }984 }985 if accept {986 {987 save := p.ParserData.Pos()988 {989 save := p.ParserData.Pos()990 c := p.ParserData.Read()991 if c >= 'a' && c <= 'f' {992 accept = true993 } else {994 p.ParserData.UnRead()995 accept = false996 }997 if !accept {998 c := p.ParserData.Read()999 if c >= 'A' && c <= 'F' {1000 accept = true1001 } else {1002 p.ParserData.UnRead()1003 accept = false1004 }1005 if !accept {1006 c := p.ParserData.Read()1007 if c >= '0' && c <= '9' {1008 accept = true1009 } else {1010 p.ParserData.UnRead()1011 accept = false1012 }1013 if !accept {1014 }1015 }1016 }1017 if !accept {1018 p.ParserData.Seek(save)1019 }1020 }1021 if !accept {1022 p.ParserData.Seek(save)1023 } else {1024 for accept {1025 {1026 save := p.ParserData.Pos()1027 c := p.ParserData.Read()1028 if c >= 'a' && c <= 'f' {1029 accept = true1030 } else {1031 p.ParserData.UnRead()1032 accept = false1033 }1034 if !accept {1035 c := p.ParserData.Read()1036 if c >= 'A' && c <= 'F' {1037 accept = true1038 } else {1039 p.ParserData.UnRead()1040 accept = false1041 }1042 if !accept {1043 c := p.ParserData.Read()1044 if c >= '0' && c <= '9' {1045 accept = true1046 } else {1047 p.ParserData.UnRead()1048 accept = false1049 }1050 if !accept {1051 }1052 }1053 }1054 if !accept {1055 p.ParserData.Seek(save)1056 }1057 }1058 }1059 accept = true1060 }1061 }1062 if accept {1063 }1064 }1065 if !accept {1066 if p.LastError < p.ParserData.Pos() {1067 p.LastError = p.ParserData.Pos()1068 }1069 p.ParserData.Seek(save)1070 }1071 }1072 if !accept {1073 {1074 save := p.ParserData.Pos()1075 c := p.ParserData.Read()1076 if c >= '0' && c <= '9' {1077 accept = true1078 } else {1079 p.ParserData.UnRead()1080 accept = false1081 }1082 if !accept {1083 p.ParserData.Seek(save)1084 } else {1085 for accept {1086 c := p.ParserData.Read()1087 if c >= '0' && c <= '9' {1088 accept = true1089 } else {1090 p.ParserData.UnRead()1091 accept = false1092 }1093 }1094 accept = true1095 }1096 }1097 if !accept {1098 }1099 }1100 if !accept {1101 p.ParserData.Seek(save)1102 }1103 }1104 end := p.ParserData.Pos()1105 if accept {1106 node := p.Root.Cleanup(start, end)1107 node.Name = "Constant"1108 node.P = p1109 node.Range = node.Range.Clip(p.IgnoreRange)1110 p.Root.Append(node)1111 } else {1112 p.Root.Discard(start)1113 }1114 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {1115 p.IgnoreRange = text.Region{}1116 }1117 return accept1118}1119func (p *EXPRESSION) Spacing() bool {1120 // Spacing <- [ \t\n\r]+1121 accept := false1122 accept = true1123 start := p.ParserData.Pos()1124 {1125 save := p.ParserData.Pos()1126 {1127 accept = false1128 c := p.ParserData.Read()1129 if c == ' ' || c == '\t' || c == '\n' || c == '\r' {1130 accept = true1131 } else {1132 p.ParserData.UnRead()1133 }1134 }1135 if !accept {1136 p.ParserData.Seek(save)1137 } else {1138 for accept {1139 {1140 accept = false1141 c := p.ParserData.Read()1142 if c == ' ' || c == '\t' || c == '\n' || c == '\r' {1143 accept = true1144 } else {1145 p.ParserData.UnRead()1146 }1147 }1148 }1149 accept = true1150 }1151 }1152 if accept && start != p.ParserData.Pos() {1153 if start < p.IgnoreRange.A || p.IgnoreRange.A == 0 {1154 p.IgnoreRange.A = start1155 }1156 p.IgnoreRange.B = p.ParserData.Pos()1157 }1158 return accept1159}1160func (p *EXPRESSION) EndOfFile() bool {1161 // EndOfFile <- !.1162 accept := false1163 accept = true1164 start := p.ParserData.Pos()1165 s := p.ParserData.Pos()1166 if p.ParserData.Pos() >= p.ParserData.Len() {1167 accept = false1168 } else {1169 p.ParserData.Read()1170 accept = true1171 }1172 p.ParserData.Seek(s)1173 p.Root.Discard(s)1174 accept = !accept1175 end := p.ParserData.Pos()1176 if accept {1177 node := p.Root.Cleanup(start, end)1178 node.Name = "EndOfFile"1179 node.P = p1180 node.Range = node.Range.Clip(p.IgnoreRange)1181 p.Root.Append(node)1182 } else {1183 p.Root.Discard(start)1184 }1185 if p.IgnoreRange.A >= end || p.IgnoreRange.B <= start {1186 p.IgnoreRange = text.Region{}1187 }1188 return accept1189}...

Full Screen

Full Screen

parser.go

Source:parser.go Github

copy

Full Screen

...24 panic(r)25 }26 }()27 p.parseLines()28 p.accept(scanner.EOF)29 p.nodes = append(p.nodes, p.comments...)30 sort.Sort(byPosition(p.nodes))31 return p.nodes, p.errors32}33type parser struct {34 scanner scanner.Scanner35 tok rune36 errors []error37 comments []Node38 nodes []Node39 lines []int40}41func NewParser(filename string, r io.Reader) *parser {42 p := &parser{}43 p.lines = []int{0}44 p.scanner.Init(r)45 p.scanner.Error = func(sc *scanner.Scanner, msg string) {46 p.errorf(msg)47 }48 p.scanner.Whitespace = 049 p.scanner.IsIdentRune = func(ch rune, i int) bool {50 return ch > 0 && ch != ':' && ch != '#' && ch != '=' && ch != '+' && ch != '$' &&51 ch != '\\' && ch != '(' && ch != ')' && ch != '{' && ch != '}' && ch != ';' &&52 ch != '|' && ch != '?' && ch != '\r' && !isWhitespace(ch)53 }54 p.scanner.Mode = scanner.ScanIdents55 p.scanner.Filename = filename56 p.next()57 return p58}59func (p *parser) Unpack(pos Pos) scanner.Position {60 offset := int(pos)61 line := sort.Search(len(p.lines), func(i int) bool { return p.lines[i] > offset }) - 162 return scanner.Position{63 Filename: p.scanner.Filename,64 Line: line + 1,65 Column: offset - p.lines[line] + 1,66 Offset: offset,67 }68}69func (p *parser) pos() Pos {70 pos := p.scanner.Position71 if !pos.IsValid() {72 pos = p.scanner.Pos()73 }74 return Pos(pos.Offset)75}76func (p *parser) errorf(format string, args ...interface{}) {77 err := &ParseError{78 Err: fmt.Errorf(format, args...),79 Pos: p.scanner.Position,80 }81 p.errors = append(p.errors, err)82 if len(p.errors) >= maxErrors {83 panic(errTooManyErrors)84 }85}86func (p *parser) accept(toks ...rune) bool {87 for _, tok := range toks {88 if p.tok != tok {89 p.errorf("expected %s, found %s", scanner.TokenString(tok),90 scanner.TokenString(p.tok))91 return false92 }93 p.next()94 }95 return true96}97func (p *parser) next() {98 if p.tok != scanner.EOF {99 p.tok = p.scanner.Scan()100 for p.tok == '\r' {101 p.tok = p.scanner.Scan()102 }103 }104 if p.tok == '\n' {105 p.lines = append(p.lines, p.scanner.Position.Offset+1)106 }107}108func (p *parser) parseLines() {109 for {110 p.ignoreWhitespace()111 if p.parseDirective() {112 continue113 }114 ident := p.parseExpression('=', '?', ':', '#', '\n')115 p.ignoreSpaces()116 switch p.tok {117 case '?':118 p.accept('?')119 if p.tok == '=' {120 p.parseAssignment("?=", nil, ident)121 } else {122 p.errorf("expected = after ?")123 }124 case '+':125 p.accept('+')126 if p.tok == '=' {127 p.parseAssignment("+=", nil, ident)128 } else {129 p.errorf("expected = after +")130 }131 case ':':132 p.accept(':')133 switch p.tok {134 case '=':135 p.parseAssignment(":=", nil, ident)136 default:137 p.parseRule(ident)138 }139 case '=':140 p.parseAssignment("=", nil, ident)141 case '#', '\n', scanner.EOF:142 ident.TrimRightSpaces()143 if v, ok := toVariable(ident); ok {144 p.nodes = append(p.nodes, &v)145 } else if !ident.Empty() {146 p.errorf("expected directive, rule, or assignment after ident " + ident.Dump())147 }148 switch p.tok {149 case scanner.EOF:150 return151 case '\n':152 p.accept('\n')153 case '#':154 p.parseComment()155 }156 default:157 p.errorf("expected assignment or rule definition, found %s\n",158 p.scanner.TokenText())159 return160 }161 }162}163func (p *parser) parseDirective() bool {164 if p.tok != scanner.Ident || !isDirective(p.scanner.TokenText()) {165 return false166 }167 d := p.scanner.TokenText()168 pos := p.pos()169 p.accept(scanner.Ident)170 endPos := NoPos171 expression := SimpleMakeString("", pos)172 switch d {173 case "endif", "endef", "else":174 // Nothing175 case "define":176 expression, endPos = p.parseDefine()177 default:178 p.ignoreSpaces()179 expression = p.parseExpression()180 }181 p.nodes = append(p.nodes, &Directive{182 NamePos: pos,183 Name: d,184 Args: expression,185 EndPos: endPos,186 })187 return true188}189func (p *parser) parseDefine() (*MakeString, Pos) {190 value := SimpleMakeString("", p.pos())191loop:192 for {193 switch p.tok {194 case scanner.Ident:195 value.appendString(p.scanner.TokenText())196 if p.scanner.TokenText() == "endef" {197 p.accept(scanner.Ident)198 break loop199 }200 p.accept(scanner.Ident)201 case '\\':202 p.parseEscape()203 switch p.tok {204 case '\n':205 value.appendString(" ")206 case scanner.EOF:207 p.errorf("expected escaped character, found %s",208 scanner.TokenString(p.tok))209 break loop210 default:211 value.appendString(`\` + string(p.tok))212 }213 p.accept(p.tok)214 //TODO: handle variables inside defines? result depends if215 //define is used in make or rule context216 //case '$':217 // variable := p.parseVariable()218 // value.appendVariable(variable)219 case scanner.EOF:220 p.errorf("unexpected EOF while looking for endef")221 break loop222 default:223 value.appendString(p.scanner.TokenText())224 p.accept(p.tok)225 }226 }227 return value, p.pos()228}229func (p *parser) parseEscape() {230 p.scanner.Mode = 0231 p.accept('\\')232 p.scanner.Mode = scanner.ScanIdents233}234func (p *parser) parseExpression(end ...rune) *MakeString {235 value := SimpleMakeString("", p.pos())236 endParen := false237 for _, r := range end {238 if r == ')' {239 endParen = true240 }241 }242 parens := 0243loop:244 for {245 if endParen && parens > 0 && p.tok == ')' {246 parens--247 value.appendString(")")248 p.accept(')')249 continue250 }251 for _, r := range end {252 if p.tok == r {253 break loop254 }255 }256 switch p.tok {257 case '\n':258 break loop259 case scanner.Ident:260 value.appendString(p.scanner.TokenText())261 p.accept(scanner.Ident)262 case '\\':263 p.parseEscape()264 switch p.tok {265 case '\n':266 value.appendString(" ")267 case scanner.EOF:268 p.errorf("expected escaped character, found %s",269 scanner.TokenString(p.tok))270 return value271 default:272 value.appendString(`\` + string(p.tok))273 }274 p.accept(p.tok)275 case '#':276 p.parseComment()277 break loop278 case '$':279 var variable Variable280 variable = p.parseVariable()281 value.appendVariable(variable)282 case scanner.EOF:283 break loop284 case '(':285 if endParen {286 parens++287 }288 value.appendString("(")289 p.accept('(')290 default:291 value.appendString(p.scanner.TokenText())292 p.accept(p.tok)293 }294 }295 if parens > 0 {296 p.errorf("expected closing paren %s", value.Dump())297 }298 return value299}300func (p *parser) parseVariable() Variable {301 pos := p.pos()302 p.accept('$')303 var name *MakeString304 switch p.tok {305 case '(':306 return p.parseBracketedVariable('(', ')', pos)307 case '{':308 return p.parseBracketedVariable('{', '}', pos)309 case '$':310 name = SimpleMakeString("__builtin_dollar", NoPos)311 case scanner.EOF:312 p.errorf("expected variable name, found %s",313 scanner.TokenString(p.tok))314 default:315 name = p.parseExpression(variableNameEndRunes...)316 }317 return p.nameToVariable(name)318}319func (p *parser) parseBracketedVariable(start, end rune, pos Pos) Variable {320 p.accept(start)321 name := p.parseExpression(end)322 p.accept(end)323 return p.nameToVariable(name)324}325func (p *parser) nameToVariable(name *MakeString) Variable {326 return Variable{327 Name: name,328 }329}330func (p *parser) parseRule(target *MakeString) {331 prerequisites, newLine := p.parseRulePrerequisites(target)332 recipe := ""333 recipePos := p.pos()334loop:335 for {336 if newLine {337 if p.tok == '\t' {338 p.accept('\t')339 newLine = false340 continue loop341 } else if p.parseDirective() {342 newLine = false343 continue344 } else {345 break loop346 }347 }348 newLine = false349 switch p.tok {350 case '\\':351 p.parseEscape()352 recipe += string(p.tok)353 p.accept(p.tok)354 case '\n':355 newLine = true356 recipe += "\n"357 p.accept('\n')358 case scanner.EOF:359 break loop360 default:361 recipe += p.scanner.TokenText()362 p.accept(p.tok)363 }364 }365 if prerequisites != nil {366 p.nodes = append(p.nodes, &Rule{367 Target: target,368 Prerequisites: prerequisites,369 Recipe: recipe,370 RecipePos: recipePos,371 })372 }373}374func (p *parser) parseRulePrerequisites(target *MakeString) (*MakeString, bool) {375 newLine := false376 p.ignoreSpaces()377 prerequisites := p.parseExpression('#', '\n', ';', ':', '=')378 switch p.tok {379 case '\n':380 p.accept('\n')381 newLine = true382 case '#':383 p.parseComment()384 newLine = true385 case ';':386 p.accept(';')387 case ':':388 p.accept(':')389 if p.tok == '=' {390 p.parseAssignment(":=", target, prerequisites)391 return nil, true392 } else {393 more := p.parseExpression('#', '\n', ';')394 prerequisites.appendMakeString(more)395 }396 case '=':397 p.parseAssignment("=", target, prerequisites)398 return nil, true399 default:400 p.errorf("unexpected token %s after rule prerequisites", scanner.TokenString(p.tok))401 }402 return prerequisites, newLine403}404func (p *parser) parseComment() {405 pos := p.pos()406 p.accept('#')407 comment := ""408loop:409 for {410 switch p.tok {411 case '\\':412 p.parseEscape()413 if p.tok == '\n' {414 comment += "\n"415 } else {416 comment += "\\" + p.scanner.TokenText()417 }418 p.accept(p.tok)419 case '\n':420 p.accept('\n')421 break loop422 case scanner.EOF:423 break loop424 default:425 comment += p.scanner.TokenText()426 p.accept(p.tok)427 }428 }429 p.comments = append(p.comments, &Comment{430 CommentPos: pos,431 Comment: comment,432 })433}434func (p *parser) parseAssignment(t string, target *MakeString, ident *MakeString) {435 // The value of an assignment is everything including and after the first436 // non-whitespace character after the = until the end of the logical line,437 // which may included escaped newlines438 p.accept('=')439 value := p.parseExpression()440 value.TrimLeftSpaces()441 if ident.EndsWith('+') && t == "=" {442 ident.TrimRightOne()443 t = "+="444 }445 ident.TrimRightSpaces()446 p.nodes = append(p.nodes, &Assignment{447 Name: ident,448 Value: value,449 Target: target,450 Type: t,451 })452}453type androidMkModule struct {454 assignments map[string]string455}456type androidMkFile struct {457 assignments map[string]string458 modules []androidMkModule459 includes []string460}461var directives = [...]string{462 "define",463 "else",464 "endef",465 "endif",466 "ifdef",467 "ifeq",468 "ifndef",469 "ifneq",470 "include",471 "-include",472}473var functions = [...]string{474 "abspath",475 "addprefix",476 "addsuffix",477 "basename",478 "dir",479 "notdir",480 "subst",481 "suffix",482 "filter",483 "filter-out",484 "findstring",485 "firstword",486 "flavor",487 "join",488 "lastword",489 "patsubst",490 "realpath",491 "shell",492 "sort",493 "strip",494 "wildcard",495 "word",496 "wordlist",497 "words",498 "origin",499 "foreach",500 "call",501 "info",502 "error",503 "warning",504 "if",505 "or",506 "and",507 "value",508 "eval",509 "file",510}511func init() {512 sort.Strings(directives[:])513 sort.Strings(functions[:])514}515func isDirective(s string) bool {516 for _, d := range directives {517 if s == d {518 return true519 } else if s < d {520 return false521 }522 }523 return false524}525func isFunctionName(s string) bool {526 for _, f := range functions {527 if s == f {528 return true529 } else if s < f {530 return false531 }532 }533 return false534}535func isWhitespace(ch rune) bool {536 return ch == ' ' || ch == '\t' || ch == '\n'537}538func isValidVariableRune(ch rune) bool {539 return ch != scanner.Ident && ch != ':' && ch != '=' && ch != '#'540}541var whitespaceRunes = []rune{' ', '\t', '\n'}542var variableNameEndRunes = append([]rune{':', '=', '#', ')', '}'}, whitespaceRunes...)543func (p *parser) ignoreSpaces() int {544 skipped := 0545 for p.tok == ' ' || p.tok == '\t' {546 p.accept(p.tok)547 skipped++548 }549 return skipped550}551func (p *parser) ignoreWhitespace() {552 for isWhitespace(p.tok) {553 p.accept(p.tok)554 }555}...

Full Screen

Full Screen

accept

Using AI Code Generation

copy

Full Screen

1import (2func main() {3func main() {4 fmt.Println("Hello, 世界")5}6 f, err := parser.ParseFile(fset, "hello.go", src, 0)7 if err != nil {8 fmt.Println(err)9 }10 parser.Print(fset, f)11}12func main() {13 fmt.Println("Hello, 世界")14}15import (16func main() {17func main() {18 fmt.Println("Hello, 世界")19}20 f, err := parser.ParseFile(fset, "hello.go", src, 0)21 if err != nil {22 fmt.Println(err)23 }24 ast.Print(fset, f)25}26func main() {27 fmt.Println("Hello, 世界")28}29import (30func main() {31 expr, err := parser.ParseExpr(src)32 if err != nil {33 fmt.Println(err)34 }35 ast.Print(fset, expr)36}37import (38func main() {39func main() {40 fmt.Println("Hello, 世界")41}

Full Screen

Full Screen

accept

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 src := []byte(`package main4import "fmt"5func main() {6 fmt.Println("Hello, World!")7}`)8 fset := token.NewFileSet()9 f, err := parser.ParseFile(fset, "", src, parser.ParseComments)10 if err != nil {11 fmt.Println(err)12 }13 fmt.Println(f.Name)14}

Full Screen

Full Screen

accept

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Parser interface {3 Parse()4}5type MyParser struct {6}7func (p *MyParser) Parse() {8 fmt.Println("Parsing data")9}10func main() {11 var parser Parser = &MyParser{}12 parser.Parse()13}

Full Screen

Full Screen

accept

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := parser.NewParser()4 p.Accept("abc")5 fmt.Println(p)6}7import (8func main() {9 p := parser.NewParser()10 fmt.Println(p)11}12import (13func main() {14 p := parser.NewParser()15 fmt.Println(p)16}17import (18func main() {19 p := parser.NewParser()20 fmt.Println(p)21}22import (23func main() {24 p := parser.NewParser()25 fmt.Println(p)26}27import (28func main() {29 p := parser.NewParser()30 fmt.Println(p)31}32import (33func main() {34 p := parser.NewParser()35 fmt.Println(p)36}37import (38func main() {39 p := parser.NewParser()40 fmt.Println(p)41}42import (43func main() {44 p := parser.NewParser()45 fmt.Println(p)46}47import (48func main() {49 p := parser.NewParser()50 fmt.Println(p)51}52import (53func main() {54 p := parser.NewParser()55 fmt.Println(p)56}

Full Screen

Full Screen

accept

Using AI Code Generation

copy

Full Screen

1import java.io.*;2{3public static void main(String args[])4{5String s="a+b*c";6Parser p=new Parser();7p.accept(s);8p.parse();9}10}11import java.io.*;12{13String s;14int i;15public void accept(String str)16{17s=str;18i=0;19}20public void parse()21{22E();23}24public void E()25{26T();27Ep();28}29public void Ep()30{31if(i<s.length())32{33if(s.charAt(i)=='+')34{35i++;36T();37Ep();38}39{40return;41}42}43}44public void T()45{46F();47Tp();48}49public void Tp()50{51if(i<s.length())52{53if(s.charAt(i)=='*')54{55i++;56F();57Tp();58}59{60return;61}62}63}64public void F()65{66if(s.charAt(i)=='a')67{68i++;69}70else if(s.charAt(i)=='(')71{72i++;73E();74if(s.charAt(i)==')')75{76i++;77}78}79}80}

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 Gauge 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