Browse Source

add null data type

pull/16/head
Brett Langdon 11 years ago
parent
commit
e6ec0a6d6c
6 changed files with 30 additions and 0 deletions
  1. +6
    -0
      README.md
  2. +10
    -0
      config/config.go
  3. +1
    -0
      example/example.cfg
  4. +5
    -0
      parser/parser.go
  5. +2
    -0
      token/tokenid.go
  6. +6
    -0
      token/tokenizer.go

+ 6
- 0
README.md View File

@ -43,6 +43,12 @@ A boolean value is either `true` or `false` of any case.
`TRUE`, `true`, `True`, `FALSE`, `False`, `false`.
### Null
A null value is allowed as `null` of any case.
`NULL`, `Null`, `null`.
### String
A string value is wrapped by double quotes (single quotes will not work).


+ 10
- 0
config/config.go View File

@ -8,6 +8,7 @@ const (
BOOLEAN
FLOAT
STRING
NULL
)
var configTypes = [...]string{
@ -16,6 +17,7 @@ var configTypes = [...]string{
INTEGER: "INTEGER",
FLOAT: "FLOAT",
STRING: "STRING",
NULL: "NULL",
}
func (this ConfigType) String() string {
@ -44,6 +46,14 @@ type BooleanValue struct {
func (this BooleanValue) GetType() ConfigType { return BOOLEAN }
func (this BooleanValue) GetValue() interface{} { return this.Value }
type NullValue struct {
Name string
Value interface{}
}
func (this NullValue) GetType() ConfigType { return NULL }
func (this NullValue) GetValue() interface{} { return nil }
type IntegerValue struct {
Name string
Value int64


+ 1
- 0
example/example.cfg View File

@ -5,6 +5,7 @@ master {
float = 80.80;
boolean = true;
negative = FALSE;
nothing = NULL;
sub {
key = "master sub key value";
}


+ 5
- 0
parser/parser.go View File

@ -128,6 +128,11 @@ func (this *Parser) parseSetting(name string) error {
Name: name,
Value: bool_val,
}
case token.NULL:
value = config.NullValue{
Name: name,
Value: nil,
}
case token.INTEGER:
int_val, err := strconv.ParseInt(this.cur_tok.Literal, 10, 64)
if err != nil {


+ 2
- 0
token/tokenid.go View File

@ -17,6 +17,7 @@ const (
INTEGER
FLOAT
STRING
NULL
)
var tokenNames = [...]string{
@ -32,6 +33,7 @@ var tokenNames = [...]string{
INTEGER: "INTEGER",
FLOAT: "FLOAT",
STRING: "STRING",
NULL: "NULL",
}
func (this TokenID) String() string {


+ 6
- 0
token/tokenizer.go View File

@ -25,6 +25,10 @@ func isBoolean(str string) bool {
return lower == "true" || lower == "false"
}
func isNull(str string) bool {
return strings.ToLower(str) == "null"
}
type Tokenizer struct {
cur_line int
cur_col int
@ -80,6 +84,8 @@ func (this *Tokenizer) parseIdentifier() {
if isBoolean(this.cur_tok.Literal) {
this.cur_tok.ID = BOOLEAN
} else if isNull(this.cur_tok.Literal) {
this.cur_tok.ID = NULL
}
}


Loading…
Cancel
Save