Skip to content

Commit

Permalink
Revert "Feat/seqgen grammar v2" (#1383)
Browse files Browse the repository at this point in the history
Revert "Feat/seqgen grammar v2 (#1362)"

This reverts commit dbe5435.
  • Loading branch information
duranb authored and JosephVolosin committed Oct 21, 2024
1 parent 20a7a18 commit 4147216
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 1,395 deletions.
1 change: 0 additions & 1 deletion src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ declare global {
parameterDictionaries: ParameterDictionary[],
channelDictionary: ChannelDictionary | null,
);
var ALLOW_NON_COMMAND_STEPS: boolean | undefined;
}

export {};
79 changes: 22 additions & 57 deletions src/components/sequencing/form/SelectedCommand.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<svelte:options immutable={true} />

<script lang="ts">
import type { EditorState } from '@codemirror/state';
import type { SyntaxNode } from '@lezer/common';
import type {
ChannelDictionary,
CommandDictionary,
FswCommand,
FswCommandArgument,
FswCommandArgumentRepeat,
FswCommandArgumentVarString,
ParameterDictionary,
} from '@nasa-jpl/aerie-ampcs';
import type { EditorView } from 'codemirror';
Expand All @@ -20,19 +20,10 @@
type ArgTextDef,
} from '../../../utilities/codemirror/codemirror-utils';
import { getCustomArgDef } from '../../../utilities/new-sequence-editor/extension-points';
import {
getNameNode,
TOKEN_ACTIVATE,
TOKEN_COMMAND,
TOKEN_ERROR,
TOKEN_GROUND_BLOCK,
TOKEN_GROUND_EVENT,
TOKEN_LOAD,
} from '../../../utilities/new-sequence-editor/sequencer-grammar-constants';
import { TOKEN_COMMAND, TOKEN_ERROR } from '../../../utilities/new-sequence-editor/sequencer-grammar-constants';
import { getAncestorNode } from '../../../utilities/new-sequence-editor/tree-utils';
import AddMissingArgsButton from './AddMissingArgsButton.svelte';
import ArgEditor from './ArgEditor.svelte';
import StringEditor from './StringEditor.svelte';
type TimeTagInfo = { node: SyntaxNode; text: string } | null | undefined;
Expand All @@ -51,17 +42,8 @@
let missingArgDefArray: FswCommandArgument[] = [];
let timeTagNode: TimeTagInfo = null;
$: commandNode = getAncestorNode(
node,
TOKEN_COMMAND,
TOKEN_ACTIVATE,
TOKEN_GROUND_BLOCK,
TOKEN_GROUND_EVENT,
TOKEN_LOAD,
);
$: commandNameNode = getNameNode(commandNode);
$: commandName = commandNameNode && editorSequenceView.state.sliceDoc(commandNameNode.from, commandNameNode.to);
$: commandDef = getCommandDef(commandDictionary, commandName ?? '');
$: commandNode = getAncestorNode(node, TOKEN_COMMAND);
$: commandDef = getCommandDef(commandDictionary, editorSequenceView.state, commandNode);
$: argInfoArray = getArgumentInfo(
commandNode?.getChild('Args') ?? null,
commandDef?.arguments,
Expand Down Expand Up @@ -150,8 +132,23 @@
return argArray;
}
function getCommandDef(commandDictionary: CommandDictionary | null, stemName: string) {
return commandDictionary?.fswCommandMap[stemName] ?? null;
function getCommandDef(
commandDictionary: CommandDictionary | null,
state: EditorState | undefined,
commandNode: SyntaxNode | null,
) {
if (!commandDictionary || !state || !node) {
return null;
}
const stemNode = commandNode?.getChild('Stem');
if (stemNode) {
const stemName = state.sliceDoc(stemNode.from, stemNode.to);
return commandDictionary.fswCommandMap[stemName];
}
return null;
}
function setInEditor(token: SyntaxNode, val: string) {
Expand Down Expand Up @@ -184,21 +181,6 @@
return hasAncestorWithId(element.parentElement, id);
}
function formatTypeName(s: string) {
// add spaces to CamelCase names, 'GroundEvent' -> 'Ground Event'
return s.replace(/([^A-Z])(?=[A-Z])/g, '$1 ');
}
const nameArgumentDef: FswCommandArgumentVarString = {
arg_type: 'var_string',
default_value: null,
description: '',
max_bit_length: null,
name: '',
prefix_bit_length: null,
valid_regex: null,
};
// When the type in the argument value is compatible with the argument definition,
// provide a more restrictive editor to keep argument valid. Otherwise fall back on a string editor.
Expand All @@ -211,9 +193,8 @@

<div class="select-command-detail" id={ID_COMMAND_DETAIL_PANE}>
{#if !!commandNode}
<div>Selected Command</div>
{#if !!commandDef}
<div>Selected {formatTypeName(commandNode.name)}</div>

{#if !!timeTagNode}
<div>Time Tag: {timeTagNode.text.trim()}</div>
{/if}
Expand Down Expand Up @@ -244,22 +225,6 @@
/>
{/if}
</div>
{:else}
<div>Selected {formatTypeName(commandNode.name)}</div>
{#if !!timeTagNode}
<div>Time Tag: {timeTagNode.text.trim()}</div>
{/if}
<div>
<StringEditor
argDef={nameArgumentDef}
initVal={commandName ?? ''}
setInEditor={val => {
if (commandNameNode) {
setInEditor(commandNameNode, val);
}
}}
/>
</div>
{/if}
{/if}
</div>
Expand Down
3 changes: 0 additions & 3 deletions src/utilities/codemirror/codemirror-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ export function quoteEscape(s: string) {
return `"${s.replaceAll('"', '\\"')}"`;
}

export function removeEscapedQuotes(text: string): string;
export function removeEscapedQuotes(text: number): number;
export function removeEscapedQuotes(text: boolean): boolean;
export function removeEscapedQuotes(text: string | number | boolean): string | number | boolean {
if (typeof text === 'string') {
return text.replace(/\\"|"(?!\\")/g, '"').trim();
Expand Down
8 changes: 0 additions & 8 deletions src/utilities/codemirror/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@ export const SeqLanguage = LRLanguage.define({
Command: customFoldInside,
}),
styleTags({
Activate: t.namespace,
Boolean: t.bool,
Engine: t.namespace,
Epoch: t.namespace,
GenericDirective: t.namespace,
Global: t.namespace,
GroundBlock: t.namespace,
GroundEpoch: t.className,
GroundEvent: t.namespace,
HardwareCommands: t.namespace,
IdDeclaration: t.namespace,
ImmediateCommands: t.namespace,
LineComment: t.comment,
Load: t.namespace,
LoadAndGoDirective: t.namespace,
LocalDeclaration: t.namespace,
MetaEntry: t.namespace,
Model: t.namespace,
ParameterDeclaration: t.namespace,
Request: t.namespace,
Stem: t.keyword,
String: t.string,
TimeAbsolute: t.className,
Expand Down
80 changes: 3 additions & 77 deletions src/utilities/codemirror/sequence.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

// Potential Improvements
// maintainability - use @specialize on directives
// expressiveness - add activate, load and ground syntax

@precedence {
stemStart @cut
Expand All @@ -35,15 +36,9 @@ LocalDeclaration {
}

commandBlock {
(
step |
Request |
commentLine ~maybeComments
)+
(Command | commentLine ~maybeComments)+
}

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

commentLine {
LineComment newLine
}
Expand Down Expand Up @@ -89,57 +84,6 @@ Command {
Models?
}

Activate { TimeTag activateDirective commonLoadActivate }

Load { TimeTag loadDirective commonLoadActivate }

commonLoadActivate {
"(" SequenceName { String } ")"
Args
LineComment?
newLine
Engine { engineDirective whiteSpace Number newLine }?
Epoch { epochDirective whiteSpace String newLine }?
Metadata?
Models?
}

GroundBlock { TimeTag groundBlockDirective commonGround }

GroundEvent { TimeTag groundEventDirective commonGround }

commonGround {
"(" GroundName { String } ")"
Args
LineComment?
newLine
Metadata?
Models?
}

Request {
(TimeTag | GroundEpoch {
groundEpochDirective
"("
whiteSpace?
Name { String }
whiteSpace?
","
whiteSpace?
Delta { String }
whiteSpace?
")"
// Extra properties are allowed in schema, but not supported by tool chain
whiteSpace
})
requestStartDirective "(" RequestName { String } ")"
whiteSpace? LineComment? newLine
// json schema requires step+, catch error in linter for cleaner message
Steps { step* }
requestEndDirective newLine
Metadata?
}

Metadata {
MetaEntry {
metadataDirective
Expand Down Expand Up @@ -220,15 +164,6 @@ Stem { !stemStart identifier }
hardwareDirective { "@HARDWARE" }
localsDirective { "@LOCALS" }
parameterDirective { "@INPUT_PARAMS" }
activateDirective { "@ACTIVATE" }
loadDirective { "@LOAD" }
engineDirective { "@ENGINE" }
epochDirective { "@EPOCH" }
groundEpochDirective { "@GROUND_EPOCH" }
groundBlockDirective { "@GROUND_BLOCK" }
groundEventDirective { "@GROUND_EVENT" }
requestStartDirective { "@REQUEST_BEGIN" }
requestEndDirective { "@REQUEST_END" }
metadataDirective { "@METADATA" }
modelDirective { "@MODEL" }
genericDirective { "@"identifier }
Expand All @@ -238,23 +173,14 @@ Stem { !stemStart identifier }
@precedence{ TimeAbsolute, TimeRelative, TimeEpoch, TimeComplete, identifier }

@precedence {
LoadAndGoDirective,
idDirective,
metadataDirective,
modelDirective,
immediateDirective,
hardwareDirective,
localsDirective,
parameterDirective,
activateDirective,
loadDirective,
groundBlockDirective,
groundEventDirective,
groundEpochDirective,
requestStartDirective,
requestEndDirective,
engineDirective,
epochDirective,
LoadAndGoDirective,
genericDirective,
identifier
}
Expand Down
Loading

0 comments on commit 4147216

Please sign in to comment.