Skip to content

Commit 007f5ed

Browse files
committed
Merge branch 'main' into zapdiff
2 parents 788da5d + 2ecad6f commit 007f5ed

138 files changed

Lines changed: 2753 additions & 749 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "v1.5.24"
2+
"version": "v1.6.5"
33
}

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: 'go.mod'
19+
20+
- name: Build
21+
run: go build -v ./...
22+
23+
- name: Test
24+
run: go test -v ./...

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,13 @@ To query, use you favorite MySQL client. On the command line, for example:
340340

341341

342342
```console
343-
mysql -h 127.0.0.1 --skip-ssl
343+
mysql -h 127.0.0.1 --skip-ssl MatterSpec
344344
```
345345

346346
The `--skip-ssl` is because `alchemy-db` runs locally without SSL certificates, as a debug tool, yet modern MySQL versions require SSL on the connection unless otherwise specified.
347347

348348
##### Semantic tags used across multiple Namespaces
349349
```sql
350-
USE MatterSpec;
351-
352350
SELECT
353351
t.name AS tag,
354352
ns.name AS namespace,
@@ -410,3 +408,28 @@ WHERE
410408
(SELECT NAME FROM LargeEnums)
411409
);
412410
```
411+
412+
##### Export full list of semantic tags
413+
```sql
414+
415+
SELECT
416+
n.id AS namespace_id,
417+
t.id AS tag_id,
418+
t.name AS tag_name,
419+
n.name AS namespace_name,
420+
d.name AS source_name
421+
FROM
422+
tag AS t
423+
INNER JOIN
424+
namespace AS n ON t.namespace_id = n.namespace_id
425+
INNER JOIN
426+
document AS d ON n.document_id = d.document_id
427+
ORDER BY
428+
namespace_id ASC, tag_id ASC;
429+
```
430+
431+
An export as CSV of this query can be done directly like this:
432+
433+
```console
434+
mysql -h 127.0.0.1 --skip-ssl --batch -e "SELECT n.id AS namespace_id, t.id AS tag_id, t.name AS tag_name, n.name AS namespace_name, d.name AS source_name FROM tag AS t INNER JOIN namespace AS n ON t.namespace_id = n.namespace_id INNER JOIN document AS d ON n.document_id = d.document_id ORDER BY namespace_id ASC, tag_id ASC;" MatterSpec | sed 's/\t/,/g' > namespaces.csv
435+
```

asciidoc/counter.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ type Counter struct {
66

77
Name string
88
InitialValue string
9-
Display bool
9+
Display CounterVisibility
1010
}
1111

