Skip to content

Commit

Permalink
Feature/block relative and notes seqn (#1600)
Browse files Browse the repository at this point in the history
* First pass at adding block relative to the grammar

* Finished adding notes

* Added note seqjson converter

* Added Time1 as a param to the seqjson time conversion function

* Added more missing block relative logic

* Added a new timeSegments token for our seqn grammar

* Fixed some broken sasf tests that were using R rather than the new B time tag

* Removed Time1 from from-seq-json

* Fixed an issue now that there's a distinct time type without a tag
  • Loading branch information
cohansen authored Feb 11, 2025
1 parent fb8083f commit 91c1ef1
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 29 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"dependencies": {
"@fontsource/jetbrains-mono": "^5.0.19",
"@nasa-jpl/aerie-ampcs": "^1.0.5",
"@nasa-jpl/seq-json-schema": "^1.2.0",
"@nasa-jpl/seq-json-schema": "^1.3.1",
"@nasa-jpl/stellar": "^1.1.18",
"@streamparser/json": "^0.0.17",
"@sveltejs/adapter-node": "5.0.1",
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/codemirror/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export const SeqLanguage = LRLanguage.define({
LocalDeclaration: t.namespace,
MetaEntry: t.namespace,
Model: t.namespace,
Note: t.namespace,
ParameterDeclaration: t.namespace,
Request: t.namespace,
Stem: t.keyword,
String: t.string,
TimeAbsolute: t.className,
TimeBlockRelative: t.className,
TimeComplete: t.className,
TimeEpoch: t.className,
TimeGroundEpoch: t.className,
Expand Down
8 changes: 4 additions & 4 deletions src/utilities/codemirror/satf/satf-sasf-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('satfToSequence', () => {
expect(result).toHaveProperty('sequences');
expect(result.sequences[0].name).toStrictEqual('test');
expect(result.sequences[0].sequence).toStrictEqual(`## test
R00:01:00 01VV param6 10 false "abc" # This command turns, to correct position.
B00:01:00 01VV param6 10 false "abc" # This command turns, to correct position.
@MODEL "x" 1 "00:00:00"
@MODEL "z" 1.1 "00:00:00"
@MODEL "y" "abc" "00:00:00"`);
Expand Down Expand Up @@ -126,7 +126,7 @@ R00:01:00 01VV param6 10 false "abc" # This command turns, to correct position.
expect(result.sequences.length).toBe(2);
expect(result.sequences[0].name).toStrictEqual('test');
expect(result.sequences[0].sequence).toStrictEqual(`## test
R00:01:00 01VV param6 10 false "abc" # This command turns, to correct position.
B00:01:00 01VV param6 10 false "abc" # This command turns, to correct position.
@MODEL "x" 1 "00:00:00"
@MODEL "z" 1.1 "00:00:00"
@MODEL "y" "abc" "00:00:00"`);
Expand Down Expand Up @@ -288,7 +288,7 @@ string STRING
quoted_string STRING "" "abc, 123"
@INPUT_PARAMS_END
R00:01:00 NOOP`);
B00:01:00 NOOP`);
});

it('Quoted Parameters', async () => {
Expand Down Expand Up @@ -318,6 +318,6 @@ R00:01:00 NOOP`);
attitude_spec ENUM STORE_NAME "" "BOB_HARDWARE, SALLY_FARM, TIM_FLOWERS"
@INPUT_PARAMS_END
R00:01:00 ECHO "abc"`);
B00:01:00 ECHO "abc"`);
});
});
3 changes: 1 addition & 2 deletions src/utilities/codemirror/satf/satf-sasf-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,7 @@ function parseTimeNode(timeNode: SyntaxNode | null, text: string): string {
return `R${time} `;
case 'FROM_REQUEST_START':
case 'FROM_ACTIVITY_START':
// TODO: This needs to be changed to refer to the start of the request.
return `R${time} `;
return `B${time} `;
case 'WAIT_PREVIOUS_END':
return `C `;
default:
Expand Down
27 changes: 21 additions & 6 deletions src/utilities/codemirror/sequence.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ commandBlock {
)+
}

step { Command | Activate | GroundBlock | GroundEvent | Load }
step { Command | Activate | GroundBlock | GroundEvent | Load | Note }

commentLine {
LineComment newLine
Expand All @@ -70,7 +70,7 @@ HardwareCommands {
commandBlock
}

TimeTag { TimeAbsolute | (TimeGroundEpoch Name { String } whiteSpace) | TimeEpoch | TimeRelative | TimeComplete }
TimeTag { TimeAbsolute | (TimeGroundEpoch Name { String } whiteSpace) | TimeEpoch | TimeRelative | TimeComplete | TimeBlockRelative }

Args {
(whiteSpace (arg))* whiteSpace?
Expand Down Expand Up @@ -120,6 +120,15 @@ commonGround {
Models?
}

Note {
TimeTag
noteDirective "(" NoteValue { String } ")"
Args
LineComment?
newLine
Metadata?
}

Request {
TimeTag
requestStartDirective "(" RequestName { String } ")"
Expand Down Expand Up @@ -174,13 +183,17 @@ Stem { !stemStart identifier }

timeSecond { $[1-9] @digit* ("."@digit+)? }

timeSegments { timeSecond | timeDOY | timeHhmmss }

TimeAbsolute { 'A'@digit@digit@digit@digit"-"@digit@digit@digit"T"timeHhmmss whiteSpace }

TimeRelative { 'R'(timeSecond | timeDOY | timeHhmmss) whiteSpace}
TimeRelative { 'R'timeSegments whiteSpace}

TimeBlockRelative { 'B'$[+\-]?timeSegments whiteSpace }

TimeEpoch { 'E'$[+\-]?(timeSecond | timeDOY | timeHhmmss) whiteSpace}
TimeEpoch { 'E'$[+\-]?timeSegments whiteSpace}

TimeGroundEpoch { 'G'$[+\-]?(timeSecond | timeDOY | timeHhmmss) whiteSpace}
TimeGroundEpoch { 'G'$[+\-]?timeSegments whiteSpace}

TimeComplete { 'C' whiteSpace }

Expand Down Expand Up @@ -226,11 +239,12 @@ Stem { !stemStart identifier }
requestEndDirective { "@REQUEST_END" }
metadataDirective { "@METADATA" }
modelDirective { "@MODEL" }
noteDirective { "@NOTE" }
genericDirective { "@"identifier }

@precedence { newLine, whiteSpace }

@precedence{ TimeAbsolute, TimeRelative, TimeEpoch, TimeComplete, TimeGroundEpoch, Boolean, identifier }
@precedence{ TimeAbsolute, TimeRelative, TimeEpoch, TimeComplete, TimeGroundEpoch, TimeBlockRelative, Boolean, identifier }

@precedence {
LoadAndGoDirective,
Expand All @@ -249,6 +263,7 @@ Stem { !stemStart identifier }
loadDirective,
groundBlockDirective,
groundEventDirective,
noteDirective,
requestStartDirective,
requestEndDirective,
engineDirective,
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/sequence-editor/from-seq-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function seqJsonTimeToSequence(time: Time): string {
return `R${time.tag ?? ''}`;
case 'EPOCH_RELATIVE':
return `E${time.tag ?? ''}`;
case 'BLOCK_RELATIVE':
return `B${time.tag ?? ''}`;
default:
return '';
}
Expand Down
6 changes: 5 additions & 1 deletion src/utilities/sequence-editor/grammar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Command(Stem,Args(String),Models(Model(Variable(String),Value(String),Offset(Str
[
`Seq.Json comprehension`,
`A2024-123T12:34:56 @GROUND_BLOCK("ground_block.name") # No Args
C @NOTE("note_value")
R123T12:34:56 @GROUND_EVENT("ground_event.name") "foo" 1 2 3
A2024-123T12:34:56 @ACTIVATE("activate.name") # No Args
@ENGINE 10
Expand Down Expand Up @@ -348,12 +349,14 @@ A2024-123T12:34:56 @REQUEST_BEGIN("request2.name")
R100 CMD_3 "1 2 3"
C CMD_4 1 2 3
R100 CMD_5 "1 2 3"
B00:00:00 CMD_6 "1 2 3"
@REQUEST_END
@METADATA "foo" "bar"
`,
`
Sequence(Commands(
GroundBlock(TimeTag(TimeAbsolute),GroundName(String),Args,LineComment),
Note(TimeTag(TimeComplete),NoteValue(String)Args),
GroundEvent(TimeTag(TimeRelative),GroundName(String),Args(String,Number,Number,Number)),
Activate(TimeTag(TimeAbsolute),SequenceName(String),Args,LineComment,Engine(Number),Epoch(String)),
Activate(TimeTag(TimeRelative),SequenceName(String),Args(String,Number,Number,Number),LineComment,Engine(Number)),
Expand All @@ -379,7 +382,8 @@ Sequence(Commands(
Command(TimeTag(TimeComplete),Stem,Args(Number,Number,Number)),
Command(TimeTag(TimeRelative),Stem,Args(String)),
Command(TimeTag(TimeComplete),Stem,Args(Number,Number,Number)),
Command(TimeTag(TimeRelative),Stem,Args(String))
Command(TimeTag(TimeRelative),Stem,Args(String)),
Command(TimeTag(TimeBlockRelative),Stem,Args(String))
),
Metadata(MetaEntry(Key(String),Value(String)))
)
Expand Down
22 changes: 22 additions & 0 deletions src/utilities/sequence-editor/sequence-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ export function sequenceCompletion(
section: 'Time Tags',
type: 'keyword',
},
{
apply: 'B00:00:00 ',
info: 'Execute command at an offset from the block',
label: 'B (block relative)',
section: 'Time Tags',
type: 'keyword',
},
{
apply: 'G1 "epoch.name" ',
info: 'Add a ground epoch to a request',
Expand Down Expand Up @@ -216,6 +223,21 @@ export function sequenceCompletion(
section: 'Directives',
type: 'keyword',
},
{
apply: (view, _completion, from: number, to: number) => {
view.dispatch({
changes: {
from: Math.max(0, from + (!cursor.isAfterTimeTag || cursor.isAtSymbolBefore ? -1 : 0)),
insert: `${!cursor.isAfterTimeTag ? 'C ' : ''}@NOTE("note_value")`,
to,
},
});
},
info: 'note',
label: '@NOTE',
section: 'Directives',
type: 'function',
},
);
}

Expand Down
34 changes: 25 additions & 9 deletions src/utilities/sequence-editor/sequence-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ function validateTimeTags(command: SyntaxNode, text: string): Diagnostic[] {
const timeTagAbsoluteNode = timeTagNode?.getChild('TimeAbsolute');
const timeTagEpochNode = timeTagNode?.getChild('TimeEpoch') ?? timeTagNode.getChild('TimeGroundEpoch');
const timeTagRelativeNode = timeTagNode?.getChild('TimeRelative');
const timeTagBlockRelativeNode = timeTagNode?.getChild('TimeBlockRelative');

if (timeTagAbsoluteNode) {
const absoluteText = text.slice(timeTagAbsoluteNode.from + 1, timeTagAbsoluteNode.to).trim();
Expand Down Expand Up @@ -834,43 +835,58 @@ function validateTimeTags(command: SyntaxNode, text: string): Diagnostic[] {
}
}
}
} else if (timeTagRelativeNode) {
const relativeText = text.slice(timeTagRelativeNode.from + 1, timeTagRelativeNode.to).trim();
} else if (timeTagRelativeNode || timeTagBlockRelativeNode) {
let relativeText = '';
let from = -1;
let to = -1;

if (timeTagRelativeNode) {
from = timeTagRelativeNode.from;
to = timeTagRelativeNode.to;
relativeText = text.slice(from + 1, to).trim();
} else if (timeTagBlockRelativeNode) {
from = timeTagBlockRelativeNode.from;
to = timeTagBlockRelativeNode.to;
relativeText = text.slice(from + 1, to).trim();
}

const isValid =
validateTime(relativeText, TimeTypes.RELATIVE) || validateTime(relativeText, TimeTypes.RELATIVE_SIMPLE);
validateTime(relativeText, TimeTypes.RELATIVE) ||
(validateTime(relativeText, TimeTypes.RELATIVE_SIMPLE) && !timeTagBlockRelativeNode);
if (!isValid) {
diagnostics.push({
actions: [],
from: timeTagRelativeNode.from,
from,
message: CustomErrorCodes.InvalidRelativeTime().message,
severity: 'error',
to: timeTagRelativeNode.to,
to,
});
} else {
if (validateTime(relativeText, TimeTypes.RELATIVE)) {
if (isTimeMax(relativeText, TimeTypes.RELATIVE)) {
diagnostics.push({
actions: [],
from: timeTagRelativeNode.from,
from,
message: CustomErrorCodes.MaxRelativeTime().message,
severity: 'error',
to: timeTagRelativeNode.to,
to,
});
} else {
if (!isTimeBalanced(relativeText, TimeTypes.EPOCH)) {
diagnostics.push({
actions: [],
from: timeTagRelativeNode.from,
from,
message: CustomErrorCodes.UnbalancedTime(getBalancedDuration(relativeText)).message,
severity: 'error',
to: timeTagRelativeNode.to,
to,
});
}
}
}
}
}
}

return diagnostics;
}

Expand Down
Loading

0 comments on commit 91c1ef1

Please sign in to comment.