Skip to content

Commit

Permalink
Call two sides of Assignment and Redir simply Left and Right.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaq committed Feb 13, 2017
1 parent 01794c5 commit e1dc20e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions edit/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func (s *Highlighter) highlight(n parse.Node) {
switch n := n.(type) {
case *parse.Form:
for _, an := range n.Assignments {
if an.Dst != nil && an.Dst.Head != nil {
v := an.Dst.Head
if an.Left != nil && an.Left.Head != nil {
v := an.Left.Head
s.addStyling(v.Begin(), v.End(), styleForGoodVariable.String())
}
}
Expand Down
14 changes: 7 additions & 7 deletions eval/compile-op.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (cp *compiler) form(n *parse.Form) OpFunc {
}
} else {
for _, a := range n.Assignments {
v, r := cp.lvaluesOp(a.Dst)
v, r := cp.lvaluesOp(a.Left)
saveVarsOps = append(saveVarsOps, v, r)
}
Logger.Println("temporary assignment of", len(n.Assignments), "pairs")
Expand Down Expand Up @@ -431,8 +431,8 @@ func (cp *compiler) control(n *parse.Control) OpFunc {
}

func (cp *compiler) assignment(n *parse.Assignment) OpFunc {
variablesOp, restOp := cp.lvaluesOp(n.Dst)
valuesOp := cp.compoundOp(n.Src)
variablesOp, restOp := cp.lvaluesOp(n.Left)
valuesOp := cp.compoundOp(n.Right)
return makeAssignmentOpFunc(variablesOp, restOp, valuesOp)
}

Expand Down Expand Up @@ -498,11 +498,11 @@ const defaultFileRedirPerm = 0644
// redir compiles a Redir into a op.
func (cp *compiler) redir(n *parse.Redir) OpFunc {
var dstOp ValuesOp
if n.Dest != nil {
dstOp = cp.compoundOp(n.Dest)
if n.Left != nil {
dstOp = cp.compoundOp(n.Left)
}
srcOp := cp.compoundOp(n.Source)
sourceIsFd := n.SourceIsFd
srcOp := cp.compoundOp(n.Right)
sourceIsFd := n.RightIsFd
mode := n.Mode
flag := makeFlag(mode)

Expand Down
16 changes: 8 additions & 8 deletions parse/boilerplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ func GetAssignment(n Node) *Assignment {
return nil
}

func (n *Assignment) setDst(ch *Indexing) {
n.Dst = ch
func (n *Assignment) setLeft(ch *Indexing) {
n.Left = ch
addChild(n, ch)
}

func (n *Assignment) setSrc(ch *Compound) {
n.Src = ch
func (n *Assignment) setRight(ch *Compound) {
n.Right = ch
addChild(n, ch)
}

Expand Down Expand Up @@ -247,13 +247,13 @@ func GetRedir(n Node) *Redir {
return nil
}

func (n *Redir) setDest(ch *Compound) {
n.Dest = ch
func (n *Redir) setLeft(ch *Compound) {
n.Left = ch
addChild(n, ch)
}

func (n *Redir) setSource(ch *Compound) {
n.Source = ch
func (n *Redir) setRight(ch *Compound) {
n.Right = ch
addChild(n, ch)
}

Expand Down
30 changes: 15 additions & 15 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ func startsForm(r rune) bool {
// Assignment = Indexing '=' Compound
type Assignment struct {
node
Dst *Indexing
Src *Compound
Left *Indexing
Right *Compound
}

func (an *Assignment) parse(ps *parser) {
ps.cut('=')
an.setDst(parseIndexing(ps, false))
head := an.Dst.Head
an.setLeft(parseIndexing(ps, false))
head := an.Left.Head
if !checkVariableInAssignment(head, ps) {
ps.errorp(head.Begin(), head.End(), errShouldBeVariableName)
}
Expand All @@ -320,7 +320,7 @@ func (an *Assignment) parse(ps *parser) {
if !parseSep(an, ps, '=') {
ps.error(errShouldBeEqual)
}
an.setSrc(parseCompound(ps, false))
an.setRight(parseCompound(ps, false))
}

func checkVariableInAssignment(p *Primary, ps *parser) bool {
Expand Down Expand Up @@ -521,16 +521,16 @@ func (ern *ExitusRedir) parse(ps *parser) {
// Redir = { Compound } { '<'|'>'|'<>'|'>>' } { Space } ( '&'? Compound )
type Redir struct {
node
Dest *Compound
Mode RedirMode
SourceIsFd bool
Source *Compound
Left *Compound
Mode RedirMode
RightIsFd bool
Right *Compound
}

func (rn *Redir) parse(ps *parser, dest *Compound) {
// The parsing of the Dest part is done in Form.parse.
// The parsing of the Left part is done in Form.parse.
if dest != nil {
rn.setDest(dest)
rn.setLeft(dest)
rn.begin = dest.begin
}

Expand All @@ -554,11 +554,11 @@ func (rn *Redir) parse(ps *parser, dest *Compound) {
addSep(rn, ps)
parseSpaces(rn, ps)
if parseSep(rn, ps, '&') {
rn.SourceIsFd = true
rn.RightIsFd = true
}
rn.setSource(parseCompound(ps, false))
if len(rn.Source.Indexings) == 0 {
if rn.SourceIsFd {
rn.setRight(parseCompound(ps, false))
if len(rn.Right.Indexings) == 0 {
if rn.RightIsFd {
ps.error(errShouldBeFD)
} else {
ps.error(errShouldBeFilename)
Expand Down
14 changes: 7 additions & 7 deletions parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ var goodCases = []struct {
{"a >b", ast{"Chunk/Pipeline/Form", fs{
"Head": "a",
"Redirs": []ast{
ast{"Redir", fs{"Mode": Write, "Source": "b"}}},
ast{"Redir", fs{"Mode": Write, "Right": "b"}}},
}}},
// More redirections
{"a >>b 2>b 3>&- 4>&1 5<c 6<>d", ast{"Chunk/Pipeline/Form", fs{
"Head": "a",
"Redirs": []ast{
ast{"Redir", fs{"Mode": Append, "Source": "b"}},
ast{"Redir", fs{"Dest": "2", "Mode": Write, "Source": "b"}},
ast{"Redir", fs{"Dest": "3", "Mode": Write, "SourceIsFd": true, "Source": "-"}},
ast{"Redir", fs{"Dest": "4", "Mode": Write, "SourceIsFd": true, "Source": "1"}},
ast{"Redir", fs{"Dest": "5", "Mode": Read, "Source": "c"}},
ast{"Redir", fs{"Dest": "6", "Mode": ReadWrite, "Source": "d"}},
ast{"Redir", fs{"Mode": Append, "Right": "b"}},
ast{"Redir", fs{"Left": "2", "Mode": Write, "Right": "b"}},
ast{"Redir", fs{"Left": "3", "Mode": Write, "RightIsFd": true, "Right": "-"}},
ast{"Redir", fs{"Left": "4", "Mode": Write, "RightIsFd": true, "Right": "1"}},
ast{"Redir", fs{"Left": "5", "Mode": Read, "Right": "c"}},
ast{"Redir", fs{"Left": "6", "Mode": ReadWrite, "Right": "d"}},
},
}}},
// Exitus redirection
Expand Down

0 comments on commit e1dc20e

Please sign in to comment.