1
0
Fork 0

Go fmt em all

This commit is contained in:
Gregory Eremin 2014-10-20 22:27:40 +07:00
parent 81068376fa
commit 3c14e17cb1
12 changed files with 1625 additions and 1799 deletions

View File

@ -1,7 +1,6 @@
package errors package errors
import( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/localhots/penny/token" "github.com/localhots/penny/token"

View File

@ -1,12 +1,11 @@
package lexer package lexer
import( import (
"fmt" "fmt"
"github.com/localhots/penny/token" "github.com/localhots/penny/token"
) )
type ActionTable [NumStates] ActionRow type ActionTable [NumStates]ActionRow
type ActionRow struct { type ActionRow struct {
Accept token.Type Accept token.Type
@ -310,5 +309,4 @@ var ActTab = ActionTable{
Accept: 22, Accept: 22,
Ignore: "", Ignore: "",
}, },
} }

View File

@ -1,4 +1,3 @@
package lexer package lexer
import ( import (
@ -6,12 +5,12 @@ import (
// "fmt" // "fmt"
// "github.com/localhots/penny/util" // "github.com/localhots/penny/util"
"github.com/localhots/penny/token"
"io/ioutil" "io/ioutil"
"unicode/utf8" "unicode/utf8"
"github.com/localhots/penny/token"
) )
const( const (
NoState = -1 NoState = -1
NumStates = 73 NumStates = 73
NumSymbols = 90 NumSymbols = 90
@ -77,7 +76,6 @@ func (this *Lexer) Scan() (tok *token.Token) {
this.column++ this.column++
} }
// Production start // Production start
if rune1 != -1 { if rune1 != -1 {
state = TransTab[state](rune1) state = TransTab[state](rune1)
@ -99,7 +97,6 @@ func (this *Lexer) Scan() (tok *token.Token) {
// state = nextState // state = nextState
// Debug end // Debug end
if state != -1 { if state != -1 {
switch { switch {
case ActTab[state].Accept != -1: case ActTab[state].Accept != -1:

View File

@ -1,84 +1,80 @@
package lexer package lexer
/* /*
Let s be the current state Let s be the current state
Let r be the current input rune Let r be the current input rune
transitionTable[s](r) returns the next state. transitionTable[s](r) returns the next state.
*/ */
type TransitionTable [NumStates] func(rune) int type TransitionTable [NumStates]func(rune) int
var TransTab = TransitionTable{ var TransTab = TransitionTable{
// S0 // S0
func(r rune) int { func(r rune) int {
switch { switch {
case r == 9 : // ['\t','\t'] case r == 9: // ['\t','\t']
return 1 return 1
case r == 10 : // ['\n','\n'] case r == 10: // ['\n','\n']
return 1 return 1
case r == 13 : // ['\r','\r'] case r == 13: // ['\r','\r']
return 1 return 1
case r == 32 : // [' ',' '] case r == 32: // [' ',' ']
return 1 return 1
case r == 33 : // ['!','!'] case r == 33: // ['!','!']
return 2 return 2
case r == 38 : // ['&','&'] case r == 38: // ['&','&']
return 3 return 3
case r == 40 : // ['(','('] case r == 40: // ['(','(']
return 4 return 4
case r == 41 : // [')',')'] case r == 41: // [')',')']
return 5 return 5
case 48 <= r && r <= 57 : // ['0','9'] case 48 <= r && r <= 57: // ['0','9']
return 6 return 6
case r == 59 : // [';',';'] case r == 59: // [';',';']
return 7 return 7
case r == 60 : // ['<','<'] case r == 60: // ['<','<']
return 8 return 8
case r == 61 : // ['=','='] case r == 61: // ['=','=']
return 9 return 9
case r == 62 : // ['>','>'] case r == 62: // ['>','>']
return 10 return 10
case r == 92 : // ['\','\'] case r == 92: // ['\','\']
return 11 return 11
case r == 95 : // ['_','_'] case r == 95: // ['_','_']
return 12 return 12
case 97 <= r && r <= 98 : // ['a','b'] case 97 <= r && r <= 98: // ['a','b']
return 13 return 13
case r == 99 : // ['c','c'] case r == 99: // ['c','c']
return 14 return 14
case r == 100 : // ['d','d'] case r == 100: // ['d','d']
return 15 return 15
case r == 101 : // ['e','e'] case r == 101: // ['e','e']
return 16 return 16
case r == 102 : // ['f','f'] case r == 102: // ['f','f']
return 17 return 17
case 103 <= r && r <= 104 : // ['g','h'] case 103 <= r && r <= 104: // ['g','h']
return 13 return 13
case r == 105 : // ['i','i'] case r == 105: // ['i','i']
return 18 return 18
case 106 <= r && r <= 115 : // ['j','s'] case 106 <= r && r <= 115: // ['j','s']
return 13 return 13
case r == 116 : // ['t','t'] case r == 116: // ['t','t']
return 19 return 19
case r == 117 : // ['u','u'] case r == 117: // ['u','u']
return 20 return 20
case r == 118 : // ['v','v'] case r == 118: // ['v','v']
return 13 return 13
case r == 119 : // ['w','w'] case r == 119: // ['w','w']
return 21 return 21
case 120 <= r && r <= 122 : // ['x','z'] case 120 <= r && r <= 122: // ['x','z']
return 13 return 13
case r == 123 : // ['{','{'] case r == 123: // ['{','{']
return 22 return 22
case r == 124 : // ['|','|'] case r == 124: // ['|','|']
return 23 return 23
case r == 125 : // ['}','}'] case r == 125: // ['}','}']
return 24 return 24
default: default:
return 25 return 25
} }
@ -89,8 +85,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -100,8 +94,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -110,11 +102,9 @@ var TransTab = TransitionTable{
// S3 // S3
func(r rune) int { func(r rune) int {
switch { switch {
case r == 38 : // ['&','&'] case r == 38: // ['&','&']
return 26 return 26
} }
return NoState return NoState
@ -124,8 +114,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -135,8 +123,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -145,11 +131,9 @@ var TransTab = TransitionTable{
// S6 // S6
func(r rune) int { func(r rune) int {
switch { switch {
case 48 <= r && r <= 57 : // ['0','9'] case 48 <= r && r <= 57: // ['0','9']
return 6 return 6
} }
return NoState return NoState
@ -158,11 +142,9 @@ var TransTab = TransitionTable{
// S7 // S7
func(r rune) int { func(r rune) int {
switch { switch {
case r == 59 : // [';',';'] case r == 59: // [';',';']
return 27 return 27
} }
return NoState return NoState
@ -171,15 +153,13 @@ var TransTab = TransitionTable{
// S8 // S8
func(r rune) int { func(r rune) int {
switch { switch {
case r == 38 : // ['&','&'] case r == 38: // ['&','&']
return 28 return 28
case r == 60 : // ['<','<'] case r == 60: // ['<','<']
return 29 return 29
case r == 62 : // ['>','>'] case r == 62: // ['>','>']
return 30 return 30
} }
return NoState return NoState
@ -189,8 +169,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -199,15 +177,13 @@ var TransTab = TransitionTable{
// S10 // S10
func(r rune) int { func(r rune) int {
switch { switch {
case r == 38 : // ['&','&'] case r == 38: // ['&','&']
return 31 return 31
case r == 62 : // ['>','>'] case r == 62: // ['>','>']
return 32 return 32
case r == 124 : // ['|','|'] case r == 124: // ['|','|']
return 33 return 33
} }
return NoState return NoState
@ -216,11 +192,9 @@ var TransTab = TransitionTable{
// S11 // S11
func(r rune) int { func(r rune) int {
switch { switch {
case r == 110 : // ['n','n'] case r == 110: // ['n','n']
return 34 return 34
} }
return NoState return NoState
@ -229,15 +203,13 @@ var TransTab = TransitionTable{
// S12 // S12
func(r rune) int { func(r rune) int {
switch { switch {
case 48 <= r && r <= 57 : // ['0','9'] case 48 <= r && r <= 57: // ['0','9']
return 35 return 35
case r == 95 : // ['_','_'] case r == 95: // ['_','_']
return 12 return 12
case 97 <= r && r <= 122 : // ['a','z'] case 97 <= r && r <= 122: // ['a','z']
return 36 return 36
} }
return NoState return NoState
@ -246,11 +218,9 @@ var TransTab = TransitionTable{
// S13 // S13
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
} }
return NoState return NoState
@ -259,13 +229,11 @@ var TransTab = TransitionTable{
// S14 // S14
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 97 : // ['a','a'] case r == 97: // ['a','a']
return 38 return 38
} }
return NoState return NoState
@ -274,13 +242,11 @@ var TransTab = TransitionTable{
// S15 // S15
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 111 : // ['o','o'] case r == 111: // ['o','o']
return 39 return 39
} }
return NoState return NoState
@ -289,15 +255,13 @@ var TransTab = TransitionTable{
// S16 // S16
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 108 : // ['l','l'] case r == 108: // ['l','l']
return 40 return 40
case r == 115 : // ['s','s'] case r == 115: // ['s','s']
return 41 return 41
} }
return NoState return NoState
@ -306,15 +270,13 @@ var TransTab = TransitionTable{
// S17 // S17
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 105 : // ['i','i'] case r == 105: // ['i','i']
return 42 return 42
case r == 111 : // ['o','o'] case r == 111: // ['o','o']
return 43 return 43
} }
return NoState return NoState
@ -323,15 +285,13 @@ var TransTab = TransitionTable{
// S18 // S18
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 102 : // ['f','f'] case r == 102: // ['f','f']
return 44 return 44
case r == 110 : // ['n','n'] case r == 110: // ['n','n']
return 45 return 45
} }
return NoState return NoState
@ -340,13 +300,11 @@ var TransTab = TransitionTable{
// S19 // S19
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 104 : // ['h','h'] case r == 104: // ['h','h']
return 46 return 46
} }
return NoState return NoState
@ -355,13 +313,11 @@ var TransTab = TransitionTable{
// S20 // S20
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 110 : // ['n','n'] case r == 110: // ['n','n']
return 47 return 47
} }
return NoState return NoState
@ -370,13 +326,11 @@ var TransTab = TransitionTable{
// S21 // S21
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
case r == 104 : // ['h','h'] case r == 104: // ['h','h']
return 48 return 48
} }
return NoState return NoState
@ -386,8 +340,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -396,11 +348,9 @@ var TransTab = TransitionTable{
// S23 // S23
func(r rune) int { func(r rune) int {
switch { switch {
case r == 124 : // ['|','|'] case r == 124: // ['|','|']
return 49 return 49
} }
return NoState return NoState
@ -410,8 +360,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -421,8 +369,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -432,8 +378,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -443,8 +387,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -454,8 +396,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -464,11 +404,9 @@ var TransTab = TransitionTable{
// S29 // S29
func(r rune) int { func(r rune) int {
switch { switch {
case r == 45 : // ['-','-'] case r == 45: // ['-','-']
return 50 return 50
} }
return NoState return NoState
@ -478,8 +416,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -489,8 +425,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -500,8 +434,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -511,8 +443,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -522,8 +452,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -532,15 +460,13 @@ var TransTab = TransitionTable{
// S35 // S35
func(r rune) int { func(r rune) int {
switch { switch {
case 48 <= r && r <= 57 : // ['0','9'] case 48 <= r && r <= 57: // ['0','9']
return 35 return 35
case r == 95 : // ['_','_'] case r == 95: // ['_','_']
return 12 return 12
case 97 <= r && r <= 122 : // ['a','z'] case 97 <= r && r <= 122: // ['a','z']
return 36 return 36
} }
return NoState return NoState
@ -549,11 +475,9 @@ var TransTab = TransitionTable{
// S36 // S36
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 51 return 51
} }
return NoState return NoState
@ -562,15 +486,13 @@ var TransTab = TransitionTable{
// S37 // S37
func(r rune) int { func(r rune) int {
switch { switch {
case 48 <= r && r <= 57 : // ['0','9'] case 48 <= r && r <= 57: // ['0','9']
return 35 return 35
case r == 95 : // ['_','_'] case r == 95: // ['_','_']
return 52 return 52
case 97 <= r && r <= 122 : // ['a','z'] case 97 <= r && r <= 122: // ['a','z']
return 53 return 53
} }
return NoState return NoState
@ -579,11 +501,9 @@ var TransTab = TransitionTable{
// S38 // S38
func(r rune) int { func(r rune) int {
switch { switch {
case r == 115 : // ['s','s'] case r == 115: // ['s','s']
return 54 return 54
} }
return NoState return NoState
@ -592,11 +512,9 @@ var TransTab = TransitionTable{
// S39 // S39
func(r rune) int { func(r rune) int {
switch { switch {
case r == 110 : // ['n','n'] case r == 110: // ['n','n']
return 55 return 55
} }
return NoState return NoState
@ -605,13 +523,11 @@ var TransTab = TransitionTable{
// S40 // S40
func(r rune) int { func(r rune) int {
switch { switch {
case r == 105 : // ['i','i'] case r == 105: // ['i','i']
return 56 return 56
case r == 115 : // ['s','s'] case r == 115: // ['s','s']
return 57 return 57
} }
return NoState return NoState
@ -620,11 +536,9 @@ var TransTab = TransitionTable{
// S41 // S41
func(r rune) int { func(r rune) int {
switch { switch {
case r == 97 : // ['a','a'] case r == 97: // ['a','a']
return 58 return 58
} }
return NoState return NoState
@ -634,8 +548,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -644,11 +556,9 @@ var TransTab = TransitionTable{
// S43 // S43
func(r rune) int { func(r rune) int {
switch { switch {
case r == 114 : // ['r','r'] case r == 114: // ['r','r']
return 59 return 59
} }
return NoState return NoState
@ -658,8 +568,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -669,8 +577,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -679,11 +585,9 @@ var TransTab = TransitionTable{
// S46 // S46
func(r rune) int { func(r rune) int {
switch { switch {
case r == 101 : // ['e','e'] case r == 101: // ['e','e']
return 60 return 60
} }
return NoState return NoState
@ -692,11 +596,9 @@ var TransTab = TransitionTable{
// S47 // S47
func(r rune) int { func(r rune) int {
switch { switch {
case r == 116 : // ['t','t'] case r == 116: // ['t','t']
return 61 return 61
} }
return NoState return NoState
@ -705,11 +607,9 @@ var TransTab = TransitionTable{
// S48 // S48
func(r rune) int { func(r rune) int {
switch { switch {
case r == 105 : // ['i','i'] case r == 105: // ['i','i']
return 62 return 62
} }
return NoState return NoState
@ -719,8 +619,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -730,8 +628,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -740,15 +636,13 @@ var TransTab = TransitionTable{
// S51 // S51
func(r rune) int { func(r rune) int {
switch { switch {
case 48 <= r && r <= 57 : // ['0','9'] case 48 <= r && r <= 57: // ['0','9']
return 35 return 35
case r == 95 : // ['_','_'] case r == 95: // ['_','_']
return 12 return 12
case 97 <= r && r <= 122 : // ['a','z'] case 97 <= r && r <= 122: // ['a','z']
return 36 return 36
} }
return NoState return NoState
@ -757,15 +651,13 @@ var TransTab = TransitionTable{
// S52 // S52
func(r rune) int { func(r rune) int {
switch { switch {
case 48 <= r && r <= 57 : // ['0','9'] case 48 <= r && r <= 57: // ['0','9']
return 35 return 35
case r == 95 : // ['_','_'] case r == 95: // ['_','_']
return 52 return 52
case 97 <= r && r <= 122 : // ['a','z'] case 97 <= r && r <= 122: // ['a','z']
return 53 return 53
} }
return NoState return NoState
@ -774,11 +666,9 @@ var TransTab = TransitionTable{
// S53 // S53
func(r rune) int { func(r rune) int {
switch { switch {
case 65 <= r && r <= 90 : // ['A','Z'] case 65 <= r && r <= 90: // ['A','Z']
return 37 return 37
} }
return NoState return NoState
@ -787,11 +677,9 @@ var TransTab = TransitionTable{
// S54 // S54
func(r rune) int { func(r rune) int {
switch { switch {
case r == 101 : // ['e','e'] case r == 101: // ['e','e']
return 63 return 63
} }
return NoState return NoState
@ -800,11 +688,9 @@ var TransTab = TransitionTable{
// S55 // S55
func(r rune) int { func(r rune) int {
switch { switch {
case r == 101 : // ['e','e'] case r == 101: // ['e','e']
return 64 return 64
} }
return NoState return NoState
@ -813,11 +699,9 @@ var TransTab = TransitionTable{
// S56 // S56
func(r rune) int { func(r rune) int {
switch { switch {
case r == 102 : // ['f','f'] case r == 102: // ['f','f']
return 65 return 65
} }
return NoState return NoState
@ -826,11 +710,9 @@ var TransTab = TransitionTable{
// S57 // S57
func(r rune) int { func(r rune) int {
switch { switch {
case r == 101 : // ['e','e'] case r == 101: // ['e','e']
return 66 return 66
} }
return NoState return NoState
@ -839,11 +721,9 @@ var TransTab = TransitionTable{
// S58 // S58
func(r rune) int { func(r rune) int {
switch { switch {
case r == 99 : // ['c','c'] case r == 99: // ['c','c']
return 67 return 67
} }
return NoState return NoState
@ -853,8 +733,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -863,11 +741,9 @@ var TransTab = TransitionTable{
// S60 // S60
func(r rune) int { func(r rune) int {
switch { switch {
case r == 110 : // ['n','n'] case r == 110: // ['n','n']
return 68 return 68
} }
return NoState return NoState
@ -876,11 +752,9 @@ var TransTab = TransitionTable{
// S61 // S61
func(r rune) int { func(r rune) int {
switch { switch {
case r == 105 : // ['i','i'] case r == 105: // ['i','i']
return 69 return 69
} }
return NoState return NoState
@ -889,11 +763,9 @@ var TransTab = TransitionTable{
// S62 // S62
func(r rune) int { func(r rune) int {
switch { switch {
case r == 108 : // ['l','l'] case r == 108: // ['l','l']
return 70 return 70
} }
return NoState return NoState
@ -903,8 +775,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -914,8 +784,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -925,8 +793,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -936,8 +802,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -947,8 +811,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -958,8 +820,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -968,11 +828,9 @@ var TransTab = TransitionTable{
// S69 // S69
func(r rune) int { func(r rune) int {
switch { switch {
case r == 108 : // ['l','l'] case r == 108: // ['l','l']
return 71 return 71
} }
return NoState return NoState
@ -981,11 +839,9 @@ var TransTab = TransitionTable{
// S70 // S70
func(r rune) int { func(r rune) int {
switch { switch {
case r == 101 : // ['e','e'] case r == 101: // ['e','e']
return 72 return 72
} }
return NoState return NoState
@ -995,8 +851,6 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
@ -1006,11 +860,8 @@ var TransTab = TransitionTable{
func(r rune) int { func(r rune) int {
switch { switch {
} }
return NoState return NoState
}, },
} }

View File

@ -1,4 +1,3 @@
package parser package parser
import ( import (

View File

@ -1,7 +1,6 @@
package parser package parser
type( type (
actionTable [numStates]actionRow actionTable [numStates]actionRow
actionRow struct { actionRow struct {
canRecover bool canRecover bool
@ -56,7 +55,6 @@ var actionTab = actionTable{
nil, /* ; */ nil, /* ; */
}, },
}, },
actionRow{ // S1 actionRow{ // S1
canRecover: false, canRecover: false,
@ -104,7 +102,6 @@ var actionTab = actionTable{
nil, /* ; */ nil, /* ; */
}, },
}, },
actionRow{ // S2 actionRow{ // S2
canRecover: false, canRecover: false,
@ -152,8 +149,5 @@ var actionTab = actionTable{
nil, /* ; */ nil, /* ; */
}, },
}, },
} }

View File

@ -1,12 +1,12 @@
/* /*
*/ */
package parser package parser
const numNTSymbols = 47 const numNTSymbols = 47
type(
type (
gotoTable [numStates]gotoRow gotoTable [numStates]gotoRow
gotoRow [numNTSymbols] int gotoRow [numNTSymbols]int
) )
var gotoTab = gotoTable{ var gotoTab = gotoTable{
@ -60,7 +60,6 @@ var gotoTab = gotoTable{
-1, // Separator -1, // Separator
-1, // SequentialSep -1, // SequentialSep
}, },
gotoRow{ // S1 gotoRow{ // S1
@ -112,7 +111,6 @@ var gotoTab = gotoTable{
-1, // Separator -1, // Separator
-1, // SequentialSep -1, // SequentialSep
}, },
gotoRow{ // S2 gotoRow{ // S2
@ -164,7 +162,5 @@ var gotoTab = gotoTable{
-1, // Separator -1, // Separator
-1, // SequentialSep -1, // SequentialSep
}, },
} }

View File

@ -1,10 +1,9 @@
package parser package parser
import( import (
"bytes" "bytes"
"fmt"
"errors" "errors"
"fmt"
parseError "github.com/localhots/penny/errors" parseError "github.com/localhots/penny/errors"
"github.com/localhots/penny/token" "github.com/localhots/penny/token"
) )
@ -25,7 +24,7 @@ type stack struct {
const iNITIAL_STACK_SIZE = 100 const iNITIAL_STACK_SIZE = 100
func newStack() *stack { func newStack() *stack {
return &stack{ state: make([]int, 0, iNITIAL_STACK_SIZE), return &stack{state: make([]int, 0, iNITIAL_STACK_SIZE),
attrib: make([]Attrib, 0, iNITIAL_STACK_SIZE), attrib: make([]Attrib, 0, iNITIAL_STACK_SIZE),
} }
} }
@ -40,8 +39,8 @@ func (this *stack) push(s int, a Attrib) {
this.attrib = append(this.attrib, a) this.attrib = append(this.attrib, a)
} }
func(this *stack) top() int { func (this *stack) top() int {
return this.state[len(this.state) - 1] return this.state[len(this.state)-1]
} }
func (this *stack) peek(pos int) int { func (this *stack) peek(pos int) int {
@ -53,9 +52,9 @@ func (this *stack) topIndex() int {
} }
func (this *stack) popN(items int) []Attrib { func (this *stack) popN(items int) []Attrib {
lo, hi := len(this.state) - items, len(this.state) lo, hi := len(this.state)-items, len(this.state)
attrib := this.attrib[lo: hi] attrib := this.attrib[lo:hi]
this.state = this.state[:lo] this.state = this.state[:lo]
this.attrib = this.attrib[:lo] this.attrib = this.attrib[:lo]
@ -190,7 +189,6 @@ func (this *Parser) Parse(scanner Scanner) (res interface{}, err error) {
// fmt.Printf("S%d %s %s\n", this.stack.top(), token.TokMap.TokenString(this.nextToken), action.String()) // fmt.Printf("S%d %s %s\n", this.stack.top(), token.TokMap.TokenString(this.nextToken), action.String())
switch act := action.(type) { switch act := action.(type) {
case accept: case accept:
res = this.stack.popN(1)[0] res = this.stack.popN(1)[0]

View File

@ -1,4 +1,3 @@
package parser package parser
import "github.com/localhots/penny/ast" import "github.com/localhots/penny/ast"
@ -18,7 +17,7 @@ type (
} }
) )
var productionsTable = ProdTab { var productionsTable = ProdTab{
ProdTabEntry{ ProdTabEntry{
String: `S' : Word << >>`, String: `S' : Word << >>`,
Id: "S'", Id: "S'",
@ -1099,5 +1098,4 @@ var productionsTable = ProdTab {
return X[0], nil return X[0], nil
}, },
}, },
} }

View File

@ -1,7 +1,6 @@
package token package token
import( import (
"fmt" "fmt"
) )
@ -13,7 +12,7 @@ type Token struct {
type Type int type Type int
const( const (
INVALID Type = iota INVALID Type = iota
EOF EOF
) )
@ -101,7 +100,7 @@ var TokMap = TokenMap{
";", ";",
}, },
idMap: map[string]Type { idMap: map[string]Type{
"INVALID": 0, "INVALID": 0,
"$": 1, "$": 1,
"word": 2, "word": 2,
@ -145,4 +144,3 @@ var TokMap = TokenMap{
";": 40, ";": 40,
}, },
} }

View File

@ -1,4 +1,3 @@
//Copyright 2013 Vastech SA (PTY) LTD //Copyright 2013 Vastech SA (PTY) LTD
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,4 +1,3 @@
//Copyright 2013 Vastech SA (PTY) LTD //Copyright 2013 Vastech SA (PTY) LTD
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");