all repos

clerk @ 540e892b4c90d34a76386b17ffab9266ae1a0485

missing tooling for ledger/hledger
8 files changed, 24 insertions(+), 6 deletions(-)
journal/printer: write IgnoredDirective up
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-06-08 21:10:56 +0300
Authored at: 2026-06-08 21:07:36 +0300
Change ID: zwmnunvrkksqwvzklnmsltkpqmsowoov
Parent: 7b1aef3
M journal/ast/directives.go
···
        120
        120
         func (CommentBlockDirective) entryNode() {}

      
        121
        121
         

      
        122
        122
         type IgnoredDirective struct {

      
        
        123
        +	Text    string   // content after N (commodity symbol or text)

      
        123
        124
         	Comment *Comment // optional inline comment

      
        124
        125
         	Span    token.Span

      
        125
        126
         }

      
M journal/ast/dump.go
···
        107
        107
         	case *IgnoredDirective:

      
        108
        108
         		indent(b, depth)

      
        109
        109
         		fmt.Fprintf(b, "IgnoredDirective %s\n", e.Span)

      
        
        110
        +		indent(b, depth+1)

      
        
        111
        +		fmt.Fprintf(b, "Text: %s\n", e.Text)

      
        110
        112
         	default:

      
        111
        113
         		indent(b, depth)

      
        112
        114
         		fmt.Fprintf(b, "Unknown %T\n", e)

      
M journal/parser/parser.go
···
        597
        597
         	s := p.cur.Span

      
        598
        598
         	p.expect(token.N)

      
        599
        599
         	p.skipWhitespace()

      
        
        600
        +

      
        
        601
        +	id := &ast.IgnoredDirective{}

      
        600
        602
         	if p.got(token.TEXT) || p.got(token.COMMODITYMARK) {

      
        
        603
        +		id.Text = p.cur.Literal

      
        601
        604
         		p.advance()

      
        602
        605
         	}

      
        603
        606
         	p.skipWhitespace()

      
        604
        
        -	comment := p.parseOptInlineComment()

      
        
        607
        +	id.Comment = p.parseOptInlineComment()

      
        
        608
        +

      
        605
        609
         	p.expectNewline()

      
        606
        
        -	return &ast.IgnoredDirective{

      
        607
        
        -		Comment: comment,

      
        608
        
        -		Span:    p.span(s),

      
        609
        
        -	}

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

      
        
        611
        +	return id

      
        610
        612
         }

      
        611
        613
         

      
        612
        614
         func (p *Parser) parseMarketPriceDirective() *ast.MarketPriceDirective {

      
M journal/parser/testdata/golden/Parser_ParseFile__N_directive.golden
···
        1
        1
         Journal

      
        2
        2
           IgnoredDirective j:1:1-2:1

      
        
        3
        +    Text: $

      
M journal/printer/directives.go
···
        117
        117
         	p.writeInlineComment(e.Comment)

      
        118
        118
         }

      
        119
        119
         

      
        
        120
        +func (p *printer) writeIgnoredDirective(e *ast.IgnoredDirective) {

      
        
        121
        +	p.buf.WriteString("N ")

      
        
        122
        +	p.buf.WriteString(e.Text)

      
        
        123
        +	p.writeInlineComment(e.Comment)

      
        
        124
        +}

      
        
        125
        +

      
        120
        126
         func quoteString(s string) string {

      
        121
        127
         	needsQuote := false

      
        122
        128
         	for _, c := range s {

      
M journal/printer/printer.go
···
        118
        118
         		return

      
        119
        119
         

      
        120
        120
         	case *ast.IgnoredDirective:

      
        121
        
        -		return // TODO:

      
        
        121
        +		p.writeIgnoredDirective(e)

      
        
        122
        +		return

      
        122
        123
         

      
        123
        124
         	case *ast.Comment:

      
        124
        125
         		p.writeComment(e)

      
M journal/printer/testdata/directives.golden
···
        17
        17
         ; Default commodity

      
        18
        18
         D 1,000.00$

      
        19
        19
         

      
        
        20
        +; N directive

      
        
        21
        +N $

      
        20
        22
         ; Apply/end

      
        21
        23
         apply account Expenses

      
        22
        24
         end

      
M journal/printer/testdata/directives.input
···
        17
        17
         ; Default commodity

      
        18
        18
         D $1,000.00

      
        19
        19
         

      
        
        20
        +; N directive

      
        
        21
        +N $

      
        
        22
        +

      
        20
        23
         ; Apply/end

      
        21
        24
         apply account Expenses

      
        22
        25
         end