config/lang: add (expr) for order of ops

This commit is contained in:
Mitchell Hashimoto 2015-02-26 14:39:04 -08:00
parent 6750318bb5
commit 3c4a036fb5
4 changed files with 199 additions and 138 deletions

View File

@ -95,6 +95,22 @@ func TestEval(t *testing.T) {
ast.TypeString,
},
{
"foo ${42+2*2}",
nil,
false,
"foo 88",
ast.TypeString,
},
{
"foo ${42+(2*2)}",
nil,
false,
"foo 46",
ast.TypeString,
},
{
"foo ${bar+1}",
&ast.BasicScope{

View File

@ -98,7 +98,11 @@ interpolation:
}
expr:
literalModeTop
PAREN_LEFT expr PAREN_RIGHT
{
$$ = $2
}
| literalModeTop
{
$$ = $1
}

View File

@ -50,7 +50,7 @@ const parserEofCode = 1
const parserErrCode = 2
const parserMaxDepth = 200
//line lang.y:161
//line lang.y:165
//line yacctab:1
var parserExca = []int{
@ -59,51 +59,51 @@ var parserExca = []int{
-2, 0,
}
const parserNprod = 18
const parserNprod = 19
const parserPrivate = 57344
var parserTokenNames []string
var parserStates []string
const parserLast = 26
const parserLast = 30
var parserAct = []int{
9, 7, 7, 15, 3, 20, 21, 8, 14, 13,
11, 12, 6, 6, 15, 8, 17, 19, 16, 10,
2, 1, 22, 18, 4, 5,
9, 20, 16, 16, 7, 7, 3, 18, 10, 8,
1, 17, 14, 12, 13, 6, 6, 19, 8, 22,
15, 23, 24, 11, 2, 25, 16, 21, 4, 5,
}
var parserPact = []int{
-2, -1000, -2, -1000, -1000, -1000, -1000, -3, -1000, 3,
-2, -1000, -1000, 10, -1000, -3, -3, -1000, -4, -8,
-1000, -3, -8,
1, -1000, 1, -1000, -1000, -1000, -1000, 0, -1000, 15,
0, 1, -1000, -1000, -1, -1000, 0, -8, 0, -1000,
-1000, 12, -9, -1000, 0, -9,
}
var parserPgo = []int{
0, 0, 25, 24, 19, 4, 23, 21,
0, 0, 29, 28, 23, 6, 27, 10,
}
var parserR1 = []int{
0, 7, 7, 4, 4, 5, 5, 2, 1, 1,
1, 1, 1, 1, 6, 6, 6, 3,
1, 1, 1, 1, 1, 6, 6, 6, 3,
}
var parserR2 = []int{
0, 0, 1, 1, 2, 1, 1, 3, 1, 1,
1, 3, 1, 4, 0, 3, 1, 1,
0, 0, 1, 1, 2, 1, 1, 3, 3, 1,
1, 1, 3, 1, 4, 0, 3, 1, 1,
}
var parserChk = []int{
-1000, -7, -4, -5, -3, -2, 15, 4, -5, -1,
-4, 13, 14, 12, 5, 11, 8, -1, -6, -1,
9, 10, -1,
8, -4, 13, 14, 12, 5, 11, -1, 8, -1,
9, -6, -1, 9, 10, -1,
}
var parserDef = []int{
1, -2, 2, 3, 5, 6, 17, 0, 4, 0,
8, 9, 10, 12, 7, 0, 14, 11, 0, 16,
13, 0, 15,
1, -2, 2, 3, 5, 6, 18, 0, 4, 0,
0, 9, 10, 11, 13, 7, 0, 0, 15, 12,
8, 0, 17, 14, 0, 16,
}
var parserTok1 = []int{
@ -412,10 +412,15 @@ parserdefault:
case 8:
//line lang.y:102
{
parserVAL.node = parserS[parserpt-0].node
parserVAL.node = parserS[parserpt-1].node
}
case 9:
//line lang.y:106
{
parserVAL.node = parserS[parserpt-0].node
}
case 10:
//line lang.y:110
{
parserVAL.node = &ast.LiteralNode{
Value: parserS[parserpt-0].token.Value.(int),
@ -423,8 +428,8 @@ parserdefault:
Posx: parserS[parserpt-0].token.Pos,
}
}
case 10:
//line lang.y:114
case 11:
//line lang.y:118
{
parserVAL.node = &ast.LiteralNode{
Value: parserS[parserpt-0].token.Value.(float64),
@ -432,8 +437,8 @@ parserdefault:
Posx: parserS[parserpt-0].token.Pos,
}
}
case 11:
//line lang.y:122
case 12:
//line lang.y:126
{
parserVAL.node = &ast.Arithmetic{
Op: parserS[parserpt-1].token.Value.(ast.ArithmeticOp),
@ -441,33 +446,33 @@ parserdefault:
Posx: parserS[parserpt-2].node.Pos(),
}
}
case 12:
//line lang.y:130
{
parserVAL.node = &ast.VariableAccess{Name: parserS[parserpt-0].token.Value.(string), Posx: parserS[parserpt-0].token.Pos}
}
case 13:
//line lang.y:134
{
parserVAL.node = &ast.Call{Func: parserS[parserpt-3].token.Value.(string), Args: parserS[parserpt-1].nodeList, Posx: parserS[parserpt-3].token.Pos}
parserVAL.node = &ast.VariableAccess{Name: parserS[parserpt-0].token.Value.(string), Posx: parserS[parserpt-0].token.Pos}
}
case 14:
//line lang.y:139
//line lang.y:138
{
parserVAL.nodeList = nil
parserVAL.node = &ast.Call{Func: parserS[parserpt-3].token.Value.(string), Args: parserS[parserpt-1].nodeList, Posx: parserS[parserpt-3].token.Pos}
}
case 15:
//line lang.y:143
{
parserVAL.nodeList = append(parserS[parserpt-2].nodeList, parserS[parserpt-0].node)
parserVAL.nodeList = nil
}
case 16:
//line lang.y:147
{
parserVAL.nodeList = append(parserVAL.nodeList, parserS[parserpt-0].node)
parserVAL.nodeList = append(parserS[parserpt-2].nodeList, parserS[parserpt-0].node)
}
case 17:
//line lang.y:153
//line lang.y:151
{
parserVAL.nodeList = append(parserVAL.nodeList, parserS[parserpt-0].node)
}
case 18:
//line lang.y:157
{
parserVAL.node = &ast.LiteralNode{
Value: parserS[parserpt-0].token.Value.(string),

View File

@ -51,25 +51,26 @@ state 5
state 6
literal: STRING. (17)
literal: STRING. (18)
. reduce 17 (src line 151)
. reduce 18 (src line 155)
state 7
interpolation: PROGRAM_BRACKET_LEFT.expr PROGRAM_BRACKET_RIGHT
PROGRAM_BRACKET_LEFT shift 7
IDENTIFIER shift 13
INTEGER shift 11
FLOAT shift 12
PAREN_LEFT shift 10
IDENTIFIER shift 14
INTEGER shift 12
FLOAT shift 13
STRING shift 6
. error
expr goto 9
interpolation goto 5
literal goto 4
literalModeTop goto 10
literalModeTop goto 11
literalModeValue goto 3
state 8
@ -82,146 +83,181 @@ state 9
interpolation: PROGRAM_BRACKET_LEFT expr.PROGRAM_BRACKET_RIGHT
expr: expr.ARITH_OP expr
PROGRAM_BRACKET_RIGHT shift 14
ARITH_OP shift 15
PROGRAM_BRACKET_RIGHT shift 15
ARITH_OP shift 16
. error
state 10
literalModeTop: literalModeTop.literalModeValue
expr: literalModeTop. (8)
expr: PAREN_LEFT.expr PAREN_RIGHT
PROGRAM_BRACKET_LEFT shift 7
STRING shift 6
. reduce 8 (src line 100)
interpolation goto 5
literal goto 4
literalModeValue goto 8
state 11
expr: INTEGER. (9)
. reduce 9 (src line 105)
state 12
expr: FLOAT. (10)
. reduce 10 (src line 113)
state 13
expr: IDENTIFIER. (12)
expr: IDENTIFIER.PAREN_LEFT args PAREN_RIGHT
PAREN_LEFT shift 16
. reduce 12 (src line 129)
state 14
interpolation: PROGRAM_BRACKET_LEFT expr PROGRAM_BRACKET_RIGHT. (7)
. reduce 7 (src line 94)
state 15
expr: expr ARITH_OP.expr
PROGRAM_BRACKET_LEFT shift 7
IDENTIFIER shift 13
INTEGER shift 11
FLOAT shift 12
PAREN_LEFT shift 10
IDENTIFIER shift 14
INTEGER shift 12
FLOAT shift 13
STRING shift 6
. error
expr goto 17
interpolation goto 5
literal goto 4
literalModeTop goto 10
literalModeTop goto 11
literalModeValue goto 3
state 16
expr: IDENTIFIER PAREN_LEFT.args PAREN_RIGHT
args: . (14)
state 11
literalModeTop: literalModeTop.literalModeValue
expr: literalModeTop. (9)
PROGRAM_BRACKET_LEFT shift 7
IDENTIFIER shift 13
INTEGER shift 11
FLOAT shift 12
STRING shift 6
. reduce 14 (src line 138)
. reduce 9 (src line 105)
interpolation goto 5
literal goto 4
literalModeValue goto 8
state 12
expr: INTEGER. (10)
. reduce 10 (src line 109)
state 13
expr: FLOAT. (11)
. reduce 11 (src line 117)
state 14
expr: IDENTIFIER. (13)
expr: IDENTIFIER.PAREN_LEFT args PAREN_RIGHT
PAREN_LEFT shift 18
. reduce 13 (src line 133)
state 15
interpolation: PROGRAM_BRACKET_LEFT expr PROGRAM_BRACKET_RIGHT. (7)
. reduce 7 (src line 94)
state 16
expr: expr ARITH_OP.expr
PROGRAM_BRACKET_LEFT shift 7
PAREN_LEFT shift 10
IDENTIFIER shift 14
INTEGER shift 12
FLOAT shift 13
STRING shift 6
. error
expr goto 19
interpolation goto 5
literal goto 4
literalModeTop goto 10
literalModeTop goto 11
literalModeValue goto 3
args goto 18
state 17
expr: PAREN_LEFT expr.PAREN_RIGHT
expr: expr.ARITH_OP expr
expr: expr ARITH_OP expr. (11)
. reduce 11 (src line 121)
PAREN_RIGHT shift 20
ARITH_OP shift 16
. error
state 18
expr: IDENTIFIER PAREN_LEFT args.PAREN_RIGHT
args: args.COMMA expr
PAREN_RIGHT shift 20
COMMA shift 21
. error
state 19
expr: expr.ARITH_OP expr
args: expr. (16)
ARITH_OP shift 15
. reduce 16 (src line 146)
state 20
expr: IDENTIFIER PAREN_LEFT args PAREN_RIGHT. (13)
. reduce 13 (src line 133)
state 21
args: args COMMA.expr
expr: IDENTIFIER PAREN_LEFT.args PAREN_RIGHT
args: . (15)
PROGRAM_BRACKET_LEFT shift 7
IDENTIFIER shift 13
INTEGER shift 11
FLOAT shift 12
PAREN_LEFT shift 10
IDENTIFIER shift 14
INTEGER shift 12
FLOAT shift 13
STRING shift 6
. error
. reduce 15 (src line 142)
expr goto 22
interpolation goto 5
literal goto 4
literalModeTop goto 10
literalModeTop goto 11
literalModeValue goto 3
args goto 21
state 19
expr: expr.ARITH_OP expr
expr: expr ARITH_OP expr. (12)
. reduce 12 (src line 125)
state 20
expr: PAREN_LEFT expr PAREN_RIGHT. (8)
. reduce 8 (src line 100)
state 21
expr: IDENTIFIER PAREN_LEFT args.PAREN_RIGHT
args: args.COMMA expr
PAREN_RIGHT shift 23
COMMA shift 24
. error
state 22
expr: expr.ARITH_OP expr
args: args COMMA expr. (15)
args: expr. (17)
ARITH_OP shift 15
. reduce 15 (src line 142)
ARITH_OP shift 16
. reduce 17 (src line 150)
state 23
expr: IDENTIFIER PAREN_LEFT args PAREN_RIGHT. (14)
. reduce 14 (src line 137)
state 24
args: args COMMA.expr
PROGRAM_BRACKET_LEFT shift 7
PAREN_LEFT shift 10
IDENTIFIER shift 14
INTEGER shift 12
FLOAT shift 13
STRING shift 6
. error
expr goto 25
interpolation goto 5
literal goto 4
literalModeTop goto 11
literalModeValue goto 3
state 25
expr: expr.ARITH_OP expr
args: args COMMA expr. (16)
ARITH_OP shift 16
. reduce 16 (src line 146)
15 terminals, 8 nonterminals
18 grammar rules, 23/2000 states
19 grammar rules, 26/2000 states
0 shift/reduce, 0 reduce/reduce conflicts reported
57 working sets used
memory: parser 30/30000
18 extra closures
33 shift entries, 1 exceptions
13 goto entries
19 entries saved by goto default
Optimizer space used: output 26/30000
26 table entries, 0 zero
maximum spread: 15, maximum offset: 21
memory: parser 35/30000
21 extra closures
45 shift entries, 1 exceptions
14 goto entries
23 entries saved by goto default
Optimizer space used: output 30/30000
30 table entries, 0 zero
maximum spread: 15, maximum offset: 24