12-
func NewCounter(name string, initialValue any, display bool) *Counter {
12+
func NewCounter(name string, initialValue any, display CounterVisibility) *Counter {
1313
iv, _ := initialValue.(string)
1414
return &Counter{Name: name, InitialValue: iv, Display: display}
1515
}
@@ -44,6 +44,17 @@ const (
4444
CounterTypeLowerCase
4545
)
4646

47+
type CounterVisibility uint8
48+
49+
const (
50+
CounterVisibilityHidden CounterVisibility = iota
51+
CounterVisibilityVisible
52+
)
53+
54+
func (cb CounterVisibility) Visible() bool {
55+
return cb == CounterVisibilityVisible
56+
}
57+
4758
type CounterState struct {
4859
CounterType CounterType
4960
Value int

asciidoc/describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func Describe(el Element) string {
164164
if el.InitialValue != "" {
165165
s += fmt.Sprintf(" (initial value: %s)", el.InitialValue)
166166
}
167-
if el.Display {
167+
if el.Display.Visible() {
168168
s += " (display)"
169169
}
170170
return s

asciidoc/overlay/overlay.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
123123
}
124124
remove = true
125125
case *asciidoc.IfDef:
126-
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
126+
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
127127
suppress = suppress || !el.Eval(pps)
128128
remove = true
129-
addToCell = el.Inline
129+
addToCell = el.Inline || isContentIfDef(parent, index)
130130
case *asciidoc.IfNDef:
131-
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
131+
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
132132
suppress = suppress || !el.Eval(pps)
133133
remove = true
134-
addToCell = el.Inline
134+
addToCell = el.Inline || isContentIfDef(parent, index)
135135
case *asciidoc.IfEval:
136-
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el})
136+
suppressStack.Push(&conditionalBlock{suppress: suppress, open: el, addToCell: addToCell})
137137
if !suppress {
138138
var include bool
139139
include, err = el.Eval(pps)
@@ -144,7 +144,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
144144
suppress = !include
145145
}
146146
remove = true
147-
addToCell = el.Inline
147+
addToCell = el.Inline || isContentIfDef(parent, index)
148148
case *asciidoc.IfDefBlock, *asciidoc.IfNDefBlock, *asciidoc.IfEvalBlock:
149149
err = fmt.Errorf("unexpected type in preparse: %T", el)
150150
should = parse.SearchShouldStop
@@ -163,7 +163,7 @@ func preparseFile(cxt OverlayContext, pps *overlayFileState, d *asciidoc.Documen
163163
}
164164
suppress = cb.suppress
165165
remove = true
166-
addToCell = false
166+
addToCell = cb.addToCell
167167
case *asciidoc.InlineIfDef:
168168
if !suppress {
169169
if el.Eval(pps) {
@@ -365,3 +365,26 @@ func parseLevelOffset(el asciidoc.Parent, elements asciidoc.Elements) (leveloffs
365365
leveloffset, relative, err = text.ParseRelativeNumber(val)
366366
return
367367
}
368+
369+
func isContentIfDef(parent asciidoc.ParentElement, index int) bool {
370+
if _, ok := parent.(*asciidoc.Table); !ok {
371+
return false
372+
}
373+
children := parent.Children()
374+
depth := 0
375+
for i := index + 1; i < len(children); i++ {
376+
child := children[i]
377+
switch child.(type) {
378+
case *asciidoc.IfDef, *asciidoc.IfNDef, *asciidoc.IfEval:
379+
depth++
380+
case *asciidoc.EndIf:
381+
if depth == 0 {
382+
return true
383+
}
384+
depth--
385+
case *asciidoc.TableRow:
386+
return false
387+
}
388+
}
389+
return false
390+
}

asciidoc/overlay/state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
)
88

99
type conditionalBlock struct {
10-
open asciidoc.Element
11-
suppress bool
10+
open asciidoc.Element
11+
suppress bool
12+
addToCell bool
1213
}
1314

1415
type overlayState struct {

asciidoc/parse/asciidoc.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

asciidoc/parse/parse.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"log/slog"
8+
"os"
89
"time"
910

1011
"github.com/project-chip/alchemy/asciidoc"
@@ -31,6 +32,16 @@ func Bytes(path asciidoc.Path, b []byte, opts ...Option) (*asciidoc.Document, er
3132
return d, nil
3233
}
3334

35+
func File(path asciidoc.Path, opts ...Option) (*asciidoc.Document, error) {
36+
37+
file, err := os.Open(path.Absolute)
38+
if err != nil {
39+
return nil, err
40+
}
41+
defer file.Close()
42+
return Reader(path, file, opts...)
43+
}
44+
3445
func parseBytes(document *asciidoc.Document, b []byte, opts ...Option) (elements asciidoc.Elements, err error) {
3546

3647
opts = append(opts, setDocument(document))

asciidoc/render/attributes.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ const (
3030
AttributeFilterFloat
3131
)
3232

33+
type attributeRenderType uint8
34+
35+
const (
36+
attributeRenderTypeBlock attributeRenderType = iota
37+
attributeRenderTypeInline
38+
)
39+
3340
func shouldRenderAttributeType(at AttributeFilter, include AttributeFilter, exclude AttributeFilter) bool {
3441
return ((at & include) == at) && ((at & exclude) != at)
3542
}
3643

37-
func renderAttributes(cxt Target, attributes []asciidoc.Attribute, inline bool) error {
38-
_, err := renderSelectAttributes(cxt, attributes, AttributeFilterAll, AttributeFilterNone, inline)
44+
func renderAttributes(cxt Target, attributes []asciidoc.Attribute, renderType attributeRenderType) error {
45+
_, err := renderSelectAttributes(cxt, attributes, AttributeFilterAll, AttributeFilterNone, renderType)
3946
return err
4047
}
4148

@@ -67,12 +74,12 @@ func getAttributeType(name asciidoc.AttributeName) AttributeFilter {
6774
return AttributeFilterNone
6875
}
6976

70-
func renderSelectAttributes(cxt Target, attributes []asciidoc.Attribute, include AttributeFilter, exclude AttributeFilter, inline bool) (n int, err error) {
77+
func renderSelectAttributes(cxt Target, attributes []asciidoc.Attribute, include AttributeFilter, exclude AttributeFilter, renderType attributeRenderType) (n int, err error) {
7178
if len(attributes) == 0 {
7279
return
7380
}
7481

75-
type attributeClass uint32
82+
type attributeClass uint8
7683

7784
const (
7885
attributeClassNone attributeClass = iota
@@ -136,7 +143,7 @@ func renderSelectAttributes(cxt Target, attributes []asciidoc.Attribute, include
136143
continue
137144
}
138145
for _, ta := range anchors {
139-
err = renderAttributeAnchor(cxt, ta, include, exclude, inline)
146+
err = renderAttributeAnchor(cxt, ta, include, exclude, renderType)
140147
if err != nil {
141148
return
142149
}
@@ -170,7 +177,7 @@ func renderSelectAttributes(cxt Target, attributes []asciidoc.Attribute, include
170177
if len(filtered) == 0 {
171178
continue
172179
}
173-
if !inline {
180+
if renderType != attributeRenderTypeInline {
174181
cxt.EnsureNewLine()
175182
}
176183
cxt.FlushWrap()
@@ -216,7 +223,7 @@ func renderSelectAttributes(cxt Target, attributes []asciidoc.Attribute, include
216223
n++
217224
}
218225
cxt.WriteString("]")
219-
if !inline {
226+
if renderType != attributeRenderTypeInline {
220227
cxt.WriteString("\n")
221228
}
222229
cxt.EndBlock()
@@ -229,10 +236,10 @@ func renderSelectAttributes(cxt Target, attributes []asciidoc.Attribute, include
229236
return
230237
}
231238

232-
func renderAttributeAnchor(cxt Target, anchor *asciidoc.AnchorAttribute, include AttributeFilter, exclude AttributeFilter, inline bool) (err error) {
239+
func renderAttributeAnchor(cxt Target, anchor *asciidoc.AnchorAttribute, include AttributeFilter, exclude AttributeFilter, renderType attributeRenderType) (err error) {
233240
id := anchor.ID
234241
if len(id) > 0 && shouldRenderAttributeType(AttributeFilterID, include, exclude) {
235-
if !inline {
242+
if renderType != attributeRenderTypeInline {
236243
cxt.EnsureNewLine()
237244
}
238245
cxt.FlushWrap()
@@ -255,7 +262,7 @@ func renderAttributeAnchor(cxt Target, anchor *asciidoc.AnchorAttribute, include
255262
}
256263
}
257264
cxt.WriteString("]]")
258-
if !inline {
265+
if renderType != attributeRenderTypeInline {
259266
cxt.WriteRune('\n')
260267
}
261268
cxt.EndBlock()

0 commit comments

Comments
 (0)