本文整理汇总了Golang中github.com/pschlump/lexie/com.LF函数的典型用法代码示例。如果您正苦于以下问题:Golang LF函数的具体用法?Golang LF怎么用?Golang LF使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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())
}
示例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())
}
示例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
}
示例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))
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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++
}
示例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
}
示例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)
}
示例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)
}