Skip to content

Commit 8d40aa0

Browse files
committed
Parser: more support for type specs
1 parent 68b74a2 commit 8d40aa0

File tree

2 files changed

+76
-6
lines changed
  • language-powerquery/src/Language/PowerQuery
  • language-powerquery-ast/src/Language/PowerQuery/AST

2 files changed

+76
-6
lines changed

language-powerquery-ast/src/Language/PowerQuery/AST/AST.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ data PrimaryType annotation
364364
}
365365
| FunctionType
366366
{ _functionType_parametersSpecifications :: !(Maybe [ParameterSpecification annotation])
367-
, _functionType_returnType :: !PrimitiveType
367+
, _functionType_returnType :: !(Type annotation)
368368
, _functionType_annotation :: !(Maybe annotation)
369369
}
370370
| TableType

language-powerquery/src/Language/PowerQuery/Parser.y

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,23 +683,93 @@ primitive_type
683683
684684
record_type :: { PrimaryType Annotation }
685685
record_type
686-
: 'xxx' { RecordType [] Nothing }
686+
: '[' '...' ']' { RecordType [] (Just Annotation) }
687+
| '[' field_specification_list ']' { RecordType $2 (Just Annotation) }
688+
| '[' field_specification_list ',' '...' ']' { RecordType $2 (Just Annotation) }
689+
690+
field_specification_list :: { [FieldSpecification Annotation] }
691+
field_specification_list
692+
: field_specification { [$1] }
693+
| field_specification ',' field_specification_list { $1:$3 }
694+
695+
field_specification :: { FieldSpecification Annotation }
696+
field_specification
697+
: optional__opt 'identifier' field_type_specification__opt { FieldSpecification (getIdent $2) $3 $1 (Just Annotation) }
698+
699+
optional__opt :: { Bool }
700+
optional__opt
701+
: 'optional' { True }
702+
| {- empty -} { False }
703+
704+
field_type_specification__opt :: { Maybe (Type Annotation) }
705+
field_type_specification__opt
706+
: field_type_specification { Just $1 }
707+
| {- empty -} { Nothing }
708+
709+
field_type_specification :: { Type Annotation }
710+
field_type_specification
711+
: '=' field_type { $2 }
712+
713+
field_type :: { Type Annotation }
714+
field_type
715+
: type { $1 }
687716
688717
list_type :: { PrimaryType Annotation }
689718
list_type
690-
: 'xxx' { ListType undefined Nothing }
719+
: '{' item_type '}' { ListType $2 (Just Annotation) }
720+
721+
item_type :: { Type Annotation }
722+
item_type
723+
: type { $1 }
691724
692725
function_type :: { PrimaryType Annotation }
693726
function_type
694-
: 'xxx' { FunctionType undefined TypeAny Nothing }
727+
: 'function' '(' parameter_specification_list__opt ')' return_type { FunctionType $3 $5 (Just Annotation) }
728+
729+
parameter_specification_list__opt :: { Maybe [ParameterSpecification Annotation] }
730+
parameter_specification_list__opt
731+
: parameter_specification_list { Just $1 }
732+
| {- empty -} { Nothing }
733+
734+
parameter_specification_list :: { [ParameterSpecification Annotation] }
735+
parameter_specification_list
736+
: required_parameter_specification_list { $1 }
737+
| required_parameter_specification_list ',' optional_parameter_specification_list { $1 <> $3 }
738+
| optional_parameter_specification_list { $1 }
739+
740+
required_parameter_specification_list :: { [ParameterSpecification Annotation] }
741+
required_parameter_specification_list
742+
: required_parameter_specification { [$1] }
743+
| required_parameter_specification ',' required_parameter_specification_list { $1:$3 }
744+
745+
required_parameter_specification :: { ParameterSpecification Annotation }
746+
required_parameter_specification
747+
: parameter_specification { $1 }
748+
749+
optional_parameter_specification_list :: { [ParameterSpecification Annotation] }
750+
optional_parameter_specification_list
751+
: optional_parameter_specification { [$1] }
752+
| optional_parameter_specification ',' optional_parameter_specification_list { $1:$3 }
753+
754+
optional_parameter_specification :: { ParameterSpecification Annotation }
755+
optional_parameter_specification
756+
: 'optional' parameter_specification { $2 { _parameterSpecification_optional = True} }
757+
758+
parameter_specification :: { ParameterSpecification Annotation }
759+
parameter_specification
760+
: parameter_name parameter_type { ParameterSpecification $1 (Just $2) False (Just Annotation) }
695761
696762
table_type :: { PrimaryType Annotation }
697763
table_type
698-
: 'xxx' { TableType [] Nothing }
764+
: 'table' row_type { TableType $2 (Just Annotation) }
765+
766+
row_type :: { [FieldSpecification Annotation] }
767+
row_type
768+
: '[' field_specification_list ']' { $2 }
699769
700770
nullable_type :: { PrimaryType Annotation }
701771
nullable_type
702-
: 'xxx' { NullableType undefined Nothing }
772+
: 'nullable' type { NullableType $2 (Just Annotation) }
703773
704774
-- 12.2.3.26 - Error raising expression
705775
error_raising_expression :: { ErrorRaisingExpression Annotation }

0 commit comments

Comments
 (0)