• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang com.LF函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pschlump/lexie/com.LF函数的典型用法代码示例。如果您正苦于以下问题:Golang LF函数的具体用法?Golang LF怎么用?Golang LF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了LF函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ParseRe

func (lr *LexReType) ParseRe(ss string) {
	com.DbPrintf("db2", "at %s\n", com.LF())
	lr.SetBuf(ss)
	com.DbPrintf("db2", "at %s\n", com.LF())
	lr.parseExpression(0, 0, nil)
	com.DbPrintf("db2", "at %s\n", com.LF())
}
开发者ID:pschlump,项目名称:lexie,代码行数:7,代码来源:re.go


示例2: DumpParseNodesChild

//
// What can I see at the top of a RE
//
//	LR_Text                     //
//	LR_EOF                      //
//	LR_DOT                      // .		-- Match any char
//	LR_STAR                     // *		-- Error if 1st char
//	LR_PLUS                     // +		-- Error if 1st char
//	LR_QUEST                    // ?		-- Error if 1st char
//	LR_B_CCL                    // [		-- Start of CCL Node
//	LR_E_CCL                    // ]
//	LR_OP_PAR                   // (		-- Start of Sub_Re
//	LR_CL_PAR                   // )
//	LR_CCL                      // [...]	-- CCL Node (Above)
//	LR_N_CCL                    // [^...]	-- N_CCL Node
//	LR_CARROT                   // ^		-- BOL
//	LR_MINUS                    // -		-- Text if not in CCL and not 1st char in CCL
//
//	Item     string
//	LR_Tok   LR_TokType
//	Children []*ReTreeNodeType
//	Next     *ReTreeNodeType
//
func (lr *LexReType) DumpParseNodesChild(ch []ReTreeNodeType, d int) {
	com.DbPrintf("DumpParseNodes", "\n%sDumpParseNodesChild: At %s\n", N4Blanks(d), com.LF())
	for ii, vv := range ch {
		com.DbPrintf("DumpParseNodes", "%sat %s [step %d] ", N4Blanks(d), com.LF(), ii)
		com.DbPrintf("DumpParseNodes", "Item: [%s] %d=%s, N-Children=%d\n", vv.Item, vv.LR_Tok, NameOfLR_TokType(vv.LR_Tok), len(vv.Children))
		if len(vv.Children) > 0 {
			lr.DumpParseNodesChild(vv.Children, d+1)
		}
	}
	com.DbPrintf("DumpParseNodes", "%sDumpParseNodesChild: Done %s\n\n", N4Blanks(d), com.LF())
}
开发者ID:pschlump,项目名称:lexie,代码行数:34,代码来源:re.go


示例3: FxReadJson

