diff --git a/src/utilities/codemirror/sequence.grammar b/src/utilities/codemirror/sequence.grammar index 8118fd5341..01c04d6242 100644 --- a/src/utilities/codemirror/sequence.grammar +++ b/src/utilities/codemirror/sequence.grammar @@ -1,5 +1,5 @@ @top Sequence { - optSpace + newLine? ( commentLine* ~maybeComments (IdDeclaration | ParameterDeclaration | LocalDeclaration | GenericDirective) @@ -19,22 +19,28 @@ } GenericDirective { - genericDirective (whiteSpace String)* newLine + genericDirective String* newLine } IdDeclaration { - idDirective (whiteSpace (String | Enum | Number)?)? newLine + idDirective (String | Enum | Number)? newLine } ParameterDeclaration { - (parameterDirective whiteSpace Variable{((Enum whiteSpace?) | (Enum whiteSpace? Object whiteSpace?))}+ newLine) | - (parameterStartDirective newLine (whiteSpace? Variable{((Enum whiteSpace?) | (Enum whiteSpace? Type { identifier } whiteSpace? ( (EnumName { identifier}) | (Range { String } (whiteSpace Values {String})? ) | (EnumName { identifier} whiteSpace (Range { String } (whiteSpace Values {String})?) )? whiteSpace?)) )} newLine)* parameterEndDirective newLine ) + (parameterDirective Variable{ Enum Object? }+ newLine) | + (parameterStartDirective newLine (Variable newLine)* parameterEndDirective newLine ) } LocalDeclaration { - (localsDirective whiteSpace Variable{((Enum whiteSpace?) | (Enum whiteSpace? Object whiteSpace?))}+ newLine) | - (localsStartDirective newLine (whiteSpace? Variable{((Enum whiteSpace?) | (Enum whiteSpace? Type { identifier } whiteSpace? ( (EnumName { identifier}) | (Range { String } (whiteSpace Values {String})? ) | (EnumName { identifier} whiteSpace (Range { String } (whiteSpace Values {String})?) )? whiteSpace?)) )} newLine)* localsEndDirective newLine ) + (localsDirective Variable{ Enum Object? }+ newLine) | + (localsStartDirective newLine (Variable newLine)* localsEndDirective newLine ) +} +Variable { + Enum (Type { identifier } ( + (EnumName { identifier } (Range { String } (Values {String})?)? )? + | (Range { String } (Values {String})? ) + ))? } commandBlock { @@ -51,10 +57,6 @@ commentLine { LineComment newLine } -optSpace { - (newLine | whiteSpace)? -} - Commands { (LoadAndGoDirective newLine)? commandBlock @@ -70,15 +72,11 @@ HardwareCommands { commandBlock } -TimeTag { TimeAbsolute | (TimeGroundEpoch Name { String } whiteSpace) | TimeEpoch | TimeRelative | TimeComplete } +TimeTag { TimeAbsolute | (TimeGroundEpoch Name { String }) | TimeEpoch | TimeRelative | TimeComplete } -Args { - (whiteSpace (arg))* whiteSpace? -} +Args { arg* } -RepeatArg { - "[" (whiteSpace? arg)* whiteSpace? "]" -} +RepeatArg { "[" (arg)* "]" } arg[@isGroup=Arguments] { Number | String | Boolean | Enum | RepeatArg } @@ -101,8 +99,8 @@ commonLoadActivate { Args LineComment? newLine - Engine { engineDirective whiteSpace Number newLine }? - Epoch { epochDirective whiteSpace String newLine }? + Engine { engineDirective Number newLine }? + Epoch { epochDirective String newLine }? Metadata? Models? } @@ -123,7 +121,7 @@ commonGround { Request { TimeTag requestStartDirective "(" RequestName { String } ")" - whiteSpace? LineComment? newLine + LineComment? newLine // json schema requires step+, catch error in linter for cleaner message Steps { step* } requestEndDirective newLine @@ -133,8 +131,8 @@ Request { Metadata { MetaEntry { metadataDirective - whiteSpace Key { String } - whiteSpace Value { metaValue } + Key { String } + Value { metaValue } newLine }+ } @@ -143,20 +141,20 @@ metaValue { String | Number | Boolean | Null | Array | Object } -Object { "{" (optSpace | list) "}" } -Array { "[" (optSpace | list) "]" } +Object { "{" (newLine? | list) "}" } +Array { "[" (newLine? | list) "]" } -Property { PropertyName optSpace ":" optSpace metaValue } +Property { PropertyName newLine? ":" newLine? metaValue } PropertyName[isolate] { String } -list { optSpace item (optSpace "," optSpace item)* optSpace } +list { newLine? item (newLine? "," newLine? item)* newLine? } Models { Model { modelDirective - whiteSpace Variable { String } - whiteSpace Value { String | Number | Boolean } - whiteSpace Offset { String } + Variable { String } + Value { String | Number | Boolean } + Offset { String } newLine }+ } @@ -174,15 +172,15 @@ Stem { !stemStart identifier } timeSecond { $[1-9] @digit* ("."@digit+)? } - TimeAbsolute { 'A'@digit@digit@digit@digit"-"@digit@digit@digit"T"timeHhmmss whiteSpace } + TimeAbsolute { 'A'@digit@digit@digit@digit"-"@digit@digit@digit"T"timeHhmmss } - TimeRelative { 'R'(timeSecond | timeDOY | timeHhmmss) whiteSpace} + TimeRelative { 'R'(timeSecond | timeDOY | timeHhmmss) } - TimeEpoch { 'E'$[+\-]?(timeSecond | timeDOY | timeHhmmss) whiteSpace} + TimeEpoch { 'E'$[+\-]?(timeSecond | timeDOY | timeHhmmss) } - TimeGroundEpoch { 'G'$[+\-]?(timeSecond | timeDOY | timeHhmmss) whiteSpace} + TimeGroundEpoch { 'G'$[+\-]?(timeSecond | timeDOY | timeHhmmss) } - TimeComplete { 'C' whiteSpace } + TimeComplete { 'C ' } String { '"' (!["\\] | "\\" _)* '"' } @@ -202,7 +200,7 @@ Stem { !stemStart identifier } LineComment { "#"![\n\r]* } - newLine { ($[ \t]* "\n")+ $[ \t]* | (whiteSpace? @eof) } + newLine { @whitespace* ("\n" | @eof) } whiteSpace { $[ \t]+ } @@ -257,3 +255,5 @@ Stem { !stemStart identifier } identifier } } + +@skip { whiteSpace } diff --git a/src/utilities/sequence-editor/grammar.test.ts b/src/utilities/sequence-editor/grammar.test.ts index e4908dd272..add7ccbd6a 100644 --- a/src/utilities/sequence-editor/grammar.test.ts +++ b/src/utilities/sequence-editor/grammar.test.ts @@ -393,17 +393,9 @@ const errorTests = [ 'Bad Input - Invalid stems', `C 2_STEM_NAME STEM$BAR`, - `Sequence(Commands(Command(TimeTag(TimeComplete),⚠(Number),Stem,Args),Command(Stem,⚠),Command(Stem,Args)))`, - ], - [ - 'Stem with disallowed characters', - `FSW_CMD%BAR$BAZ`, - `Sequence(Commands( -Command(Stem,⚠), -Command(Stem,⚠), -Command(Stem,Args) -))`, + `Sequence(Commands(Command(TimeTag(TimeComplete),⚠(Number),Stem,Args),Command(Stem,⚠,Args(Enum))))`, ], + ['Stem with disallowed characters', `FSW_CMD%BAR$BAZ`, `Sequence(Commands(Command(Stem,⚠,Args(Enum,⚠,Enum))))`], [ 'Stem ending in disallowed character', `FSW_CMD%`, @@ -418,7 +410,7 @@ CMD2 [ CMD3 ]`, `Sequence(Commands( Command(Stem,Args(RepeatArg(RepeatArg,⚠))), - Command(Stem,Args(RepeatArg(⚠))),Command(Stem,Args(⚠))))`, + Command(Stem,Args(RepeatArg(⚠))),Command(Stem,⚠,Args)))`, ], ['locals with wrong value types', `@LOCALS "string_not_enum"`, `Sequence(LocalDeclaration(⚠(String)))`], ];