99} from "../print_utils" ;
1010import { CstToDocMap } from "../CstToDocMap" ;
1111
12- export const proceduralLanguageMap : CstToDocMap < AllProceduralNodes > = {
12+ export const proceduralLanguageMap : Partial < CstToDocMap < AllProceduralNodes > > = {
1313 // BEGIN .. END
1414 block_stmt : ( print , node ) =>
1515 group ( [
@@ -19,23 +19,32 @@ export const proceduralLanguageMap: CstToDocMap<AllProceduralNodes> = {
1919 hardline ,
2020 print ( "endKw" ) ,
2121 ] ) ,
22- exception_clause : ( print ) =>
22+ exception_clause : ( print , node ) => {
23+ if ( node . clauses . length === 1 ) {
24+ // Keep single exception clause on the same line as EXCEPTION keyword
25+ return group ( print . spaced ( [ "exceptionKw" , "clauses" ] ) ) ;
26+ } else {
27+ return group ( [ print ( "exceptionKw" ) , indent ( [ line , print ( "clauses" ) ] ) ] ) ;
28+ }
29+ } ,
30+ exception_when_clause : ( print ) =>
2331 group ( [
24- print . spaced ( [ "exceptionKw" , " whenKw", "condition" , "thenKw" ] ) ,
32+ print . spaced ( [ "whenKw" , "condition" , "thenKw" ] ) ,
2533 indent ( [ hardline , stripTrailingHardline ( print ( "program" ) ) ] ) ,
2634 ] ) ,
27- error_category : ( print ) => print ( "errorKw" ) ,
35+
36+ error_bigquery : ( print ) => print ( "errorKw" ) ,
2837
2938 // DECLARE
3039 declare_stmt : ( print ) =>
3140 group (
3241 join ( " " , [
3342 print ( "declareKw" ) ,
3443 group ( print ( "names" ) ) ,
35- ...print . spaced ( [ "dataType" , "default " ] ) ,
44+ ...print . spaced ( [ "dataType" , "init " ] ) ,
3645 ] ) ,
3746 ) ,
38- declare_default : ( print ) => print . spaced ( [ "defaultKw " , "expr" ] ) ,
47+ declare_init : ( print ) => print . spaced ( [ "operator " , "expr" ] ) ,
3948
4049 // SET
4150 set_stmt : ( print ) => group ( print . spaced ( [ "setKw" , "assignments" ] ) ) ,
@@ -110,22 +119,23 @@ export const proceduralLanguageMap: CstToDocMap<AllProceduralNodes> = {
110119 // BREAK/CONTINUE
111120 break_stmt : ( print ) => group ( print . spaced ( [ "breakKw" , "label" ] ) ) ,
112121 continue_stmt : ( print ) => group ( print . spaced ( [ "continueKw" , "label" ] ) ) ,
122+ // labels
113123 labeled_stmt : ( print , node ) =>
114124 group ( [
115- print ( "beginLabel" ) ,
116- ": " ,
117- print ( "statement" ) ,
125+ print . spaced ( [ "beginLabel" , "statement" ] ) ,
118126 node . endLabel ? [ " " , print ( [ "endLabel" ] ) ] : [ ] ,
119127 ] ) ,
128+ colon_label : ( print ) => [ print ( "label" ) , ":" ] ,
129+
120130 // CALL
121131 call_stmt : ( print ) => group ( print . spaced ( [ "callKw" , "func" ] ) ) ,
122132 // RETURN
123133 return_stmt : ( print ) => group ( print . spaced ( [ "returnKw" , "expr" ] ) ) ,
124134 // RAISE
125- raise_stmt : ( print ) => group ( print . spaced ( [ "raiseKw" , "message " ] ) ) ,
126- raise_message : ( print ) => [
127- print . spaced ( "usingMessageKw" ) ,
128- " = " ,
129- print ( "string" ) ,
130- ] ,
135+ raise_stmt : ( print ) => group ( print . spaced ( [ "raiseKw" , "using " ] ) ) ,
136+ raise_using_clause : ( print ) => group ( print . spaced ( [ "usingKw" , "options" ] ) ) ,
137+ raise_option_element : ( print ) => [ print ( "nameKw" ) , " = " , print ( "value" ) ] ,
138+ // ASSERT
139+ assert_stmt : ( print ) =>
140+ group ( print . spaced ( [ "assertKw" , "condition" , "message" ] ) ) ,
131141} ;
0 commit comments