// ----------------------------------------------------------------------------------------------------------------------------------------
func FxReadJson(callNo int, pt *Parse2Type, Context *eval.ContextType, curTree *MtType) (err error) {
	fmt.Printf("Fx_ReadJson Called, %d\n", callNo)
	// {% read_json ID "file_name.json" %} (config allows url:// not just file"

	if callNo == 0 {

		if !curTree.NOptions(2) {
			// xyzzy } else if !curTree.IsId(0) {		// -- implement to check that [0] is an ID
		} else {
			id := curTree.SVal[0]
			path := curTree.SVal[1]
			// path = path[0 : len(path)-1]
			err = nil
			// var jsonData map[string]SQLOne
			var file []byte
			file, err = ioutil.ReadFile(path)
			if err != nil {
				fmt.Printf("Error(10014): %v, %s, Config File:%s\n", err, com.LF(), path)
				return
			}
			file = []byte(strings.Replace(string(file), "\t", " ", -1)) // file = []byte(ReplaceString(string(file), "^[ \t][ \t]*//.*$", ""))

			// Check beginning of file if "{" then MapOf, if "[" Array, else look at single value
			if strings.HasPrefix(string(file), "{") {

				jsonData := make(map[string]interface{})

				err = json.Unmarshal(file, &jsonData)
				if err != nil {
					fmt.Printf("Error(10012): %v, %s, Config File:%s\n", err, com.LF(), path)
					return
				}

				Context.SetInContext(id, eval.CtxType_MapOf, jsonData)

			} else {

				jsonData := make([]interface{}, 0, 100)

				err = json.Unmarshal(file, &jsonData)
				if err != nil {
					fmt.Printf("Error(10012): %v, %s, Config File:%s\n", err, com.LF(), path)
					return
				}

				Context.SetInContext(id, eval.CtxType_ArrayOf, jsonData)

			}

		}
	}

	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:55,代码来源:parse_tree.go


示例4: DumpParseNodes

func (lr *LexReType) DumpParseNodes() {
	com.DbPrintf("DumpParseNodes", "\nDumpParseNodes: At %s\n", com.LF())
	for ii, vv := range lr.Tree.Children {
		com.DbPrintf("DumpParseNodes", "at %s [step %d] ", com.LF(), ii)
		com.DbPrintf("DumpParseNodes", "Item: [%s] %d=%s, N-Children=%d\n", vv.Item, vv.LR_Tok, NameOfLR_TokType(vv.LR_Tok), len(vv.Children))
		if len(vv.Children) > 0 {
			lr.DumpParseNodesChild(vv.Children, 1)
		}
	}
	com.DbPrintf("DumpParseNodes", "DumpParseNodes: Done %s\n\n", com.LF())
	com.DbPrintf("DumpParseNodesX", "DumpParseNodes: %s\n\n", com.SVarI(lr.Tree))
}
开发者ID:pschlump,项目名称:lexie,代码行数:12,代码来源:re.go


示例5: GetPos

// Get the current line/col no and file name
func (pb *PBReadType) GetPos() (LineNo int, ColNo int, FileName string) {
	com.DbPrintf("pbbuf02", "At: %s\n", com.LF())
	if len(pb.PbBuffer) > 0 {
		com.DbPrintf("pbbuf02", "From Buffer At: %s\n", com.LF())
		LineNo = pb.PbBuffer[0].LineNo
		ColNo = pb.PbBuffer[0].ColNo
		FileName = pb.PbBuffer[0].FileName
	} else {
		com.DbPrintf("pbbuf02", "Not set At: %s\n", com.LF())
		LineNo = 1
		ColNo = 1
		FileName = ""
	}
	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:16,代码来源:pbread.go


示例6: NextRune

// Return the next rune.  If runes have been pushed back then use those first.
func (pb *PBReadType) NextRune() (rn rune, done bool) {
	com.DbPrintf("pbbuf01", "At: %s\n", com.LF())
	done = false

	if pb.PbTop > 0 {
		pb.PbTop--
		rn = pb.PbAFew[pb.PbTop]
	} else if len(pb.PbBuffer) <= 0 {
		done = true
		// } else if len(pb.PbBuffer) == 1 && pb.PbBuffer[0].Pos >= len(pb.PbBuffer[0].Buffer) && !pb.PbBuffer[0].EofOnFile {
		// Xyzzy - read in more form file - append
		// so far case never happens because EofOnFile is constant true at init time.
	} else if len(pb.PbBuffer) == 1 && pb.PbBuffer[0].Pos >= len(pb.PbBuffer[0].Buffer) && pb.PbBuffer[0].EofOnFile {
		done = true
	} else if len(pb.PbBuffer) > 1 && pb.PbBuffer[0].Pos >= len(pb.PbBuffer[0].Buffer) && pb.PbBuffer[0].EofOnFile {
		pb.PbBuffer = pb.PbBuffer[1:]
		return pb.NextRune()
	} else {
		//fmt.Printf("Just before core, Pos=%d\n", pb.PbBuffer[0].Pos)
		//fmt.Printf("Just before core, Len 1=%d\n", len(pb.PbBuffer[0].Buffer))
		if pb.PbBuffer[0].Pos >= len(pb.PbBuffer[0].Buffer) { // xyzzy --------------------- pjs - new code - not certain if correct ---------------------------------
			done = true
		} else {
			rn = pb.PbBuffer[0].Buffer[pb.PbBuffer[0].Pos]
			pb.PbBuffer[0].Pos++
			if rn == '\n' {
				pb.PbBuffer[0].LineNo++
				pb.PbBuffer[0].ColNo = 1
			} else {
				pb.PbBuffer[0].ColNo++
			}
		}
	}
	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:36,代码来源:pbread.go


示例7: ReplaceBlocksWithNew

// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Find the nodes in tree (blocks) with stated name and replace them with new
func ReplaceBlocksWithNew(search_in_tree **MtType, new_block *MtType) {

	block_name := new_block.SVal[0]

	var walkTree func(mt **MtType, pos, depth int)
	walkTree = func(mt **MtType, pos, depth int) {
		for ii := range (*mt).List {
			//if vv.FxId == gen.Fx_block && block_name == vv.SVal[0] {
			//	fmt.Printf("FxExtend Replace: [%d] found block with name >%s<-, %s\n", ii, vv.SVal[0], com.LF())
			//	*mt = new_block
			//}
			walkTree(&((*mt).List[ii]), ii, depth+1)
		}
		if len((*mt).SVal) > 0 {
			fmt.Printf("FxExtend Before FxId = %d, looking for %d (*mt).SVal[0] = >%s< looking for %s, %s\n", (*mt).FxId, gen.Fx_block, (*mt).SVal[0], block_name, com.LF())
			if (*mt).FxId == gen.Fx_block && block_name == (*mt).SVal[0] {
				fmt.Printf("FxExtend Replace: found block with name >%s<-, %s\n", (*mt).SVal[0], com.LF())
				*mt = new_block
			}
		}
	}

	walkTree(search_in_tree, 0, 0)

	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:28,代码来源:mt.go


示例8: Call

// Call a function that has been placed in the table
func (ctx *ContextType) Call(name string, params ...interface{}) (result []reflect.Value, err error) {
	ctx.mutex.RLock()
	fx, ok := ctx.Store[name]
	ctx.mutex.RUnlock()
	if !ok { // 								Need to have a mutext - lock
		err = errors.New(name + " function does not exist.")
		return
	}
	np := len(params)
	fmt.Printf("np=%d, name=%s\n", np, name)
	if np != fx.Func.Type().NumIn() { // 		Posssibility of default params? // Should save # of params from SetInContext call?
		err = ErrParamsNotAdapted
		return
	}
	in := make([]reflect.Value, np) // 			Type check params for correctness?
	for k, param := range params {
		if params[k] == nil {
			in[k] = reflect.ValueOf((*string)(nil))
		} else {
			in[k] = reflect.ValueOf(param)
		}
	}
	fmt.Printf("Just Before %s %d %+v, %s\n", name, np, params[0], com.LF())
	result = fx.Func.Call(in)
	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:27,代码来源:lst.go


示例9: EvalExpr

// n from beginning to m from end.
func (mt *MtType) EvalExpr(Context *eval.ContextType, n, m int) bool {
	m = len(mt.SVal) - m // Convert to Pos
	sv := mt.SVal[n:m]   // Slice of params to eval.
	fmt.Printf("mt.EvalExpr - TOP: ealuate sv=%+v ----------------------------------------------------- \n", sv)
	fmt.Printf("mt.EvalExpr - TOP: ealuate mt.SVal=%+v ----------------------------------------------------- \n", mt.SVal)
	// xyzzy -- temporary -- incomplete!!!!!!!!!!!!!!!!!!!!!!
	evalData := &eval.EvalType{
		Pos: 0,
		Ctx: Context,
		Mm:  mt.TokVal[n:m], // []tok.Token
	}
	fmt.Printf("INPUT m=%d n=%d, %s ----------------------------------------------------- \n", m, n, com.SVarI(evalData))
	tr := evalData.Pres2()
	fmt.Printf("BOTTOM: %s ----------------------------------------------------- \n", com.SVarI(tr))
	s := sv[0]
	v, t, _ := Context.GetFromContext(s)
	fmt.Printf("At: %s - in EvalExpr, v=%v t=%v for >%s<-\n", com.LF(), v, t, s)
	// xyzzy nil, 9 -- 9 is error, not found
	if t == eval.CtxType_Bool {
		fmt.Printf("Setting bool to true\n")
		mt.DataType = t
		mt.XValue = v
	}
	return true
}
开发者ID:pschlump,项目名称:lexie,代码行数:26,代码来源:parse_tree.go


示例10: OpenFile

// Open a file - this puts the file at the end of the input.   This is used on the command line for a list of files
// in order.  Each opened and added to the end of the list.
func (pb *PBReadType) OpenFile(fn string) (err error) {
	com.DbPrintf("pbbuf01", "At: %s\n", com.LF())
	pb.FileName = fn
	pb.AbsFileName, _ = filepath.Abs(fn)
	pb.FilesOpened[pb.AbsFileName] = true

	// read file -> PbBuffer
	b := &ABuffer{
		FileName:    fn,
		AbsFileName: pb.AbsFileName,
		LineNo:      1,
		ColNo:       1,
	}
	pb.PbBuffer = append(pb.PbBuffer, b)

	bb, err := ioutil.ReadFile(fn)
	if err != nil {
		return
	}
	b.EofOnFile = true
	b.Pos = 0
	var rn rune
	var sz int
	b.Buffer = make([]rune, 0, len(bb))
	for ii := 0; ii < len(bb); ii += sz {
		rn, sz = utf8.DecodeRune(bb[ii:])
		b.Buffer = append(b.Buffer, rn)
	}

	return nil
}
开发者ID:pschlump,项目名称:lexie,代码行数:33,代码来源:pbread.go


示例11: FileSeen

// Have we already seen the specified file.  Useful for require(fn)
func (pb *PBReadType) FileSeen(fn string) bool {
	com.DbPrintf("pbbuf01", "At: %s\n", com.LF())
	a, _ := filepath.Abs(fn)
	if t, ok := pb.FilesOpened[a]; ok && t {
		return true
	}
	return false
}
开发者ID:pschlump,项目名称:lexie,代码行数:9,代码来源:pbread.go


示例12: PbRune

// Push back a single rune onto input.  You can call this more than one time.
func (pb *PBReadType) PbRune(rn rune) {
	com.DbPrintf("pbbuf01", "At: %s\n", com.LF())

	if pb.PbTop >= MaxAFew { // Buffer is full
		pb.pushbackIntoBuffer()
	}

	pb.PbAFew[pb.PbTop] = rn
	pb.PbTop++
}
开发者ID:pschlump,项目名称:lexie,代码行数:11,代码来源:pbread.go


示例13: SetPos

// Set the line/col/file-name for the current buffer - Useful for constructing something like C/Pre processor's #line
func (pb *PBReadType) SetPos(LineNo int, ColNo int, FileName string) {
	com.DbPrintf("pbbuf01", "At: %s\n", com.LF())
	pb.pushbackIntoBuffer()
	if len(pb.PbBuffer) > 0 {
		pb.PbBuffer[0].LineNo = LineNo
		pb.PbBuffer[0].ColNo = ColNo
		pb.PbBuffer[0].FileName = FileName
	}
	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:11,代码来源:pbread.go


示例14: PbByteArray

// Push back a string.  Will be converted from an array of byte to an array of runes.
func (pb *PBReadType) PbByteArray(s []byte) {
	com.DbPrintf("pbbuf01", "At: %s\n", com.LF())
	rns := make([]rune, 0, len(s))
	var rn rune
	var sz int
	for ii := 0; ii < len(s); ii += sz {
		rn, sz = utf8.DecodeRune(s[ii:])
		rns = append(rns, rn)
	}
	pb.PbRuneArray(rns)
}
开发者ID:pschlump,项目名称:lexie,代码行数:12,代码来源:pbread.go


示例15: ReplaceToken

// dfa.TokList.ReplaceToken ( dfa.MTab.Machine[ctx.St].Info.MatchLength, dfa.MTab.Machine[ctx.St].Info.ReplStr )
func (tl *TokenList) ReplaceToken(l int, s string) {
	ii := len(tl.TL) - 1
	lv := len(tl.TL[ii].AToken.Val)
	tl.TL[ii].AToken.IsRepl = true
	tl.TL[ii].AToken.ReplStr = s
	if lv-l >= 1 {
		tl.TL[ii].AToken.Val = tl.TL[ii].AToken.Val[0:lv-l] + s
	} else {
		com.DbPrintf("db_tok01", "Error: ReplaceToken has invalid data, %s\n", com.LF())
	}
	com.DbPrintf("db_tok01", "ReplaceToken: Match: ->%s<- Val: ->%s<-\n", tl.TL[ii].AToken.Match, tl.TL[ii].AToken.Val)
}
开发者ID:pschlump,项目名称:lexie,代码行数:13,代码来源:tok.go


示例16: Dump01

// Output debugging info
func (pb *PBReadType) Dump01(fo io.Writer) {
	fmt.Fprintf(fo, "Dump At: %s\n", com.LF())
	fmt.Fprintf(fo, "N PbBuffer=%d\n", len(pb.PbBuffer))
	for ii := 0; ii < len(pb.PbBuffer); ii++ {
		fmt.Fprintf(fo, "  Buffer [%d] Len: %d Pos: %d\n", ii, len(pb.PbBuffer[ii].Buffer), pb.PbBuffer[ii].Pos)
		fmt.Fprintf(fo, "  Contents ->")
		for jj := pb.PbBuffer[ii].Pos; jj < len(pb.PbBuffer[ii].Buffer); jj++ {
			fmt.Fprintf(fo, "%s", string(pb.PbBuffer[ii].Buffer[jj]))
		}
		fmt.Fprintf(fo, "<-\n")
	}
	if pb.PbTop > 0 {
		fmt.Fprintf(fo, "PbTop=%d\n", pb.PbTop)
		fmt.Fprintf(fo, "  PbAFew ->")
		for jj := pb.PbTop - 1; jj >= 0; jj-- {
			fmt.Fprintf(fo, "%s", string(pb.PbAFew[jj]))
		}
		fmt.Fprintf(fo, "<-\n")
	}
}
开发者ID:pschlump,项目名称:lexie,代码行数:21,代码来源:pbread.go


示例17: PbFile

// Place the contents of a file in buffers at the head so NextRune will pull from this next.
func (pb *PBReadType) PbFile(fn string) (err error) {
	com.DbPrintf("pbbuf01", "At: %s\n", com.LF())
	err = nil

	pb.pushbackIntoBuffer()

	pb.FileName = fn
	pb.AbsFileName, _ = filepath.Abs(fn)
	pb.FilesOpened[pb.AbsFileName] = true

	// read file -> PbBuffer
	b := &ABuffer{
		FileName:    fn,
		AbsFileName: pb.AbsFileName,
		LineNo:      1,
		ColNo:       1,
	}
	// pb.PbBuffer = append(pb.PbBuffer, b)
	// data = append([]string{"Prepend Item"}, data...)
	pb.PbBuffer = append([]*ABuffer{b}, pb.PbBuffer...) // prepend

	bb, err := ioutil.ReadFile(fn)
	if err != nil {
		return
	}
	b.EofOnFile = true
	b.Pos = 0
	var rn rune
	var sz int
	b.Buffer = make([]rune, 0, len(bb))
	for ii := 0; ii < len(bb); ii += sz {
		rn, sz = utf8.DecodeRune(bb[ii:])
		b.Buffer = append(b.Buffer, rn)
	}

	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:38,代码来源:pbread.go


示例18: TestLexie

func (s *ReTesteSuite) TestLexie(c *C) {

	// Test of Parseing REs into RE-TParseTrees
	// return
	fmt.Fprintf(os.Stderr, "Test Parsing of REs, %s\n", com.LF())

	com.DbOnFlags["db_DumpPool"] = true
	com.DbOnFlags["parseExpression"] = true
	com.DbOnFlags["CalcLength"] = true
	com.DbOnFlags["DumpParseNodes"] = true
	com.DbOnFlags["DumpParseNodesX"] = true

	fmt.Printf("**** In Test RE\n")

	n_err := 0
	n_skip := 0

	for ii, vv := range Lexie00Data {
		if !vv.SkipTest {
			fmt.Printf("\n\n--- %d Test: %s -----------------------------------------------------------------------------\n\n", ii, vv.Test)
			lr := NewLexReType()
			lr.SetBuf(vv.Re)
			tn := 0
			cc, ww := lr.Next()
			for ww != LR_EOF {
				fmt.Printf("    %s % x = %d %s\n", string(cc), string(cc), ww, LR_TokTypeLookup[ww])

				if len(vv.SM) > 0 {
					// Check correct token
					if vv.SM[tn].Tok != ww {
						fmt.Printf("     Failed to return the correct token, expecting %d/%s, got %d/%s\n", vv.SM[tn].Tok, LR_TokTypeLookup[vv.SM[tn].Tok], ww,
							LR_TokTypeLookup[ww])
						c.Check(int(vv.SM[tn].Tok), Equals, int(ww))
						n_err++
					}
					// Check correct string/rune returned
					if !CmpByteArr(vv.SM[tn].Dat, []byte(cc)) {
						fmt.Printf("     The returned runes did not match\n")
						c.Check(string(vv.SM[tn].Dat), Equals, cc)
						n_err++
					}

				}

				tn++
				cc, ww = lr.Next()
			}
			fmt.Printf("\n--- %d End : %s -----------------------------------------------------------------------------\n\n", ii, vv.Test)
		}
	}

	for ii, vv := range Lexie01Data {
		if !vv.SkipTest {
			fmt.Printf("\n\n--- %d Test: %s -----------------------------------------------------------------------------\n\n", ii, vv.Test)

			lr := NewLexReType()
			lr.ParseRe(vv.Re)

			lr.Sigma = lr.GenerateSigma()
			fmt.Printf("Sigma: ->%s<-\n", lr.Sigma)

			if vv.Sigma != "" {
				if vv.Sigma != lr.Sigma {
					fmt.Printf("     The calculated and reference Sigma did not match\n")
					c.Check(vv.Sigma, Equals, lr.Sigma)
					n_err++
				}
			}

			fmt.Printf("\n--- %d End : %s -----------------------------------------------------------------------------\n\n", ii, vv.Test)
		}
	}

	// -------------------------------------------------------------------------------------------------------------------------------------------------
	lr := NewLexReType()
	com.DbOnFlags["DumpParseNodes"] = true
	com.DbOnFlags["DumpParseNodesX"] = true
	com.DbOnFlags["db_DumpPool"] = true
	com.DbOnFlags["parseExpression"] = true
	for i, v := range Test6Data {
		com.DbPrintf("debug", "\nTest[%03d]: `%s` %s\n\n", i, v.Re, strings.Repeat("-", 120-len(v.Re)))
		// fmt.Printf("%s *** com.Red *** %s\n", ansi.ColorCode("red"), ansi.ColorCode("reset"))
		lr.ParseRe(v.Re)
		lr.DumpParseNodes()
		if len(v.TopTok) > 0 {
			if len(v.TopTok) != len(lr.Tree.Children) {
				com.DbPrintf("debug", "%sError%s: wrong number of tokens prsed, Expected: %d Got %d\n", com.Red, com.Reset, len(v.TopTok), len(lr.Tree.Children))
				n_err++
			} else {
				for i := 0; i < len(v.TopTok); i++ {
					if v.TopTok[i] != lr.Tree.Children[i].LR_Tok {
						com.DbPrintf("debug", "%sError%s: invalid token returnd at postion %d\n", com.Red, com.Reset, i)
						c.Check(v.TopTok[i], Equals, lr.Tree.Children[i].LR_Tok)
						n_err++
					}
				}
			}
		}
		if len(v.TopVal) > 0 {
			if len(v.TopVal) != len(lr.Tree.Children) {
//.........这里部分代码省略.........
开发者ID:pschlump,项目名称:lexie,代码行数:101,代码来源:re_test.go


示例19: Test_PbBufer01

func Test_PbBufer01(t *testing.T) {

	SymbolTable := make([]*MacroDefTestType, 0, 100)
	Define := func(name rune, body string) {
		for ii := 0; ii < len(SymbolTable); ii++ {
			// fmt.Printf("Search at %d, for %s\n", ii, string(name))
			if SymbolTable[ii] != nil && SymbolTable[ii].Rn == name {
				SymbolTable[ii].Body = body
				return
			}
		}
		// fmt.Printf("Append\n")
		SymbolTable = append(SymbolTable, &MacroDefTestType{Rn: name, Body: body})
	}
	ResetST := func() {
		// SymbolTable = make([]*MacroDefTestType, 0, 100)
		SymbolTable = SymbolTable[:1]
	}
	HaveMacro := func(name rune) (body string, found bool) {
		body = ""
		found = false
		for ii := 0; ii < len(SymbolTable); ii++ {
			if SymbolTable[ii] != nil && SymbolTable[ii].Rn == name {
				body, found = SymbolTable[ii].Body, true
				return
			}
		}
		return
	}

	for ii, vv := range Pb01Test {

		if !vv.SkipTest {

			// Implement a quick - fetch execute macine to test - the PbBuffer - commands/opcodes are the Cmd* constants above.
			ss := ""
			pb := NewPbRead()
			ResetST()
			for pc, ww := range vv.Actions {

				switch ww.OpCode {
				case CmdOpenFile: // Open a file , at the tail end of list of input
					pb.OpenFile(ww.Fn)
					com.DbPrintf("testCode", "Open file %s At: %s\n", ww.Fn, com.LF())
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
				case CmdPbString: // Push back a string
					pb.PbString(ww.Data)
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
				case CmdPbRune: // Push back a rune
					pb.PbRune(ww.Rn)
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
				case CmdPbRuneArray: // Push back a rune array
					pb.PbRuneArray(ww.RnS)
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
				case CmdNextNChar:
					for ll := 0; ll < ww.X; ll++ {
						rn, done := pb.NextRune()
						if !done {
							ss = ss + string(rn)
						}
						com.DbPrintf("testCode", "Case 5: At: ->%s<- ll=%d ss >>>%s<<< %s\n", string(rn), ll, ss, com.LF())
					}
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
				case CmdPeek:
					rn, done := pb.PeekRune()
					if done || rn != ww.Rn {
						t.Errorf("%04s: Peek at [pc=%d] in test [%s] did not work, got %s expected %s, done=%v\n", pc, ii, string(rn), string(ww.Rn), done)
					}
				case CmdOutputToEof:
					com.DbPrintf("testCode", "All Done: ss >>>%s<<< before At: %s\n", ss, com.LF())
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
					for rn, done := pb.NextRune(); !done; rn, done = pb.NextRune() {
						ss = ss + string(rn)
					}
					com.DbPrintf("testCode", "All Done: ss >>>%s<<< after At: %s\n", ss, com.LF())
				case CmdPbByteArray: // Push back a byte array
					pb.PbByteArray([]byte(ww.Data))
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
				case CmdPbFile: // Open file and push contents back onto input at head of list. (Macro file, Include, Require)
					pb.PbFile(ww.Fn)
					com.DbPrintf("testCode", "Pb file %s At: %s\n", ww.Fn, com.LF())
					if com.DbOn("testDump") {
						pb.Dump01(os.Stdout)
					}
				case CmdFileSeen:
					fs := pb.FileSeen(ww.Fn)
//.........这里部分代码省略.........
开发者ID:pschlump,项目名称:lexie,代码行数:101,代码来源:p1_test.go


示例20: expandCCL

func expandCCL(s string) (ccl string) {
	ccl = ""
	com.DbPrintf("db2", "at %s\n", com.LF())

	pos := 0
	if len(s) > 0 && s[0:1] == "-" { // Check for leading '-' include in CCL
		ccl += "-"
		pos = 1
	}

	for ii := pos; ii < len(s); ii++ {
		com.DbPrintf("re2", "ii=%d remaining ->%s<-, %s\n", ii, s[ii:], com.LF())
		if strings.HasPrefix(s[ii:], "[:alphnum:]") {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			// ccl += X_ALPHA
			ccl += X_LOWER
			ccl += X_UPPER
			ccl += X_NUMERIC
			ii += len("[:alphnum:]") - 1
		} else if strings.HasPrefix(s[ii:], "[:alpha:]") {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			// ccl += X_ALPHA
			ccl += X_LOWER
			ccl += X_UPPER
			ii += len("[:alpha:]") - 1
		} else if strings.HasPrefix(s[ii:], "[:lower:]") {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			ccl += X_LOWER
			ii += len("[:lower:]") - 1
		} else if strings.HasPrefix(s[ii:], "[:upper:]") {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			ccl += X_UPPER
			ii += len("[:upper:]") - 1
		} else if strings.HasPrefix(s[ii:], "[:numeric:]") {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			ccl += X_NUMERIC
			ii += len("[:numeric:]") - 1
		} else if ii+9 <= len(s) && s[ii:ii+9] == "a-zA-Z0-9" {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			// ccl += X_ALPHA
			ccl += X_LOWER
			ccl += X_UPPER
			ccl += X_NUMERIC
			ii += 8
		} else if ii+6 <= len(s) && s[ii:ii+6] == "a-zA-Z" {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			// ccl += X_ALPHA
			ccl += X_LOWER
			ccl += X_UPPER
			ii += 5
		} else if ii+3 <= len(s) && s[ii:ii+3] == "0-9" {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			// fmt.Printf("matched 0-9 pattern\n")
			ccl += X_NUMERIC
			ii += 2
		} else if ii+3 <= len(s) && s[ii:ii+3] == "a-z" {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			ccl += X_LOWER
			ii += 2
		} else if ii+3 <= len(s) && s[ii:ii+3] == "A-Z" {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			ccl += X_UPPER
			ii += 2
		} else if ii+2 < len(s) && s[ii+1:ii+2] == "-" {
			com.DbPrintf("re2", "   Matched: %s\n", com.LF())
			// xyzzyRune  TODO - this code is horribley non-utf8 compatable at this moment in time.
			e := s[ii+2]
			// fmt.Printf("matched a-b pattern, b=%s e=%s\n", string(s[ii]), string(e))
			if s[ii] >= e {
				fmt.Printf("Error: Poorly formatted character-class, beginning is larger than or equal to end of CCL\n") // Xyzzy - need line number etc
			}
			for b := s[ii]; b <= e; b++ {
				ccl += string(b)
			}
			ii += 2
		} else {
			ccl += s[ii : ii+1]
		}
		// fmt.Printf("bottom ccl now: ->%s<-\n", ccl)
	}

	return
}
开发者ID:pschlump,项目名称:lexie,代码行数:83,代码来源:re.go



注:本文中的github.com/pschlump/lexie/com.LF函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang bolt.Tx类代码示例发布时间:2022-05-28
下一篇:
Golang com.DbPrintf函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap