all repos

clerk @ 8540205

missing tooling for ledger/hledger
5 files changed, 19 insertions(+), 12 deletions(-)
journal/parser: fix include directive
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-06-09 15:33:31 +0300
Authored at: 2026-06-09 14:50:36 +0300
Change ID: wulkywsrrlqxtsqzoqryosupnrlqzvur
Parent: dc54e90
M journal/lexer/lexer.go
···
        357
        357
         		return l.lexSingle(token.PLUS)

      
        358
        358
         	case '-':

      
        359
        359
         		return l.lexSingle(token.MINUS)

      
        360
        
        -	case '.':

      
        361
        
        -		return l.lexSingle(token.TEXT)

      
        362
        360
         	case '"', '\'':

      
        363
        361
         		return l.lexString()

      
        364
        362
         	default:

      
M journal/parser/parser.go
···
        434
        434
         	p.expect(token.INCLUDE)

      
        435
        435
         	p.skipWhitespace()

      
        436
        436
         

      
        437
        
        -	path := ""

      
        
        437
        +	id := &ast.IncludeDirective{}

      
        
        438
        +

      
        438
        439
         	if p.got(token.TEXT) {

      
        439
        
        -		path = p.cur.Literal

      
        
        440
        +		id.Path = p.cur.Literal

      
        440
        441
         		p.advance()

      
        441
        442
         	} else {

      
        442
        443
         		p.errorf("expected file path, got %s", p.cur.Type)

      
        443
        444
         	}

      
        444
        445
         

      
        445
        
        -	comment := p.parseOptInlineComment()

      
        
        446
        +	p.skipWhitespace()

      
        
        447
        +	id.Comment = p.parseOptInlineComment()

      
        446
        448
         	p.expectNewline()

      
        447
        
        -

      
        448
        
        -	return &ast.IncludeDirective{

      
        449
        
        -		Path:    path,

      
        450
        
        -		Comment: comment,

      
        451
        
        -		Span:    p.span(s),

      
        452
        
        -	}

      
        
        449
        +	id.Span = p.span(s)

      
        
        450
        +	return id

      
        453
        451
         }

      
        454
        452
         

      
        455
        453
         func (p *Parser) parseAliasDirective() *ast.AliasDirective {

      
M journal/parser/parser_test.go
···
        26
        26
         		{"P directive", "P 2024/01/01 USD 40.50 UAH\n"},

      
        27
        27
         		{"P directive with time", "P 2024-01-01 12:00:00 USD 40.50 UAH\n"},

      
        28
        28
         		{"N directive", "N $\n"},

      
        
        29
        +		{"inclue directive", "include ./path-to.journal\n"},

      
        
        30
        +		{"inclue directive with comment", "include ./path.journal ; something importnat\n"},

      
        29
        31
         		{"apply tag directive", "apply tag hashtag\n"},

      
        30
        32
         		{"apply fixed directive", "apply fixed CAD $0.90\n"},

      
        31
        33
         		{"end apply directive", "end apply tag\n"},

      ···
        182
        184
         2013/1/1 * pay taxes

      
        183
        185
             expenses:personal:tax              $1250

      
        184
        186
             assets:bank:checking               $-1250

      
        185
        
        -    

      
        
        187
        +

      
        186
        188
         `},

      
        187
        189
         		{"transaction with balance assertion", `2024/01/01 groceries

      
        188
        190
         	expenses:food  $10.00 = $100.00

      
A journal/parser/testdata/golden/Parser_ParseFile__inclue_directive.golden
···
        
        1
        +Journal

      
        
        2
        +  IncludeDirective j:1:1-2:1

      
        
        3
        +    Path: "./path-to.journal"

      
A journal/parser/testdata/golden/Parser_ParseFile__inclue_directive_with_comment.golden
···
        
        1
        +Journal

      
        
        2
        +  IncludeDirective j:1:1-2:1

      
        
        3
        +    Path: "./path.journal"

      
        
        4
        +    Comment j:1:24-2:0

      
        
        5
        +      Marker: ";"

      
        
        6
        +      Text: "something importnat"