Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/metadata json #1242

Merged
merged 26 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5a030cc
Moved sequence adaptation uploading to the command dictionary page, s…
cohansen Apr 12, 2024
e178593
Fixed issues with uploading command dictionaries and sequence adaptat…
cohansen Apr 12, 2024
4296fa7
Added support for parsing channel and parameter dictionaries
cohansen Apr 15, 2024
c09460f
Fixed an issue with uploading a parameter dictionary
cohansen Apr 15, 2024
a24068c
Fixed the form builder from showing on the sequence select screen, fi…
cohansen Apr 15, 2024
e857348
First pass at adding parcels
cohansen Apr 18, 2024
0cb6200
Changed sequence editing to use parcels rather than command dictionaries
cohansen Apr 18, 2024
b552b8a
Hooked up sequence adaptation id to parcels
cohansen Apr 18, 2024
e4b876f
Added support for a single parameter dictionary
cohansen Apr 18, 2024
1671753
link adaptation code up with parcel
joswig Apr 19, 2024
e23f512
Merge branch 'dev-sequencing' into feature/parameter-and-channel-dict…
joswig Apr 19, 2024
4dc652a
editor is readonly in table view
joswig Apr 19, 2024
4c34b6e
content assist uses adaptation
joswig Apr 20, 2024
7e6965a
check unclosed blocks
joswig Apr 20, 2024
15c78d3
annotate all parser errors
joswig Apr 20, 2024
7a4adb0
variable names, but not types are checked
joswig Apr 20, 2024
3f2b5ae
better detection of command on selection line
joswig Apr 20, 2024
d8bb02c
code style
joswig Apr 22, 2024
f475586
cleaned up some commented out print statements
joswig Apr 22, 2024
ebfe8d1
cleaned up some commented out print statements
joswig Apr 22, 2024
aea0c8e
reduce block nesting and remove obsolete commented code
joswig Apr 23, 2024
ad4c7ea
Some code cleanup
cohansen Apr 23, 2024
8b492ff
use symbol for all enum type arguments
joswig Apr 24, 2024
bf55168
wip grammar support for arrays
joswig Apr 24, 2024
e959db3
support for nested objects
joswig Apr 24, 2024
86a9ff2
seq.json read/write support
joswig Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions codemirror-lang-sequence/src/sequence.grammar
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@top Sequence {
(newLine | whiteSpace)?
optSpace
(
commentLine* ~maybeComments
(IdDeclaration | ParameterDeclaration | LocalDeclaration | GenericDirective)
Expand Down Expand Up @@ -43,6 +43,10 @@ commentLine {
LineComment newLine
}

optSpace {
(newLine | whiteSpace)?
}

Commands {
(LoadAndGoDirective newLine)?
commandBlock
Expand Down Expand Up @@ -84,11 +88,23 @@ Metadata {
MetaEntry {
metadataDirective
whiteSpace Key { String }
whiteSpace Value { String }
whiteSpace Value { metaValue }
newLine
}+
}

metaValue {
String | Number | Boolean | Null | Array | Object
}

Object { "{" list<Property>? "}" }
Array { "[" list<metaValue>? "]" }

Property { PropertyName optSpace ":" optSpace metaValue }
PropertyName[isolate] { String }

list<item> { optSpace item (optSpace "," optSpace item)* optSpace }

Models {
Model {
modelDirective
Expand Down Expand Up @@ -131,9 +147,10 @@ Stem { !stemStart identifier }
"0x" (hex | "_")+ "n"?
}

TRUE { "TRUE" }
FALSE { "FALSE" }
TRUE { "true" }
FALSE { "false" }
Boolean { TRUE | FALSE }
Null { "null" }

LineComment { "#"![\n\r]* }

Expand Down
2 changes: 1 addition & 1 deletion codemirror-lang-sequence/test/cases/parse_tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ CMD_1 1 2 3
CMD_2 "hello, it's me"
@METADATA "bar" "{ \"foo\": 5}"
@MODEL "a" 5 "c"
@MODEL "d" TRUE "f"
@MODEL "d" true "f"
==>

Sequence(
Expand Down
75 changes: 75 additions & 0 deletions codemirror-lang-sequence/test/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,81 @@ const LINE_COMMENT_TOKEN = 'LineComment';
const METADATA_TOKEN = 'Metadata';
const METADATA_ENTRY_TOKEN = 'MetaEntry';

function getMetaType(node) {
return node.firstChild.nextSibling.firstChild.name;
}

function getMetaValue(node, input) {
const mv = node.firstChild.nextSibling.firstChild;
return JSON.parse(input.slice(mv.from, mv.to));
}

describe('metadata', () => {
it('primitive types', () => {
const input = `
@METADATA "name 1" "string val"
@METADATA "name 2" false
@METADATA "name3" 3
@METADATA "name4" 4e1
C STEM
`;
const parseTree = SeqLanguage.parser.parse(input);
assertNoErrorNodes(input);
const topLevelMetaData = parseTree.topNode.getChild(METADATA_TOKEN);
const metaEntries = topLevelMetaData.getChildren(METADATA_ENTRY_TOKEN);
assert.equal(metaEntries.length, 4);
assert.equal(getMetaType(metaEntries[0]), 'String');
assert.equal(getMetaType(metaEntries[1]), 'Boolean');
assert.equal(getMetaType(metaEntries[2]), 'Number');
assert.equal(getMetaType(metaEntries[3]), 'Number');
});

it('structured types', () => {
const input = `
@METADATA "name 1" [ 1,2 , 3 ]
@METADATA "name 2" ["a", true ,
2 ]

@METADATA "name 3" {
"level1": {
"level2": [
false,
1,
"two"
],
"level2 nest": {
"level3": true
}
}
}

@METADATA "name 4" {}

C STEM
`;
const parseTree = SeqLanguage.parser.parse(input);
assertNoErrorNodes(input);
const topLevelMetaData = parseTree.topNode.getChild(METADATA_TOKEN);
const metaEntries = topLevelMetaData.getChildren(METADATA_ENTRY_TOKEN);
assert.equal(metaEntries.length, 4);
assert.equal(getMetaType(metaEntries[0]), 'Array');
assert.equal(getMetaType(metaEntries[1]), 'Array');
assert.equal(getMetaType(metaEntries[2]), 'Object');
assert.equal(getMetaType(metaEntries[3]), 'Object');
assert.deepStrictEqual(getMetaValue(metaEntries[0], input), [1, 2, 3]);
assert.deepStrictEqual(getMetaValue(metaEntries[1], input), ['a', true, 2]);
assert.deepStrictEqual(getMetaValue(metaEntries[2], input), {
level1: {
level2: [false, 1, 'two'],
'level2 nest': {
level3: true,
},
},
});
assert.deepStrictEqual(getMetaValue(metaEntries[3], input), {});
});
});

describe('error positions', () => {
for (const { testname, input, first_error } of [
{
Expand Down
3 changes: 1 addition & 2 deletions src/utilities/new-sequence-editor/from-seq-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function seqJsonMetadataToSequence(metadata: Metadata): string {
const metaDataString = Object.entries(metadata)
.map(
([key, value]: [key: string, value: unknown]) =>
`@METADATA ${quoteEscape(key)} ${typeof value === 'string' ? quoteEscape(String(value)) : `"${value}"`}`,
`@METADATA ${quoteEscape(key)} ${JSON.stringify(value, null, 2)}`,
)
.join('\n');
return metaDataString.length > 0 ? `${metaDataString}\n` : '';
Expand All @@ -127,7 +127,6 @@ export function seqJsonToSequence(seqJson: SeqJson | null): string {
const sequence: string[] = [];

if (seqJson) {

// ID
sequence.push(`@ID "${seqJson.id}"\n`);

Expand Down
10 changes: 8 additions & 2 deletions src/utilities/new-sequence-editor/to-seq-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,15 @@ function parseMetadata(node: SyntaxNode, text: string): Metadata | undefined {
}

const keyText = removeQuotes(text.slice(keyNode.from, keyNode.to)) as string;
const valueText = removeQuotes(text.slice(valueNode.from, valueNode.to));

obj[keyText] = valueText;
let value = text.slice(valueNode.from, valueNode.to);
try {
value = JSON.parse(value);
} catch (e) {
logInfo(`Malformed metadata ${value}`);
}

obj[keyText] = value;
});

return obj;
Expand Down