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
import(
import (
"bytes"
"fmt"
"github.com/localhots/penny/token"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,9 @@
package parser
import(
import (
"bytes"
"fmt"
"errors"
"fmt"
parseError "github.com/localhots/penny/errors"
"github.com/localhots/penny/token"
)
@ -25,7 +24,7 @@ type stack struct {
const iNITIAL_STACK_SIZE = 100
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),
}
}
@ -40,8 +39,8 @@ func (this *stack) push(s int, a Attrib) {
this.attrib = append(this.attrib, a)
}
func(this *stack) top() int {
return this.state[len(this.state) - 1]
func (this *stack) top() int {
return this.state[len(this.state)-1]
}
func (this *stack) peek(pos int) int {
@ -53,9 +52,9 @@ func (this *stack) topIndex() int {
}
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.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())
switch act := action.(type) {
case accept:
res = this.stack.popN(1)[0]

View File

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

View File

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

View File

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

View File

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