Skip to content

Commit b8b1569

Browse files
committed
improved error messaging
1 parent 2c0bce3 commit b8b1569

1 file changed

Lines changed: 86 additions & 56 deletions

File tree

data-raw/excelguide_schema.cue

Lines changed: 86 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,99 @@
11
// usage: cue vet -c schema.cue file.yml
22

3-
"guide.version"! : #Version
4-
"template.name"! : string
5-
"template.min.version"! : #Version
6-
"template.max.version"! : #Version | null
7-
"plate.format"! : #Plateformat
8-
"locations"! : [...#Location]
9-
"translations" : [...#Translation]
10-
11-
#Version: =~ "^\\d+\\.\\d+$" // Only version numbers in major.minor format allowed
12-
13-
#Plateformat: 24 | 48 | 96 | 384
14-
15-
//#AnyLocation: {
16-
// "sheet"! : string
17-
// "varname"! : #VariableName
18-
// "translate"? : bool | *false
19-
// "atomicclass"? : #Atom | [...#Atom] | *"character"
20-
//}
21-
22-
//#CellLocation: {
23-
// "type"! : "cells"
24-
// "variables"! : [...#Variable]
25-
// ...
26-
//}
27-
28-
//#RangeLocation: {
29-
// "type"! : "keyvalue" | "platedata" | "table"
30-
// "ranges"! : [...#Range]
31-
// ...
32-
//}
33-
34-
// This does not work:
35-
// #Location: #AnyLocation & {#CellLocation | #RangeLocation}
36-
37-
#Location: {
38-
"sheet"! : string
39-
"varname"! : #VariableName
40-
"translate"? : bool | *false
41-
"type"! : "cells"
42-
"variables"! : [...#Variable]
43-
"atomicclass"? : #Atom | [...#Atom] | *"character"
44-
} | {
45-
"sheet"! : string
46-
"varname"! : #VariableName
47-
"translate"? : bool | *false
48-
"type"! : "keyvalue" | "platedata" | "table"
49-
"ranges"! : [...#Range]
50-
"atomicclass"? : #Atom | [...#Atom] | *"character"
3+
// Excel Data Guide Schema
4+
// This schema validates Excel template guide files that describe how to extract
5+
// data from Excel workbooks with specific template formats.
6+
7+
// Top-level required fields
8+
"guide.version"!: #Version
9+
"template.name"!: string
10+
"template.min.version"!: #Version
11+
"template.max.version"!: #Version | null
12+
"plate.format"!: #Plateformat
13+
"locations"!: [...#Location]
14+
"translations": [...#Translation]
15+
16+
// Version constraint: must be in major.minor format (e.g., "1.0", "2.3")
17+
#Version: string
18+
#Version: =~"^\\d+\\.\\d+$" | _|_("Version must be in major.minor format (e.g., '1.0' or '2.3')")
19+
20+
// Valid plate formats for laboratory experiments
21+
#Plateformat: 24 | 48 | 96 | 384 | _|_("Plate format must be one of: 24, 48, 96, or 384")
22+
23+
// Common fields shared by all location types
24+
#AnyLocation: {
25+
// The Excel sheet name where this location is found
26+
"sheet"!: string
27+
28+
// Variable name used to store the extracted data
29+
"varname"!: #VariableName
30+
31+
// Whether to apply translations to extracted values (default: false)
32+
"translate"?: bool | *false
33+
34+
// Allow additional fields for specific location types
35+
...
36+
}
37+
38+
// Cell-based location: extracts data from individual named cells
39+
#CellLocation: #AnyLocation & {
40+
// Type must be "cells" for cell-based locations
41+
"type"!: "cells"
42+
43+
// List of variables to extract, each with a name and cell reference
44+
"variables"!: [...#Variable]
45+
46+
// Optional atomic class specification for type coercion
47+
"atomicclass"?: #Atom | [...#Atom] | *"character"
5148
}
5249

50+
// Range-based location: extracts data from rectangular ranges
51+
#RangeLocation: #AnyLocation & {
52+
// Type specifies how to interpret the range data
53+
// - keyvalue: key-value pairs in two columns
54+
// - platedata: structured plate data with multiple wells
55+
// - table: tabular data with headers
56+
"type"!: "keyvalue" | "platedata" | "table"
57+
58+
// List of cell ranges to extract (e.g., "A1:B10")
59+
"ranges"!: [...#Range]
60+
61+
// Optional atomic class specification for type coercion
62+
"atomicclass"?: #Atom | [...#Atom] | *"character"
63+
}
64+
65+
// A location can be either cell-based or range-based
66+
#Location: #CellLocation | #RangeLocation
67+
68+
// Variable definition for cell-based locations
5369
#Variable: {
54-
"name"! : #VariableName
55-
"cell"! : #Cell
70+
// Variable name for storing the extracted value
71+
"name"!: #VariableName
72+
73+
// Cell reference where the value is located (e.g., "A1", "B23")
74+
"cell"!: #Cell
5675
}
5776

77+
// Translation mapping between short and long variable names
5878
#Translation: {
59-
"short"! : string
60-
"long"! : string
79+
// Short name used in the data structure
80+
"short"!: string
81+
82+
// Long, human-readable description
83+
"long"!: string
6184
}
6285

63-
#Atom : "character" | "date" | "numeric"
86+
// Atomic data types for type coercion
87+
#Atom: "character" | "date" | "numeric" | _|_("Atomic class must be one of: 'character', 'date', or 'numeric'")
6488

65-
#Range : =~ "^[A-Z]\\d+:[A-Z]\\d+$" // Valid spreadsheed range value required
89+
// Valid spreadsheet range format (e.g., "A1:B10", "C5:Z20")
90+
#Range: string
91+
#Range: =~"^[A-Z]+\\d+:[A-Z]+\\d+$" | _|_("Range must be in format 'A1:B10' (uppercase letters followed by numbers)")
6692

67-
#Cell : =~ "^[A-Z]\\d+$" // Valid spreadsheed cell value required
93+
// Valid spreadsheet cell reference (e.g., "A1", "B23", "Z99")
94+
#Cell: string
95+
#Cell: =~"^[A-Z]+\\d+$" | _|_("Cell reference must be in format 'A1' (uppercase letters followed by numbers)")
6896

69-
#VariableName : =~ "[^\\s]" // variable names are not allowed to contain space-like characters
97+
// Variable names cannot contain whitespace characters
98+
#VariableName: string
99+
#VariableName: =~"[^\\s]" | _|_("Variable names cannot contain whitespace characters")

0 commit comments

Comments
 (0)