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
@ -18,297 +17,296 @@ func (this ActionRow) String() string {
}
var ActTab = ActionTable{
ActionRow{ // S0
ActionRow{ // S0
Accept: 0,
Ignore: "",
},
ActionRow{ // S1
Ignore: "",
},
ActionRow{ // S1
Accept: -1,
Ignore: "!whitespace",
},
ActionRow{ // S2
Ignore: "!whitespace",
},
ActionRow{ // S2
Accept: 7,
Ignore: "",
},
ActionRow{ // S3
Ignore: "",
},
ActionRow{ // S3
Accept: 39,
Ignore: "",
},
ActionRow{ // S4
Ignore: "",
},
ActionRow{ // S4
Accept: 9,
Ignore: "",
},
ActionRow{ // S5
Ignore: "",
},
ActionRow{ // S5
Accept: 10,
Ignore: "",
},
ActionRow{ // S6
Ignore: "",
},
ActionRow{ // S6
Accept: 3,
Ignore: "",
},
ActionRow{ // S7
Ignore: "",
},
ActionRow{ // S7
Accept: 40,
Ignore: "",
},
ActionRow{ // S8
Ignore: "",
},
ActionRow{ // S8
Accept: 28,
Ignore: "",
},
ActionRow{ // S9
Ignore: "",
},
ActionRow{ // S9
Accept: 4,
Ignore: "",
},
ActionRow{ // S10
Ignore: "",
},
ActionRow{ // S10
Accept: 30,
Ignore: "",
},
ActionRow{ // S11
Ignore: "",
},
ActionRow{ // S11
Accept: 0,
Ignore: "",
},
ActionRow{ // S12
Ignore: "",
},
ActionRow{ // S12
Accept: 13,
Ignore: "",
},
ActionRow{ // S13
Ignore: "",
},
ActionRow{ // S13
Accept: 0,
Ignore: "",
},
ActionRow{ // S14
Ignore: "",
},
ActionRow{ // S14
Accept: 0,
Ignore: "",
},
ActionRow{ // S15
Ignore: "",
},
ActionRow{ // S15
Accept: 0,
Ignore: "",
},
ActionRow{ // S16
Ignore: "",
},
ActionRow{ // S16
Accept: 0,
Ignore: "",
},
ActionRow{ // S17
Ignore: "",
},
ActionRow{ // S17
Accept: 0,
Ignore: "",
},
ActionRow{ // S18
Ignore: "",
},
ActionRow{ // S18
Accept: 0,
Ignore: "",
},
ActionRow{ // S19
Ignore: "",
},
ActionRow{ // S19
Accept: 0,
Ignore: "",
},
ActionRow{ // S20
Ignore: "",
},
ActionRow{ // S20
Accept: 0,
Ignore: "",
},
ActionRow{ // S21
Ignore: "",
},
ActionRow{ // S21
Accept: 0,
Ignore: "",
},
ActionRow{ // S22
Ignore: "",
},
ActionRow{ // S22
Accept: 24,
Ignore: "",
},
ActionRow{ // S23
Ignore: "",
},
ActionRow{ // S23
Accept: 8,
Ignore: "",
},
ActionRow{ // S24
Ignore: "",
},
ActionRow{ // S24
Accept: 25,
Ignore: "",
},
ActionRow{ // S25
Ignore: "",
},
ActionRow{ // S25
Accept: 38,
Ignore: "",
},
ActionRow{ // S26
Ignore: "",
},
ActionRow{ // S26
Accept: 5,
Ignore: "",
},
ActionRow{ // S27
Ignore: "",
},
ActionRow{ // S27
Accept: 16,
Ignore: "",
},
ActionRow{ // S28
Ignore: "",
},
ActionRow{ // S28
Accept: 29,
Ignore: "",
},
ActionRow{ // S29
Ignore: "",
},
ActionRow{ // S29
Accept: 35,
Ignore: "",
},
ActionRow{ // S30
Ignore: "",
},
ActionRow{ // S30
Accept: 33,
Ignore: "",
},
ActionRow{ // S31
Ignore: "",
},
ActionRow{ // S31
Accept: 31,
Ignore: "",
},
ActionRow{ // S32
Ignore: "",
},
ActionRow{ // S32
Accept: 32,
Ignore: "",
},
ActionRow{ // S33
Ignore: "",
},
ActionRow{ // S33
Accept: 34,
Ignore: "",
},
ActionRow{ // S34
Ignore: "",
},
ActionRow{ // S34
Accept: 37,
Ignore: "",
},
ActionRow{ // S35
Ignore: "",
},
ActionRow{ // S35
Accept: 13,
Ignore: "",
},
ActionRow{ // S36
Ignore: "",
},
ActionRow{ // S36
Accept: 0,
Ignore: "",
},
ActionRow{ // S37
Ignore: "",
},
ActionRow{ // S37
Accept: 2,
Ignore: "",
},
ActionRow{ // S38
Ignore: "",
},
ActionRow{ // S38
Accept: 0,
Ignore: "",
},
ActionRow{ // S39
Ignore: "",
},
ActionRow{ // S39
Accept: 26,
Ignore: "",
},
ActionRow{ // S40
Ignore: "",
},
ActionRow{ // S40
Accept: 0,
Ignore: "",
},
ActionRow{ // S41
Ignore: "",
},
ActionRow{ // S41
Accept: 0,
Ignore: "",
},
ActionRow{ // S42
Ignore: "",
},
ActionRow{ // S42
Accept: 19,
Ignore: "",
},
ActionRow{ // S43
Ignore: "",
},
ActionRow{ // S43
Accept: 0,
Ignore: "",
},
ActionRow{ // S44
Ignore: "",
},
ActionRow{ // S44
Accept: 17,
Ignore: "",
},
ActionRow{ // S45
Ignore: "",
},
ActionRow{ // S45
Accept: 12,
Ignore: "",
},
ActionRow{ // S46
Ignore: "",
},
ActionRow{ // S46
Accept: 0,
Ignore: "",
},
ActionRow{ // S47
Ignore: "",
},
ActionRow{ // S47
Accept: 0,
Ignore: "",
},
ActionRow{ // S48
Ignore: "",
},
ActionRow{ // S48
Accept: 0,
Ignore: "",
},
ActionRow{ // S49
Ignore: "",
},
ActionRow{ // S49
Accept: 6,
Ignore: "",
},
ActionRow{ // S50
Ignore: "",
},
ActionRow{ // S50
Accept: 36,
Ignore: "",
},
ActionRow{ // S51
Ignore: "",
},
ActionRow{ // S51
Accept: 13,
Ignore: "",
},
ActionRow{ // S52
Ignore: "",
},
ActionRow{ // S52
Accept: 2,
Ignore: "",
},
ActionRow{ // S53
Ignore: "",
},
ActionRow{ // S53
Accept: 0,
Ignore: "",
},
ActionRow{ // S54
Ignore: "",
},
ActionRow{ // S54
Accept: 0,
Ignore: "",
},
ActionRow{ // S55
Ignore: "",
},
ActionRow{ // S55
Accept: 0,
Ignore: "",
},
ActionRow{ // S56
Ignore: "",
},
ActionRow{ // S56
Accept: 0,
Ignore: "",
},
ActionRow{ // S57
Ignore: "",
},
ActionRow{ // S57
Accept: 0,
Ignore: "",
},
ActionRow{ // S58
Ignore: "",
},
ActionRow{ // S58
Accept: 0,
Ignore: "",
},
ActionRow{ // S59
Ignore: "",
},
ActionRow{ // S59
Accept: 11,
Ignore: "",
},
ActionRow{ // S60
Ignore: "",
},
ActionRow{ // S60
Accept: 0,
Ignore: "",
},
ActionRow{ // S61
Ignore: "",
},
ActionRow{ // S61
Accept: 0,
Ignore: "",
},
ActionRow{ // S62
Ignore: "",
},
ActionRow{ // S62
Accept: 0,
Ignore: "",
},
ActionRow{ // S63
Ignore: "",
},
ActionRow{ // S63
Accept: 14,
Ignore: "",
},
ActionRow{ // S64
Ignore: "",
},
ActionRow{ // S64
Accept: 27,
Ignore: "",
},
ActionRow{ // S65
Ignore: "",
},
ActionRow{ // S65
Accept: 20,
Ignore: "",
},
ActionRow{ // S66
Ignore: "",
},
ActionRow{ // S66
Accept: 21,
Ignore: "",
},
ActionRow{ // S67
Ignore: "",
},
ActionRow{ // S67
Accept: 15,
Ignore: "",
},
ActionRow{ // S68
Ignore: "",
},
ActionRow{ // S68
Accept: 18,
Ignore: "",
},
ActionRow{ // S69
Ignore: "",
},
ActionRow{ // S69
Accept: 0,
Ignore: "",
},
ActionRow{ // S70
Ignore: "",
},
ActionRow{ // S70
Accept: 0,
Ignore: "",
},
ActionRow{ // S71
Ignore: "",
},
ActionRow{ // S71
Accept: 23,
Ignore: "",
},
ActionRow{ // S72
Ignore: "",
},
ActionRow{ // S72
Accept: 22,
Ignore: "",
},
Ignore: "",
},
}

