updated code
This commit is contained in:
parent
70646c256e
commit
15ba383f96
@ -124,7 +124,70 @@ func (p *process_t) pop_context() (node *Cnode_t) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
stmt
|
||||||
|
|
||||||
|
text text bracket
|
||||||
|
stmt: text text
|
||||||
|
stmt: text TEXT
|
||||||
|
*/
|
||||||
func (interp *Interp) eval_atom_node(node *Cnode_t) (*string, error) {
|
func (interp *Interp) eval_atom_node(node *Cnode_t) (*string, error) {
|
||||||
|
var (
|
||||||
|
p process_t
|
||||||
|
v *string
|
||||||
|
inode *Cnode_t
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
p.interp = interp
|
||||||
|
|
||||||
|
for node != nil {
|
||||||
|
p.push_context(node)
|
||||||
|
p.push_string_value("") // placeholder for return value
|
||||||
|
|
||||||
|
for inode = node.child; inode != nil; inode = inode.next {
|
||||||
|
switch inode.code {
|
||||||
|
case CNODE_BRACKET:
|
||||||
|
//p.push_context(inode)
|
||||||
|
//p.push_string_value("")
|
||||||
|
//node =
|
||||||
|
|
||||||
|
case CNODE_TEXT:
|
||||||
|
|
||||||
|
//fmt.Printf("XXXXXXXXXXXXXXXXXXXx[%s]\n", string(inode.token))
|
||||||
|
err = p.push_string_value(string(inode.token))
|
||||||
|
if err != nil {
|
||||||
|
goto oops
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("CALLING\n")
|
||||||
|
err = p.call()
|
||||||
|
if err != nil {
|
||||||
|
goto oops
|
||||||
|
}
|
||||||
|
if p.ctx.parent_ctx != nil {
|
||||||
|
p.pop_context()
|
||||||
|
}
|
||||||
|
|
||||||
|
node = node.next
|
||||||
|
}
|
||||||
|
|
||||||
|
v = (*string)(p.pop_value())
|
||||||
|
p.pop_context()
|
||||||
|
if p.ctx != nil {
|
||||||
|
err = fmt.Errorf("internal error - dangling process context")
|
||||||
|
goto oops
|
||||||
|
}
|
||||||
|
|
||||||
|
return v, nil
|
||||||
|
|
||||||
|
oops:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (interp *Interp) eval_atom_node_old(node *Cnode_t) (*string, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
p process_t
|
p process_t
|
||||||
@ -186,11 +249,6 @@ func (interp *Interp) eval_atom_node(node *Cnode_t) (*string, error) {
|
|||||||
goto oops
|
goto oops
|
||||||
}
|
}
|
||||||
|
|
||||||
case CNODE_SEP:
|
|
||||||
// skip
|
|
||||||
case CNODE_EOL:
|
|
||||||
// skip
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("internal error - non-atom node - %d", node.code)
|
err = fmt.Errorf("internal error - non-atom node - %d", node.code)
|
||||||
goto oops
|
goto oops
|
||||||
|
@ -392,7 +392,7 @@ func (inter *Interp) add_cnode_to_feed_struct(feed *feed_struct_t, cnode *Cnode_
|
|||||||
}
|
}
|
||||||
|
|
||||||
var feed_to_cnode_code_tab [11]cnode_code_t = [11]cnode_code_t{
|
var feed_to_cnode_code_tab [11]cnode_code_t = [11]cnode_code_t{
|
||||||
FEED_TOP: CNODE_EOL, // this must never be used
|
FEED_TOP: CNODE_INVALID, // this must never be used
|
||||||
FEED_INIT: CNODE_INIT,
|
FEED_INIT: CNODE_INIT,
|
||||||
FEED_BRACKET: CNODE_BRACKET,
|
FEED_BRACKET: CNODE_BRACKET,
|
||||||
FEED_BRACE: CNODE_BRACE,
|
FEED_BRACE: CNODE_BRACE,
|
||||||
@ -400,9 +400,9 @@ var feed_to_cnode_code_tab [11]cnode_code_t = [11]cnode_code_t{
|
|||||||
FEED_DQUOTE: CNODE_DQUOTE,
|
FEED_DQUOTE: CNODE_DQUOTE,
|
||||||
FEED_DQUOTED_TEXT: CNODE_TEXT,
|
FEED_DQUOTED_TEXT: CNODE_TEXT,
|
||||||
FEED_DOLLAR: CNODE_VAR,
|
FEED_DOLLAR: CNODE_VAR,
|
||||||
FEED_SEP: CNODE_SEP,
|
FEED_SEP: CNODE_INVALID,
|
||||||
FEED_WORD: CNODE_TEXT,
|
FEED_WORD: CNODE_TEXT,
|
||||||
FEED_EOL: CNODE_EOL,
|
FEED_EOL: CNODE_INVALID,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (interp *Interp) pop_feed_struct() *feed_struct_t {
|
func (interp *Interp) pop_feed_struct() *feed_struct_t {
|
||||||
@ -445,6 +445,9 @@ func (interp *Interp) pop_feed_struct() *feed_struct_t {
|
|||||||
parent.cnode_cont = false
|
parent.cnode_cont = false
|
||||||
} else {
|
} else {
|
||||||
cnode = &Cnode_t{code: feed_to_cnode_code_tab[feed.state], token: feed.token}
|
cnode = &Cnode_t{code: feed_to_cnode_code_tab[feed.state], token: feed.token}
|
||||||
|
if cnode.code == CNODE_INVALID {
|
||||||
|
panic("internal error - CNODE INVALID encountered")
|
||||||
|
}
|
||||||
if cnode.code == CNODE_BRACKET || cnode.code == CNODE_BRACE || cnode.code == CNODE_INIT {
|
if cnode.code == CNODE_BRACKET || cnode.code == CNODE_BRACE || cnode.code == CNODE_INIT {
|
||||||
// popping a container feed struct
|
// popping a container feed struct
|
||||||
interp.finalize_feed_struct(feed, true)
|
interp.finalize_feed_struct(feed, true)
|
||||||
@ -452,15 +455,7 @@ func (interp *Interp) pop_feed_struct() *feed_struct_t {
|
|||||||
} else if cnode.code == CNODE_DQUOTE {
|
} else if cnode.code == CNODE_DQUOTE {
|
||||||
interp.finalize_feed_struct(feed, false)
|
interp.finalize_feed_struct(feed, false)
|
||||||
cnode.child = feed.cnode_first
|
cnode.child = feed.cnode_first
|
||||||
} /*else if cnode.code == CNODE_VAR {
|
}
|
||||||
fmt.Printf(">>>>\n")
|
|
||||||
interp.dump_cnodes(parent.cnode_first, true)
|
|
||||||
fmt.Printf(">>>>\n")
|
|
||||||
interp.dump_cnodes(parent.cnode_tmp_first, true)
|
|
||||||
fmt.Printf(">>>>\n")
|
|
||||||
interp.dump_cnodes(cnode, true)
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// add the current cnode to the parent feed struct
|
// add the current cnode to the parent feed struct
|
||||||
interp.add_cnode_to_feed_struct(parent, cnode)
|
interp.add_cnode_to_feed_struct(parent, cnode)
|
||||||
|
@ -54,14 +54,13 @@ type call_frame_t struct {
|
|||||||
type cnode_code_t int
|
type cnode_code_t int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CNODE_INIT cnode_code_t = iota
|
CNODE_INVALID cnode_code_t = iota
|
||||||
|
CNODE_INIT
|
||||||
CNODE_BRACKET
|
CNODE_BRACKET
|
||||||
CNODE_BRACE
|
CNODE_BRACE
|
||||||
CNODE_DQUOTE
|
CNODE_DQUOTE
|
||||||
CNODE_VAR
|
CNODE_VAR
|
||||||
CNODE_TEXT
|
CNODE_TEXT
|
||||||
CNODE_SEP
|
|
||||||
CNODE_EOL
|
|
||||||
CNODE_STMT
|
CNODE_STMT
|
||||||
CNODE_JOIN // merge the two top elements off the stack
|
CNODE_JOIN // merge the two top elements off the stack
|
||||||
)
|
)
|
||||||
@ -329,12 +328,6 @@ func (interp *Interp) __dump_cnodes(node *Cnode_t, nl bool, tabs int) {
|
|||||||
// contained inside other containers, some escaping is required
|
// contained inside other containers, some escaping is required
|
||||||
fmt.Printf("%s", string(node.token))
|
fmt.Printf("%s", string(node.token))
|
||||||
|
|
||||||
case CNODE_SEP:
|
|
||||||
fmt.Printf(" ")
|
|
||||||
|
|
||||||
case CNODE_EOL:
|
|
||||||
fmt.Printf("\n")
|
|
||||||
|
|
||||||
case CNODE_JOIN:
|
case CNODE_JOIN:
|
||||||
// do nothing
|
// do nothing
|
||||||
//fmt.Printf("<M>")
|
//fmt.Printf("<M>")
|
||||||
|
Loading…
Reference in New Issue
Block a user