config/lang: fix bug parsing empty strings

This commit is contained in:
Mitchell Hashimoto 2015-01-13 10:27:31 -08:00
parent c424a8a815
commit e68fbceebc
4 changed files with 101 additions and 74 deletions

View File

@ -30,7 +30,14 @@ import (
%%
top:
literalModeTop
{
parserResult = &ast.LiteralNode{
Value: "",
Type: ast.TypeString,
Posx: ast.Pos{Column: 1, Line: 1},
}
}
| literalModeTop
{
parserResult = $1
}

View File

@ -13,6 +13,16 @@ func TestParse(t *testing.T) {
Error bool
Result ast.Node
}{
{
"",
false,
&ast.LiteralNode{
Value: "",
Type: ast.TypeString,
Posx: ast.Pos{Column: 1, Line: 1},
},
},
{
"foo",
false,

View File

@ -48,7 +48,7 @@ const parserEofCode = 1
const parserErrCode = 2
const parserMaxDepth = 200
//line lang.y:127
//line lang.y:134
//line yacctab:1
var parserExca = []int{
@ -57,7 +57,7 @@ var parserExca = []int{
-2, 0,
}
const parserNprod = 16
const parserNprod = 17
const parserPrivate = 57344
var parserTokenNames []string
@ -83,13 +83,13 @@ var parserPgo = []int{
}
var parserR1 = []int{
0, 7, 4, 4, 5, 5, 2, 1, 1, 1,
1, 1, 6, 6, 6, 3,
0, 7, 7, 4, 4, 5, 5, 2, 1, 1,
1, 1, 1, 6, 6, 6, 3,
}
var parserR2 = []int{
0, 1, 1, 2, 1, 1, 3, 1, 1, 1,
1, 4, 0, 3, 1, 1,
0, 0, 1, 1, 2, 1, 1, 3, 1, 1,
1, 1, 4, 0, 3, 1, 1,
}
var parserChk = []int{
@ -99,9 +99,9 @@ var parserChk = []int{
}
var parserDef = []int{
0, -2, 1, 2, 4, 5, 15, 0, 3, 0,
7, 8, 9, 10, 6, 12, 0, 14, 11, 0,
13,
1, -2, 2, 3, 5, 6, 16, 0, 4, 0,
8, 9, 10, 11, 7, 13, 0, 15, 12, 0,
14,
}
var parserTok1 = []int{
@ -342,17 +342,26 @@ parserdefault:
switch parsernt {
case 1:
//line lang.y:34
//line lang.y:33
{
parserResult = &ast.LiteralNode{
Value: "",
Type: ast.TypeString,
Posx: ast.Pos{Column: 1, Line: 1},
}
}
case 2:
//line lang.y:41
{
parserResult = parserS[parserpt-0].node
}
case 2:
//line lang.y:40
case 3:
//line lang.y:47
{
parserVAL.node = parserS[parserpt-0].node
}
case 3:
//line lang.y:44
case 4:
//line lang.y:51
{
var result []ast.Node
if c, ok := parserS[parserpt-1].node.(*ast.Concat); ok {
@ -366,28 +375,28 @@ parserdefault:
Posx: result[0].Pos(),
}
}
case 4:
//line lang.y:60
{
parserVAL.node = parserS[parserpt-0].node
}
case 5:
//line lang.y:64
//line lang.y:67
{
parserVAL.node = parserS[parserpt-0].node
}
case 6:
//line lang.y:70
{
parserVAL.node = parserS[parserpt-1].node
}
case 7:
//line lang.y:76
//line lang.y:71
{
parserVAL.node = parserS[parserpt-0].node
}
case 7:
//line lang.y:77
{
parserVAL.node = parserS[parserpt-1].node
}
case 8:
//line lang.y:80
//line lang.y:83
{
parserVAL.node = parserS[parserpt-0].node
}
case 9:
//line lang.y:87
{
parserVAL.node = &ast.LiteralNode{
Value: parserS[parserpt-0].token.Value.(int),
@ -395,8 +404,8 @@ parserdefault:
Posx: parserS[parserpt-0].token.Pos,
}
}
case 9:
//line lang.y:88
case 10:
//line lang.y:95
{
parserVAL.node = &ast.LiteralNode{
Value: parserS[parserpt-0].token.Value.(float64),
@ -404,33 +413,33 @@ parserdefault:
Posx: parserS[parserpt-0].token.Pos,
}
}
case 10:
//line lang.y:96
case 11:
//line lang.y:103
{
parserVAL.node = &ast.VariableAccess{Name: parserS[parserpt-0].token.Value.(string), Posx: parserS[parserpt-0].token.Pos}
}
case 11:
//line lang.y:100
case 12:
//line lang.y:107
{
parserVAL.node = &ast.Call{Func: parserS[parserpt-3].token.Value.(string), Args: parserS[parserpt-1].nodeList, Posx: parserS[parserpt-3].token.Pos}
}
case 12:
//line lang.y:105
case 13:
//line lang.y:112
{
parserVAL.nodeList = nil
}
case 13:
//line lang.y:109
case 14:
//line lang.y:116
{
parserVAL.nodeList = append(parserS[parserpt-2].nodeList, parserS[parserpt-0].node)
}
case 14:
//line lang.y:113
case 15:
//line lang.y:120
{
parserVAL.nodeList = append(parserVAL.nodeList, parserS[parserpt-0].node)
}
case 15:
//line lang.y:119
case 16:
//line lang.y:126
{
parserVAL.node = &ast.LiteralNode{
Value: parserS[parserpt-0].token.Value.(string),

View File

@ -1,10 +1,11 @@
state 0
$accept: .top $end
top: . (1)
PROGRAM_BRACKET_LEFT shift 7
STRING shift 6
. error
. reduce 1 (src line 32)
interpolation goto 5
literal goto 4
@ -20,39 +21,39 @@ state 1
state 2
top: literalModeTop. (1)
top: literalModeTop. (2)
literalModeTop: literalModeTop.literalModeValue
PROGRAM_BRACKET_LEFT shift 7
STRING shift 6
. reduce 1 (src line 32)
. reduce 2 (src line 40)
interpolation goto 5
literal goto 4
literalModeValue goto 8
state 3
literalModeTop: literalModeValue. (2)
literalModeTop: literalModeValue. (3)
. reduce 2 (src line 38)
. reduce 3 (src line 45)
state 4
literalModeValue: literal. (4)
literalModeValue: literal. (5)
. reduce 4 (src line 58)
. reduce 5 (src line 65)
state 5
literalModeValue: interpolation. (5)
literalModeValue: interpolation. (6)
. reduce 5 (src line 63)
. reduce 6 (src line 70)
state 6
literal: STRING. (15)
literal: STRING. (16)
. reduce 15 (src line 117)
. reduce 16 (src line 124)
state 7
@ -72,9 +73,9 @@ state 7
literalModeValue goto 3
state 8
literalModeTop: literalModeTop literalModeValue. (3)
literalModeTop: literalModeTop literalModeValue. (4)
. reduce 3 (src line 43)
. reduce 4 (src line 50)
state 9
@ -86,52 +87,52 @@ state 9
state 10
literalModeTop: literalModeTop.literalModeValue
expr: literalModeTop. (7)
expr: literalModeTop. (8)
PROGRAM_BRACKET_LEFT shift 7
STRING shift 6
. reduce 7 (src line 74)
. reduce 8 (src line 81)
interpolation goto 5
literal goto 4
literalModeValue goto 8
state 11
expr: INTEGER. (8)
expr: INTEGER. (9)
. reduce 8 (src line 79)
. reduce 9 (src line 86)
state 12
expr: FLOAT. (9)
expr: FLOAT. (10)
. reduce 9 (src line 87)
. reduce 10 (src line 94)
state 13
expr: IDENTIFIER. (10)
expr: IDENTIFIER. (11)
expr: IDENTIFIER.PAREN_LEFT args PAREN_RIGHT
PAREN_LEFT shift 15
. reduce 10 (src line 95)
. reduce 11 (src line 102)
state 14
interpolation: PROGRAM_BRACKET_LEFT expr PROGRAM_BRACKET_RIGHT. (6)
interpolation: PROGRAM_BRACKET_LEFT expr PROGRAM_BRACKET_RIGHT. (7)
. reduce 6 (src line 68)
. reduce 7 (src line 75)
state 15
expr: IDENTIFIER PAREN_LEFT.args PAREN_RIGHT
args: . (12)
args: . (13)
PROGRAM_BRACKET_LEFT shift 7
IDENTIFIER shift 13
INTEGER shift 11
FLOAT shift 12
STRING shift 6
. reduce 12 (src line 104)
. reduce 13 (src line 111)
expr goto 17
interpolation goto 5
@ -150,15 +151,15 @@ state 16
state 17
args: expr. (14)
args: expr. (15)
. reduce 14 (src line 112)
. reduce 15 (src line 119)
state 18
expr: IDENTIFIER PAREN_LEFT args PAREN_RIGHT. (11)
expr: IDENTIFIER PAREN_LEFT args PAREN_RIGHT. (12)
. reduce 11 (src line 99)
. reduce 12 (src line 106)
state 19
@ -178,13 +179,13 @@ state 19
literalModeValue goto 3
state 20
args: args COMMA expr. (13)
args: args COMMA expr. (14)
. reduce 13 (src line 108)
. reduce 14 (src line 115)
14 terminals, 8 nonterminals
16 grammar rules, 21/2000 states
17 grammar rules, 21/2000 states
0 shift/reduce, 0 reduce/reduce conflicts reported
57 working sets used
memory: parser 25/30000