View File

@ -1,27 +1,26 @@
package lexer
import (
// "fmt"
// "github.com/localhots/penny/util"
"github.com/localhots/penny/token"
"io/ioutil"
"unicode/utf8"
"github.com/localhots/penny/token"
)
const(
NoState = -1
NumStates = 73
const (
NoState = -1
NumStates = 73
NumSymbols = 90
)
)
type Lexer struct {
src []byte
pos int
line int
column int
src []byte
pos int
line int
column int
}
func NewLexer(src []byte) *Lexer {
@ -43,9 +42,9 @@ func NewLexerFile(fpath string) (*Lexer, error) {
}
func (this *Lexer) Scan() (tok *token.Token) {
// fmt.Printf("Lexer.Scan() pos=%d\n", this.pos)
tok = new(token.Token)
if this.pos >= len(this.src) {
tok.Type = token.EOF
@ -56,9 +55,9 @@ func (this *Lexer) Scan() (tok *token.Token) {
tok.Type = token.INVALID
state, rune1, size := 0, rune(-1), 0
for state != -1 {
// fmt.Printf("\tpos=%d, line=%d, col=%d, state=%d\n", this.pos, this.line, this.column, state)
if this.pos >= len(this.src) {
rune1 = -1
} else {
@ -77,7 +76,6 @@ func (this *Lexer) Scan() (tok *token.Token) {
this.column++
}
// Production start
if rune1 != -1 {
state = TransTab[state](rune1)
@ -98,7 +96,6 @@ func (this *Lexer) Scan() (tok *token.Token) {
// }
// state = nextState
// Debug end
if state != -1 {
switch {

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,159 +1,153 @@
package parser
type(
type (
actionTable [numStates]actionRow
actionRow struct {
actionRow struct {
canRecover bool
actions [numSymbols]action
actions [numSymbols]action
}
)
var actionTab = actionTable{
actionRow{ // S0
canRecover: false,
canRecover: false,
actions: [numSymbols]action{
nil, /* INVALID */
nil, /* $ */
shift(2), /* word */
nil, /* number */
nil, /* = */
nil, /* && */
nil, /* || */
nil, /* ! */
nil, /* | */
nil, /* ( */
nil, /* ) */
nil, /* for */
nil, /* in */
nil, /* name */
nil, /* case */
nil, /* esac */
nil, /* ;; */
nil, /* if */
nil, /* then */
nil, /* fi */
nil, /* elif */
nil, /* else */
nil, /* while */
nil, /* until */
nil, /* { */
nil, /* } */
nil, /* do */
nil, /* done */
nil, /* < */
nil, /* <& */
nil, /* > */
nil, /* >& */
nil, /* >> */
nil, /* <> */
nil, /* >| */
nil, /* << */
nil, /* <<- */
nil, /* \n */
nil, /* nothing */
nil, /* & */
nil, /* ; */
},
nil, /* INVALID */
nil, /* $ */
shift(2), /* word */
nil, /* number */
nil, /* = */
nil, /* && */
nil, /* || */
nil, /* ! */
nil, /* | */
nil, /* ( */
nil, /* ) */
nil, /* for */
nil, /* in */
nil, /* name */
nil, /* case */
nil, /* esac */
nil, /* ;; */
nil, /* if */
nil, /* then */
nil, /* fi */
nil, /* elif */
nil, /* else */
nil, /* while */
nil, /* until */
nil, /* { */
nil, /* } */
nil, /* do */
nil, /* done */
nil, /* < */
nil, /* <& */
nil, /* > */
nil, /* >& */
nil, /* >> */
nil, /* <> */
nil, /* >| */
nil, /* << */
nil, /* <<- */
nil, /* \n */
nil, /* nothing */
nil, /* & */
nil, /* ; */
},
},
actionRow{ // S1
canRecover: false,
canRecover: false,
actions: [numSymbols]action{
nil, /* INVALID */
accept(true), /* $ */
nil, /* word */
nil, /* number */
nil, /* = */
nil, /* && */
nil, /* || */
nil, /* ! */
nil, /* | */
nil, /* ( */
nil, /* ) */
nil, /* for */
nil, /* in */
nil, /* name */
nil, /* case */
nil, /* esac */
nil, /* ;; */
nil, /* if */
nil, /* then */
nil, /* fi */
nil, /* elif */
nil, /* else */
nil, /* while */
nil, /* until */
nil, /* { */
nil, /* } */
nil, /* do */
nil, /* done */
nil, /* < */
nil, /* <& */
nil, /* > */
nil, /* >& */
nil, /* >> */
nil, /* <> */
nil, /* >| */
nil, /* << */
nil, /* <<- */
nil, /* \n */
nil, /* nothing */
nil, /* & */
nil, /* ; */
},
nil, /* INVALID */
accept(true), /* $ */
nil, /* word */
nil, /* number */
nil, /* = */
nil, /* && */
nil, /* || */
nil, /* ! */
nil, /* | */
nil, /* ( */
nil, /* ) */
nil, /* for */
nil, /* in */
nil, /* name */
nil, /* case */
nil, /* esac */
nil, /* ;; */
nil, /* if */
nil, /* then */
nil, /* fi */
nil, /* elif */
nil, /* else */
nil, /* while */
nil, /* until */
nil, /* { */
nil, /* } */
nil, /* do */
nil, /* done */
nil, /* < */
nil, /* <& */
nil, /* > */
nil, /* >& */
nil, /* >> */
nil, /* <> */
nil, /* >| */
nil, /* << */
nil, /* <<- */
nil, /* \n */
nil, /* nothing */
nil, /* & */
nil, /* ; */
},
},
actionRow{ // S2
canRecover: false,
canRecover: false,
actions: [numSymbols]action{
nil, /* INVALID */
reduce(1), /* $, reduce: Word */
nil, /* word */
nil, /* number */
nil, /* = */
nil, /* && */
nil, /* || */
nil, /* ! */
nil, /* | */
nil, /* ( */
nil, /* ) */
nil, /* for */
nil, /* in */
nil, /* name */
nil, /* case */
nil, /* esac */
nil, /* ;; */
nil, /* if */
nil, /* then */
nil, /* fi */
nil, /* elif */
nil, /* else */
nil, /* while */
nil, /* until */
nil, /* { */
nil, /* } */
nil, /* do */
nil, /* done */
nil, /* < */
nil, /* <& */
nil, /* > */
nil, /* >& */
nil, /* >> */
nil, /* <> */
nil, /* >| */
nil, /* << */
nil, /* <<- */
nil, /* \n */
nil, /* nothing */
nil, /* & */
nil, /* ; */
nil, /* INVALID */
reduce(1), /* $, reduce: Word */
nil, /* word */
nil, /* number */
nil, /* = */
nil, /* && */
nil, /* || */
nil, /* ! */
nil, /* | */
nil, /* ( */
nil, /* ) */
nil, /* for */
nil, /* in */
nil, /* name */
nil, /* case */
nil, /* esac */
nil, /* ;; */
nil, /* if */
nil, /* then */
nil, /* fi */
nil, /* elif */
nil, /* else */
nil, /* while */
nil, /* until */
nil, /* { */
nil, /* } */
nil, /* do */
nil, /* done */
nil, /* < */
nil, /* <& */
nil, /* > */
nil, /* >& */
nil, /* >> */
nil, /* <> */
nil, /* >| */
nil, /* << */
nil, /* <<- */
nil, /* \n */
nil, /* nothing */
nil, /* & */
nil, /* ; */
},
},
}

View File

@ -1,19 +1,19 @@
/*
*/
*/
package parser
const numNTSymbols = 47
type(
type (
gotoTable [numStates]gotoRow
gotoRow [numNTSymbols] int
gotoRow [numNTSymbols]int
)
var gotoTab = gotoTable{
gotoRow{ // S0
-1, // S'
1, // Word
1, // Word
-1, // IoNumber
-1, // AssignmentWord
-1, // List
@ -59,11 +59,10 @@ var gotoTab = gotoTable{
-1, // SeparatorOp
-1, // Separator
-1, // SequentialSep
},
gotoRow{ // S1
-1, // S'
-1, // Word
-1, // IoNumber
@ -111,11 +110,10 @@ var gotoTab = gotoTable{
-1, // SeparatorOp
-1, // Separator
-1, // SequentialSep
},
gotoRow{ // S2
-1, // S'
-1, // Word
-1, // IoNumber
@ -163,8 +161,6 @@ var gotoTab = gotoTable{
-1, // SeparatorOp
-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"
)
@ -18,16 +17,16 @@ const (
// Stack
type stack struct {
state []int
attrib []Attrib
state []int
attrib []Attrib
}
const iNITIAL_STACK_SIZE = 100
func newStack() *stack {
return &stack{ state: make([]int, 0, iNITIAL_STACK_SIZE),
attrib: make([]Attrib, 0, iNITIAL_STACK_SIZE),
}
return &stack{state: make([]int, 0, iNITIAL_STACK_SIZE),
attrib: make([]Attrib, 0, iNITIAL_STACK_SIZE),
}
}
func (this *stack) reset() {
@ -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,13 +52,13 @@ func (this *stack) topIndex() int {
}
func (this *stack) popN(items int) []Attrib {
lo, hi := len(this.state) - items, len(this.state)
attrib := this.attrib[lo: hi]
lo, hi := len(this.state)-items, len(this.state)
attrib := this.attrib[lo:hi]
this.state = this.state[:lo]
this.attrib = this.attrib[:lo]
return attrib
}
@ -187,9 +186,8 @@ func (this *Parser) Parse(scanner Scanner) (res interface{}, err error) {
panic("Error recovery led to invalid action")
}
}
// fmt.Printf("S%d %s %s\n", this.stack.top(), token.TokMap.TokenString(this.nextToken), action.String())
switch act := action.(type) {
case accept:

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
package token
import(
import (
"fmt"
)
@ -13,14 +12,14 @@ type Token struct {
type Type int
const(
const (
INVALID Type = iota
EOF
)
type Pos struct {
Offset int
Line int
Line int
Column int
}
@ -29,8 +28,8 @@ func (this Pos) String() string {
}
type TokenMap struct {
typeMap []string
idMap map[string]Type
typeMap []string
idMap map[string]Type
}
func (this TokenMap) Id(tok Type) string {
@ -101,48 +100,47 @@ var TokMap = TokenMap{
";",
},
idMap: map[string]Type {
idMap: map[string]Type{
"INVALID": 0,
"$": 1,
"word": 2,
"number": 3,
"=": 4,
"&&": 5,
"||": 6,
"!": 7,
"|": 8,
"(": 9,
")": 10,
"for": 11,
"in": 12,
"name": 13,
"case": 14,
"esac": 15,
";;": 16,
"if": 17,
"then": 18,
"fi": 19,
"elif": 20,
"else": 21,
"while": 22,
"until": 23,
"{": 24,
"}": 25,
"do": 26,
"done": 27,
"<": 28,
"<&": 29,
">": 30,
">&": 31,
">>": 32,
"<>": 33,
">|": 34,
"<<": 35,
"<<-": 36,
"\n": 37,
"$": 1,
"word": 2,
"number": 3,
"=": 4,
"&&": 5,
"||": 6,
"!": 7,
"|": 8,
"(": 9,
")": 10,
"for": 11,
"in": 12,
"name": 13,
"case": 14,
"esac": 15,
";;": 16,
"if": 17,
"then": 18,
"fi": 19,
"elif": 20,
"else": 21,
"while": 22,
"until": 23,
"{": 24,
"}": 25,
"do": 26,
"done": 27,
"<": 28,
"<&": 29,
">": 30,
">&": 31,
">>": 32,
"<>": 33,
">|": 34,
"<<": 35,
"<<-": 36,
"\n": 37,
"nothing": 38,
"&": 39,
";": 40,
"&": 39,
";": 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");