Skip to content

Commit

Permalink
support SPACECRAFT_TIME() command and encoded_string arg
Browse files Browse the repository at this point in the history
  • Loading branch information
joswig committed Feb 1, 2025
1 parent 64a72aa commit 01c2a90
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
43 changes: 32 additions & 11 deletions src/utilities/codemirror/vml/vml.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
// https://github.com/lezer-parser/generator/blob/10a697a11ebdef98cd08a2c6ac2ef6619604385c/test/cases/ExternalSpecializer.txt#L9
// https://github.com/lezer-parser/css/blob/692710b42f83961151eee4cf73b0ae18ebccffad/src/tokens.js#L35
// https://github.com/lezer-parser/css/blob/692710b42f83961151eee4cf73b0ae18ebccffad/src/css.grammar#L147
// https://github.jpl.nasa.gov/MPS/vml_2_1/blob/master/vml_2_1/vml_compiler_test/command_stream/long_sequence.vml
// https://github.jpl.nasa.gov/MPS/vml/blob/master/vml_compiler/vml_compiler.y

@skip { space | Comment }

Expand Down Expand Up @@ -113,16 +115,23 @@ Common_Function {
BODY
End_lines
Time_tagged_statements {
Time_tagged_statement {
TIME_CONST
Statement
}*
Time_tagged_statement*
}
END_BODY
End_lines
}
}

Time_tagged_statement {
TIME_CONST
Statement
}

@top
Test_Time_tagged_statement {
Time_tagged_statement
}

Statement {
statement_no_endline[@isGroup=StatementSub] {
Issue
Expand Down Expand Up @@ -158,6 +167,18 @@ Clear {
CLEAR
}

Byte_array {
OPEN_PAREN
(
HEX_CONST
(
COMMA
HEX_CONST
)*
)?
CLOSE_PAREN
}

Issue {
ISSUE
// Function_name, Call_parameters not shown in schema
Expand Down Expand Up @@ -352,6 +373,8 @@ Call_parameters {

Call_parameter {
Simple_expr
// Byte_Array has limited examples
| Byte_array
}

Simple_call {
Expand Down Expand Up @@ -396,17 +419,15 @@ Unop {
}

Built_in_function {
// Grammar shows 2 sets of paranthesis
(Zero_parm_built_in_function_name OPEN_PAREN CLOSE_PAREN)
// Grammar shows 2 set paranthesis for zero arg, one here, and one next level down
// (Zero_parm_built_in_function_name OPEN_PAREN CLOSE_PAREN)
Zero_parm_built_in_function_name
| (Unary_parm_built_in_function_name OPEN_PAREN Compound_expr CLOSE_PAREN)
}

Zero_parm_built_in_function_name {
// Time is present in reference grammar, not example
// SPACECRAFT_TIME
// Odd to not have a name???
// name missing in reference grammar, present in sample
Function_name
// only function name in grammar
SPACECRAFT_TIME
OPEN_PAREN CLOSE_PAREN
}

Expand Down
33 changes: 32 additions & 1 deletion src/utilities/codemirror/vml/vml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ import {
RULE_ASSIGNMENT,
RULE_BLOCK,
RULE_BODY,
RULE_BYTE_ARRAY,
RULE_COMMON_FUNCTION,
RULE_FUNCTION,
RULE_FUNCTION_NAME,
RULE_FUNCTIONS,
RULE_SIMPLE_CALL,
RULE_SPAWN,
RULE_STATEMENT,
RULE_TEST_TIME_TAGGED_STATEMENT,
RULE_TEXT_FILE,
RULE_TIME_TAGGED_STATEMENT,
RULE_TIME_TAGGED_STATEMENTS,
RULE_VM_MANAGEMENT,
TOKEN_ERROR,
TOKEN_TIME_CONST,
} from './vmlConstants';

// In versions of VML prior to 2.1, explicit time tags were required on every statement
Expand Down Expand Up @@ -440,6 +443,33 @@ END_MODULE
});
});

describe('standalone statements', () => {
const timeTaggedConfig = { top: RULE_TEST_TIME_TAGGED_STATEMENT };
const timeTaggedParser = VmlLanguage.parser.configure(timeTaggedConfig);

it('spacecraft command with assignment', () => {
const input = `R00:00:01.00 END_TIME := spacecraft_time()\n`;
const tree = timeTaggedParser.parse(input);
const timeTaggedNode = tree.topNode.firstChild;
expect(timeTaggedNode?.firstChild?.name).toBe(TOKEN_TIME_CONST);
expect(timeTaggedNode?.firstChild?.nextSibling?.firstChild?.name).toBe(RULE_ASSIGNMENT);
expect(`${tree}`.includes(TOKEN_ERROR)).toBeFalsy();
});

it('issue with argument byte_array', () => {
const input = `R00:00:01.00 ISSUE FSW_VX_CMD (0x0, 0x0, 0x0)\n`;
const tree = timeTaggedParser.parse(input);
const timeTaggedNode = tree.topNode.firstChild;
expect(timeTaggedNode?.name).toBe(RULE_TIME_TAGGED_STATEMENT);
expect(timeTaggedNode?.firstChild?.nextSibling?.name).toBe(RULE_STATEMENT);
const statementNode = timeTaggedNode?.firstChild?.nextSibling;
expect(statementNode?.firstChild?.firstChild?.nextSibling?.nextSibling?.firstChild?.firstChild?.name).toBe(
RULE_BYTE_ARRAY,
);
expect(`${tree}`.includes(TOKEN_ERROR)).toBeFalsy();
});
});

function printNodes(input: string): void {
for (const node of filterNodes(VmlLanguage.parser.parse(input).cursor())) {
printNode(input, node);
Expand Down Expand Up @@ -468,7 +498,8 @@ END_MODULE
}

export function assertNoErrorNodes(input: string, printPrefix?: boolean): void {
const cursor = VmlLanguage.parser.parse(input).cursor();
const parser = VmlLanguage.parser;
const cursor = parser.parse(input).cursor();
do {
const { node } = cursor;
if (printPrefix) {
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/codemirror/vml/vmlConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const RULE_ASSIGNMENT = 'Assignment';
export const RULE_STATEMENT = 'Statement';
export const RULE_TIME_TAGGED_STATEMENTS = 'Time_tagged_statements';
export const RULE_TIME_TAGGED_STATEMENT = 'Time_tagged_statement';
export const RULE_TEST_TIME_TAGGED_STATEMENT = 'Test_Time_tagged_statement';
export const RULE_VM_MANAGEMENT = 'Vm_management';
export const RULE_SPAWN = 'Spawn';
export const RULE_HALT = 'Halt';
Expand All @@ -57,6 +58,7 @@ export const RULE_OPTIONAL_DEFAULT_INPUT_VALUE = 'Optional_default_input_value';
export const RULE_OPTIONAL_VALUE_LIST = 'Optional_value_list';
export const RULE_INPUT_RANGE = 'Input_Range';
export const RULE_INPUT_VALUE = 'Input_value';
export const RULE_BYTE_ARRAY = 'Byte_array';

export const GROUP_STATEMENT_SUB = 'StatementSub';

Expand Down
1 change: 1 addition & 0 deletions src/utilities/codemirror/vml/vmlLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function validateArguments(
functionNode: SyntaxNode,
functionNameNode: SyntaxNode,
docText: string,
// issue_dynamic puts the stem into the first argument
parameterOffset: number,
): Diagnostic[] {
const diagnostics: Diagnostic[] = [];
Expand Down

0 comments on commit 01c2a90

Please sign in to comment.