Skip to content

Commit

Permalink
Merge pull request #1 for v0.5 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jun 21, 2018
2 parents 5c1e180 + a03affc commit a4e8eb5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ branches:
# skip tags build, we are building branch and master that is enough for
# consistenty check and release. Let's use Travis CI resources optimally
# for aah framework.
- /^v[0-9]\.[0-9]/
- /^v[0-9.]+$/

go:
- 1.8
- 1.9
- 1.9.x
- 1.x
- tip

go_import_path: aahframework.org/forge.v0

before_install:
- bash <(curl -s https://aahframework.org/base-before-install) "vfs"

install:
- git config --global http.https://aahframework.org.followRedirects true
- go get -t -v ./...

script:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**v0.5** 2018-06-20 Jeevanandam M <[email protected]>
* Virtual FileSystem capability added `aahframework.org/vfs`

**v0.4.4** 2017-03-22 Jeevanandam M <[email protected]>
* Upstream Refresh
* File closer enhanced
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2015 Brett Langdon <[email protected]> (https://brett.is)
Copyright (c) 2017-2018 Jeevanandam M. <[email protected]> (https://myjeeva.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Forge is a configuration syntax and parser forked for [aah framework](https://aa

You can see example usage in the `example` folder.

```cfg
```bash
# example.cfg

# Global directives
Expand Down
17 changes: 13 additions & 4 deletions forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ import (
"bytes"
"io"
"strings"

"aahframework.org/vfs.v0"
)

// Version represent current release version of forge.
var Version = "0.4.4"
var Version = "0.5"

// ParseBytes takes a []byte representation of the config file, parses it
// and responds with `*Section` and potentially an `error` if it cannot
Expand All @@ -115,11 +117,18 @@ func ParseBytes(data []byte) (*Section, error) {
return ParseReader(bytes.NewReader(data))
}

// ParseFile takes a string filename for the config file, parses it
// ParseFile takes a filename for the config file, parses it
// and responds with `*Section` and potentially an `error` if it cannot
// properly parse the configf
// properly parse the config
func ParseFile(filename string) (*Section, error) {
parser, err := NewFileParser(filename)
return VFSParseFile(nil, filename)
}

// VFSParseFile takes a vfs and filename for the config file, parses it
// and responds with `*Section` and potentially an `error` if it cannot
// properly parse the config
func VFSParseFile(fs *vfs.VFS, filename string) (*Section, error) {
parser, err := VFSNewFileParser(fs, filename)
if err != nil {
return nil, err
}
Expand Down
32 changes: 25 additions & 7 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strconv"

"aahframework.org/forge.v0/token"
"aahframework.org/vfs.v0"
)

func isSemicolonOrNewline(id token.TokenID) bool {
Expand All @@ -17,6 +19,7 @@ func isSemicolonOrNewline(id token.TokenID) bool {

// Parser is a struct to hold data necessary for parsing a config from a scanner
type Parser struct {
vfs *vfs.VFS
files []string
settings *Section
scanner *Scanner
Expand All @@ -25,10 +28,18 @@ type Parser struct {
previous []*Section
}

// NewParser will create and initialize a new Parser from a provided io.Reader
// NewParser will create and initialize a new Parser from a
// provided io.Reader
func NewParser(reader io.Reader) *Parser {
return VFSNewParser(nil, reader)
}

// VFSNewParser will create and initialize a new Parser from a
// provided vfs and io.Reader
func VFSNewParser(vfs *vfs.VFS, reader io.Reader) *Parser {
settings := NewSection()
return &Parser{
vfs: vfs,
files: make([]string, 0),
scanner: NewScanner(reader),
settings: settings,
Expand All @@ -37,13 +48,20 @@ func NewParser(reader io.Reader) *Parser {
}
}

// NewFileParser will create and initialize a new Parser from a provided from a filename string
// NewFileParser will create and initialize a new Parser from a
// provided filename
func NewFileParser(filename string) (*Parser, error) {
reader, err := os.Open(filename)
return VFSNewFileParser(nil, filename)
}

// VFSNewFileParser will create and initialize a new Parser from a
// provided vfs and filename
func VFSNewFileParser(fs *vfs.VFS, filename string) (*Parser, error) {
reader, err := vfs.Open(fs, filename)
if err != nil {
return nil, err
}
parser := NewParser(reader)
parser := VFSNewParser(fs, reader)
parser.addFile(filename)
return parser, nil
}
Expand Down Expand Up @@ -239,10 +257,10 @@ func (parser *Parser) parseInclude() error {

// if it is not absolute path, resolve to relative from parent config directory
if !filepath.IsAbs(pattern) && len(parser.files) > 0 {
pattern = filepath.Join(filepath.Dir(parser.files[0]), filepath.Clean(pattern))
pattern = path.Join(path.Dir(parser.files[0]), path.Clean(pattern))
}

filenames, err := filepath.Glob(pattern)
filenames, err := vfs.Glob(parser.vfs, pattern)
if err != nil {
return err
}
Expand All @@ -253,7 +271,7 @@ func (parser *Parser) parseInclude() error {
if parser.hasParsed(filename) {
continue
}
reader, err := os.Open(filename)
reader, err := vfs.Open(parser.vfs, filename)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Token struct {

func (this Token) String() string {
return fmt.Sprintf(
"ID<%s> Literal<%s> Line<%s> Column<%s>",
"ID<%v> Literal<%v> Line<%v> Column<%v>",
this.ID, this.Literal, this.Line, this.Column,
)
}
Expand Down

0 comments on commit a4e8eb5

Please sign in to comment.