123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708 |
- package xregex
- /*
- golang version regex parser
- refer to: https://github.com/aristotle9/as3cc/tree/master/java-template/src/org/lala/lex/utils/parser
- */
- import (
- "container/list"
- "fmt"
- "strings"
- )
- // Parser golang regex parser
- type Parser struct {
- actionTable []map[int64]int64
- gotoTable map[int64]map[int64]int64
- prodList []*productionItem
- inputTable map[string]int64
- codes []interface{}
- duplCount int64
- num int64
- flags string
- flagsC string
- }
- // Info print parser info.
- func (p *Parser) Info() (s string) {
- s += fmt.Sprintf("actionTable len:%d,", len(p.actionTable))
- s += fmt.Sprintf("prodList len:%d,", len(p.prodList))
- s += fmt.Sprintf("inputTable len:%d,", len(p.inputTable))
- s += fmt.Sprintf("codes len:%d\n", len(p.codes))
- return
- }
- // New return regex parser instance.
- func New() (p *Parser) {
- p = &Parser{}
- var tmp map[int64]int64
- p.actionTable = make([]map[int64]int64, 0)
- p.actionTable = append(p.actionTable, nil)
- tmp = make(map[int64]int64)
- tmp[0x20] = 0x4
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x6] = 0x1
- tmp[0x7] = 0x2
- tmp[0x8] = 0x1C
- tmp[0x2A] = 0x24
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x27] = 0x6
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x16] = 0x8
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x1D] = 0xA
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x0] = 0x5
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x2C] = 0x22
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x2F
- tmp[0x2A] = 0x24
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x1D] = 0xA
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0x21
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x21
- tmp[0xA] = 0x21
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x1D] = 0xA
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x0] = 0x7
- tmp[0x1] = 0x7
- tmp[0x2] = 0x7
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0x7
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x7
- tmp[0xA] = 0x7
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0xF] = 0x7
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x21] = 0x18
- tmp[0x1D] = 0x7
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x2C] = 0x22
- tmp[0x8] = 0x1C
- tmp[0xA] = 0x31
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x1D] = 0xA
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0x23
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x23
- tmp[0xA] = 0x23
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x23
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x1D] = 0x23
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0x25
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x25
- tmp[0xA] = 0x25
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x25
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x1D] = 0x25
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0x27
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x27
- tmp[0xA] = 0x27
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x27
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x1D] = 0x27
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x0] = 0x9
- tmp[0x1] = 0x9
- tmp[0x2] = 0x9
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0x9
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x9
- tmp[0xA] = 0x9
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0xF] = 0x9
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x21] = 0x18
- tmp[0x1D] = 0x9
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x28] = 0x26
- tmp[0x22] = 0x2C
- tmp[0x1C] = 0x28
- tmp[0x5] = 0x30
- tmp[0x18] = 0x45
- tmp[0x1B] = 0x2E
- tmp[0xC] = 0x2E
- tmp[0xD] = 0x2A
- tmp[0xE] = 0x37
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x3] = 0x19
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x21] = 0x18
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0x29
- tmp[0x8] = 0x1C
- tmp[0x9] = 0x29
- tmp[0xA] = 0x29
- tmp[0x2B] = 0x20
- tmp[0x24] = 0x1E
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x29
- tmp[0x15] = 0xE
- tmp[0x17] = 0xC
- tmp[0x1A] = 0x16
- tmp[0x2A] = 0x24
- tmp[0x1D] = 0x29
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x1F] = 0x4F
- tmp[0x25] = 0x55
- tmp[0x13] = 0x3F
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x29] = 0x5B
- tmp[0x25] = 0x57
- tmp[0x1E] = 0x4B
- tmp[0x26] = 0x59
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x1E] = 0x4D
- tmp[0x13] = 0x41
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x0] = 0xB
- tmp[0x1] = 0xB
- tmp[0x2] = 0xB
- tmp[0x3] = 0x1B
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0xB
- tmp[0x8] = 0x1C
- tmp[0x9] = 0xB
- tmp[0xA] = 0xB
- tmp[0xB] = 0x1B
- tmp[0xC] = 0x2E
- tmp[0xD] = 0x2A
- tmp[0xE] = 0x39
- tmp[0xF] = 0xB
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x16] = 0x8
- tmp[0x17] = 0xC
- tmp[0x18] = 0x39
- tmp[0x19] = 0x47
- tmp[0x1A] = 0x16
- tmp[0x1B] = 0x2E
- tmp[0x1C] = 0x28
- tmp[0x1D] = 0xB
- tmp[0x20] = 0xB
- tmp[0x21] = 0x18
- tmp[0x22] = 0x2C
- tmp[0x23] = 0x53
- tmp[0x24] = 0x1E
- tmp[0x27] = 0x6
- tmp[0x28] = 0x26
- tmp[0x2A] = 0x24
- tmp[0x2B] = 0x20
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0xC] = 0x35
- tmp[0x1B] = 0x49
- p.actionTable = append(p.actionTable, tmp)
- tmp = make(map[int64]int64)
- tmp[0x0] = 0xD
- tmp[0x1] = 0xD
- tmp[0x2] = 0xD
- tmp[0x3] = 0xD
- tmp[0x4] = 0x2E
- tmp[0x5] = 0x30
- tmp[0x7] = 0xD
- tmp[0x8] = 0x1C
- tmp[0x9] = 0xD
- tmp[0xA] = 0xD
- tmp[0xB] = 0xD
- tmp[0xC] = 0x2E
- tmp[0xD] = 0x2A
- tmp[0xE] = 0xD
- tmp[0xF] = 0xD
- tmp[0x10] = 0x10
- tmp[0x11] = 0x12
- tmp[0x12] = 0x14
- tmp[0x14] = 0x1A
- tmp[0x15] = 0xE
- tmp[0x16] = 0x8
- tmp[0x17] = 0xC
- tmp[0x18] = 0xD
- tmp[0x1A] = 0x16
- tmp[0x1B] = 0x2E
- tmp[0x1C] = 0x28
- tmp[0x1D] = 0xD
- tmp[0x20] = 0xD
- tmp[0x21] = 0x18
- tmp[0x22] = 0x2C
- tmp[0x24] = 0x1E
- tmp[0x27] = 0x6
- tmp[0x28] = 0x26
- tmp[0x2A] = 0x24
- tmp[0x2B] = 0x20
- tmp[0x2C] = 0x22
- p.actionTable = append(p.actionTable, tmp)
- p.gotoTable = make(map[int64]map[int64]int64)
- tmp = make(map[int64]int64)
- tmp[0xB] = 0x33
- tmp[0x3] = 0x1F
- p.gotoTable[0x18] = tmp
- tmp = make(map[int64]int64)
- tmp[0x0] = 0xF
- p.gotoTable[0x13] = tmp
- tmp = make(map[int64]int64)
- tmp[0x0] = 0x11
- tmp[0x1] = 0x15
- tmp[0x2] = 0x17
- tmp[0x14] = 0x2B
- tmp[0x7] = 0x2B
- tmp[0x9] = 0x2B
- tmp[0xA] = 0x2B
- tmp[0x1D] = 0x2B
- tmp[0xF] = 0x3D
- p.gotoTable[0x14] = tmp
- tmp = make(map[int64]int64)
- tmp[0x16] = 0x43
- p.gotoTable[0x15] = tmp
- tmp = make(map[int64]int64)
- tmp[0x0] = 0x13
- tmp[0x1] = 0x13
- tmp[0x2] = 0x13
- tmp[0x3] = 0x1D
- tmp[0x7] = 0x13
- tmp[0x20] = 0x51
- tmp[0x9] = 0x13
- tmp[0xA] = 0x13
- tmp[0xB] = 0x1D
- tmp[0xE] = 0x3B
- tmp[0xF] = 0x13
- tmp[0x14] = 0x13
- tmp[0x18] = 0x3B
- tmp[0x1D] = 0x13
- p.gotoTable[0x16] = tmp
- tmp = make(map[int64]int64)
- tmp[0x9] = 0x2D
- tmp[0xA] = 0x2D
- tmp[0x14] = 0x2D
- tmp[0x1D] = 0x2D
- tmp[0x7] = 0x2D
- p.gotoTable[0x17] = tmp
- p.prodList = []*productionItem{{0x19, 0x2}, {0x13, 0x1},
- {0x13, 0x4}, {0x15, 0x2}, {0x15, 0x0},
- {0x14, 0x3}, {0x14, 0x3}, {0x14, 0x2},
- {0x14, 0x2}, {0x14, 0x2}, {0x14, 0x2},
- {0x14, 0x3}, {0x14, 0x4}, {0x14, 0x2},
- {0x14, 0x1}, {0x17, 0x3}, {0x17, 0x4},
- {0x17, 0x5}, {0x17, 0x4}, {0x18, 0x4},
- {0x18, 0x2}, {0x18, 0x1}, {0x18, 0x3},
- {0x16, 0x1}, {0x16, 0x1}}
- p.inputTable = make(map[string]int64)
- p.inputTable["/"] = 0x2
- p.inputTable["["] = 0x9
- p.inputTable["escc"] = 0x12
- p.inputTable["]"] = 0xA
- p.inputTable["("] = 0x4
- p.inputTable["{"] = 0xC
- p.inputTable["^"] = 0xB
- p.inputTable[")"] = 0x5
- p.inputTable["|"] = 0x3
- p.inputTable["?"] = 0x8
- p.inputTable["}"] = 0xE
- p.inputTable["+"] = 0x7
- p.inputTable["*"] = 0x6
- p.inputTable[","] = 0xF
- p.inputTable["<$>"] = 0x1
- p.inputTable["-"] = 0x11
- p.inputTable["c"] = 0x10
- p.inputTable["d"] = 0xD
- return
- }
- func (p *Parser) put(data interface{}) error {
- if fmt.Sprint(data) == "dupl" {
- p.duplCount++
- if p.duplCount > 100 {
- return fmt.Errorf("dupl commands over 100")
- }
- }
- return nil
- }
- func (p *Parser) parse(lx *lexer) (ret interface{}, err error) {
- var (
- act int64
- token string
- tokenID int64
- state int64
- actObj int64
- stateStack = list.New()
- outputStack []interface{}
- )
- stateStack.PushBack(uint(0))
- for {
- if token, err = lx.getToken(); err != nil {
- return
- }
- tokenID = p.inputTable[token]
- state = int64(stateStack.Front().Value.(uint))
- actObj = p.actionTable[tokenID][state]
- if actObj == 0 {
- err = fmt.Errorf("Parse Error: %s", lx.getPositionInfo())
- return
- }
- act = actObj
- if act == 1 {
- ret = outputStack[len(outputStack)-1]
- return
- } else if (act & 1) == 1 {
- outputStack = append(outputStack, lx.yyText)
- stateStack.PushFront(uint(act)>>1 - 1)
- lx.advanced = true
- } else if (act & 1) == 0 {
- pi := uint(act) >> 1
- length := p.prodList[pi].bodyLength
- var result interface{}
- if length > 0 {
- result = outputStack[int64(len(outputStack))-length]
- }
- switch pi {
- case 0x1:
- result = p.codes
- case 0x2:
- result = p.codes
- case 0x3:
- p.flagsC = outputStack[len(outputStack)-1].(string)
- if !strings.Contains(p.flags, p.flagsC) {
- err = fmt.Errorf("Flag Repeated:%s", lx.getPositionInfo())
- return
- }
- if !strings.Contains("igm", p.flagsC) {
- err = fmt.Errorf("Unknow Flag:%s", lx.getPositionInfo())
- return
- }
- p.flags += p.flagsC
- case 0x4:
- case 0x5:
- if err = p.put("or"); err != nil {
- return
- }
- case 0x6:
- case 0x7:
- case 0x8:
- if err = p.put("star"); err != nil {
- return
- }
- case 0x9:
- if err = p.put("more"); err != nil {
- return
- }
- case 0xA:
- if err = p.put("ask"); err != nil {
- return
- }
- case 0xB:
- if err = p.put([]interface{}{"include", outputStack[len(outputStack)-2]}); err != nil {
- return
- }
- case 0xC:
- if err = p.put([]interface{}{"exclude", outputStack[len(outputStack)-2]}); err != nil {
- return
- }
- case 0xD:
- if err = p.put("cat"); err != nil {
- return
- }
- case 0xE:
- if err = p.put("single"); err != nil {
- return
- }
- case 0xF:
- p.num = (outputStack[len(outputStack)-2]).(int64) - 1
- for p.num > 0 {
- if err = p.put("dupl"); err != nil {
- return
- }
- p.num--
- }
- p.num = (outputStack[len(outputStack)-2]).(int64) - 1
- for p.num > 0 {
- if err = p.put("cat"); err != nil {
- return
- }
- p.num--
- }
- case 0x10:
- if err = p.put("ask"); err != nil {
- return
- }
- p.num = (outputStack[len(outputStack)-2]).(int64) - 1
- for p.num > 0 {
- if err = p.put("dupl"); err != nil {
- return
- }
- p.num--
- }
- p.num = (outputStack[len(outputStack)-2]).(int64) - 1
- for p.num > 0 {
- if err = p.put("cat"); err != nil {
- return
- }
- p.num--
- }
- case 0x11:
- p.num = (outputStack[len(outputStack)-4]).(int64) - 1
- for p.num > 0 {
- if err = p.put("dupl"); err != nil {
- return
- }
- p.num--
- }
- p.num = (outputStack[len(outputStack)-2]).(int64) - (outputStack[len(outputStack)-4]).(int64)
- if p.num > 0 {
- if err = p.put("dupl"); err != nil {
- return
- }
- if err = p.put("ask"); err != nil {
- return
- }
- for p.num > 1 {
- if err = p.put("dupl"); err != nil {
- return
- }
- p.num--
- }
- }
- p.num = (outputStack[len(outputStack)-2]).(int64) - 1
- for p.num > 0 {
- if err = p.put("cat"); err != nil {
- return
- }
- p.num--
- }
- case 0x12:
- p.num = (outputStack[len(outputStack)-3]).(int64)
- for p.num > 0 {
- if err = p.put("dupl"); err != nil {
- return
- }
- p.num--
- }
- if err = p.put("star"); err != nil {
- return
- }
- p.num = (outputStack[len(outputStack)-3]).(int64)
- for p.num > 0 {
- if err = p.put("cat"); err != nil {
- return
- }
- p.num--
- }
- case 0x13:
- p.num = (outputStack[len(outputStack)-4]).(int64)
- result = p.num + 1
- if err = p.put([]interface{}{"c", (outputStack[len(outputStack)-3])}); err != nil {
- return
- }
- if err = p.put([]interface{}{"c", (outputStack[len(outputStack)-1])}); err != nil {
- return
- }
- if err = p.put("range"); err != nil {
- return
- }
- case 0x14:
- p.num = (outputStack[len(outputStack)-2]).(int64)
- result = p.num + 1
- if err = p.put("single"); err != nil {
- return
- }
- case 0x15:
- if err = p.put("single"); err != nil {
- return
- }
- result = int64(1)
- case 0x16:
- if err = p.put([]interface{}{"c", (outputStack[len(outputStack)-3])}); err != nil {
- return
- }
- if err = p.put([]interface{}{"c", (outputStack[len(outputStack)-1])}); err != nil {
- return
- }
- if err = p.put("range"); err != nil {
- return
- }
- result = int64(1)
- case 0x17:
- if err = p.put([]interface{}{"c", (outputStack[len(outputStack)-1])}); err != nil {
- return
- }
- case 0x18:
- if "\\c" == outputStack[len(outputStack)-1].(string) {
- err = fmt.Errorf("Control Character:%s", lx.getPositionInfo())
- return
- }
- if err = p.put([]interface{}{"escc", (outputStack[len(outputStack)-1])}); err != nil {
- return
- }
- }
- /** actions applying end **/
- var j int64
- var e *list.Element
- for j < length {
- e = stateStack.Front()
- stateStack.Remove(e)
- outputStack = outputStack[:len(outputStack)-1]
- j++
- }
- state = int64(stateStack.Front().Value.(uint))
- actObj = p.gotoTable[p.prodList[pi].headerID][state]
- if actObj == 0 {
- err = fmt.Errorf("goto error! %s", lx.getPositionInfo())
- return
- }
- act = actObj
- stateStack.PushFront(uint(act)>>1 - 1)
- outputStack = append(outputStack, result)
- }
- }
- }
- // Parse parse input string.
- func (p *Parser) Parse(source string) (result interface{}, err error) {
- defer func() {
- if e := recover(); e != nil {
- err = fmt.Errorf("panic:%v", e)
- return
- }
- }()
- if source == "" {
- return
- }
- lx := newLexer()
- lx.setSource(source)
- return p.parse(lx)
- }
|