-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
197 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package coin | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
) | ||
|
||
// Include takes a path pattern that will be expanded into a list of files to include | ||
// at the point when the include is encountered, i.e. the include files are loaded | ||
// BEFORE the loading of the current files continues. | ||
// The pattern is a glob pattern, e.g. "foo/*.coin" interpreted relative to the directory | ||
// of the file containing the include statement. | ||
// Absolute paths are interpreted relative to the directory from which the coin command was executed. | ||
// Environment variables can be used in the pattern as well. They are expanded in the normal way (os.ExpandEnv). | ||
type Include struct { | ||
Path string | ||
|
||
line uint | ||
file string | ||
} | ||
|
||
var includeHead = regexp.MustCompile(`include\s+(.+)`) | ||
|
||
func (p *Parser) parseInclude(fn string) (*Include, error) { | ||
matches := includeHead.FindSubmatch(p.Bytes()) | ||
i := &Include{Path: string(matches[1]), line: p.lineNr, file: fn} | ||
p.Scan() | ||
return i, nil | ||
} | ||
|
||
func (i *Include) Location() string { | ||
return fmt.Sprintf("%s:%d", i.file, i.line) | ||
} | ||
|
||
// Files returns list of file names matching the path to be included. | ||
// Path resolution works as follows: | ||
// - leading / is prepended with . which is the directory from which the coin command was executed; | ||
// - otherwise the path is assumed to be relative to the directory of the file containing the include statement | ||
// - environment variable references are also expanded in normal way (os.ExpandEnv) | ||
// - if the path starts with an env var, it is left to be as it expands | ||
// | ||
// Finally the path is passed to filepath.Glob to expand wildcards. | ||
func (i *Include) Files() ([]string, error) { | ||
var resolved string | ||
if i.Path[0] == '/' { | ||
resolved = "." + i.Path | ||
} else if i.Path[0] == '$' { | ||
resolved = i.Path | ||
} else { | ||
resolved = filepath.Join(filepath.Dir(i.file), i.Path) | ||
} | ||
resolved = os.ExpandEnv(resolved) | ||
return filepath.Glob(resolved) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
commodity CAD | ||
format 1.00 CAD | ||
|
||
account Assets:Bank | ||
account Income:Salary | ||
account Expenses:Food | ||
account Expenses:Rent | ||
|
||
2010/01/15 ACME Inc | ||
Bank 1000 CAD | ||
Salary | ||
|
||
2010/01/20 Freshco | ||
Food 150 CAD | ||
Bank | ||
|
||
2010/01/28 Freshco | ||
Food 100 CAD | ||
Bank | ||
|
||
2010/01/30 Housing Corp | ||
Rent 500 CAD | ||
Bank | ||
|
||
2010/02/02 Freshco | ||
Food 100 CAD | ||
Bank | ||
|
||
2010/02/15 ACME Inc | ||
Bank 1000 CAD | ||
Salary | ||
|
||
2010/02/28 Housing Corp | ||
Rent 500 CAD | ||
Bank | ||
|
||
2010/03/08 Freshco | ||
Food 200 CAD | ||
Bank | ||
|
||
2010/03/15 ACME Inc | ||
Bank 1000 CAD | ||
Salary | ||
|
||
2010/03/30 Housing Corp | ||
Rent 500 CAD | ||
Bank | ||
|
||
2010/04/15 ACME Inc | ||
Bank 1000 CAD | ||
Salary | ||
|
||
2010/04/30 Housing Corp | ||
Rent 500 CAD | ||
Bank | ||
|
||
2010/05/05 Freshco | ||
Food 300 CAD | ||
Bank | ||
|
||
2010/05/15 ACME Inc | ||
Bank 1000 CAD | ||
Salary | ||
|
||
2010/05/30 Housing Corp | ||
Rent 500 CAD | ||
Bank | ||
|
||
2010/06/15 ACME Inc | ||
Bank 1000 CAD | ||
Salary | ||
|
||
2010/06/22 Freshco | ||
Food 250 CAD | ||
Bank | ||
|
||
2010/06/30 Housing Corp | ||
Rent 500 CAD | ||
Bank | ||
|
||
2010/07/03 Freshco | ||
Food 300 CAD | ||
Bank | ||
|
||
2010/07/15 ACME Inc | ||
Bank 1000 CAD | ||
Salary | ||
|
||
2010/07/30 Housing Corp | ||
Rent 500 CAD | ||
Bank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
; this assumes `coin test` is executed from the root of the repo | ||
|
||
include /examples/yearly/commodities.coin | ||
include /examples/yearly/accounts.coin | ||
include /examples/yearly/20??.coin | ||
|
||
test stats | ||
Commodities: 1 | ||
Prices: 0 | ||
Accounts: 17 | ||
Transactions: 2558 | ||
end test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
; this assumes env var COIN_TESTS points at the tests directory | ||
|
||
include $COIN_TESTS/cmd/reg/basic.coin | ||
|
||
test stats | ||
Commodities: 1 | ||
Prices: 0 | ||
Accounts: 9 | ||
Transactions: 21 | ||
end test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include ../reg/basic.coin | ||
|
||
test stats | ||
Commodities: 1 | ||
Prices: 0 | ||
Accounts: 9 | ||
Transactions: 21 | ||
end test |