if_statement
This commit is contained in:
parent
6303f6c3d8
commit
e37e2fdea1
2 changed files with 167 additions and 0 deletions
156
corpus/plpgsql/if_statement.txt
Normal file
156
corpus/plpgsql/if_statement.txt
Normal file
|
@ -0,0 +1,156 @@
|
|||
================================================================================
|
||||
basic
|
||||
================================================================================
|
||||
do $$ begin
|
||||
if true then select 1; end if;
|
||||
end $$;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(do_block
|
||||
(block
|
||||
(dollar_quote)
|
||||
(body
|
||||
(if_statement
|
||||
(true)
|
||||
(select_statement
|
||||
(select_item
|
||||
(number)))))
|
||||
(dollar_quote))))
|
||||
|
||||
================================================================================
|
||||
many statements
|
||||
================================================================================
|
||||
do $$ begin
|
||||
if true then select 1; select 2; end if;
|
||||
end $$;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(do_block
|
||||
(block
|
||||
(dollar_quote)
|
||||
(body
|
||||
(if_statement
|
||||
(true)
|
||||
(select_statement
|
||||
(select_item
|
||||
(number)))
|
||||
(select_statement
|
||||
(select_item
|
||||
(number)))))
|
||||
(dollar_quote))))
|
||||
|
||||
================================================================================
|
||||
if then else
|
||||
================================================================================
|
||||
do $$ begin
|
||||
if var <> 5 then return 1; else return 2; end if;
|
||||
end $$;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(do_block
|
||||
(block
|
||||
(dollar_quote)
|
||||
(body
|
||||
(if_statement
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(number))
|
||||
(return_statement
|
||||
(number))
|
||||
(return_statement
|
||||
(number))))
|
||||
(dollar_quote))))
|
||||
|
||||
================================================================================
|
||||
if then else if
|
||||
================================================================================
|
||||
do $$ begin
|
||||
if var > 5 then return 1; elsif var = 4 then return 2; end if;
|
||||
end $$;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(do_block
|
||||
(block
|
||||
(dollar_quote)
|
||||
(body
|
||||
(if_statement
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(number))
|
||||
(return_statement
|
||||
(number))
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(number))
|
||||
(return_statement
|
||||
(number))))
|
||||
(dollar_quote))))
|
||||
|
||||
================================================================================
|
||||
elseif/elsif
|
||||
================================================================================
|
||||
do $$ begin
|
||||
if var > 5 then return 1; elsif var = 4 then return 2; elseif var = 3 then return 3; else return 4; end if;
|
||||
end $$;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(do_block
|
||||
(block
|
||||
(dollar_quote)
|
||||
(body
|
||||
(if_statement
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(number))
|
||||
(return_statement
|
||||
(number))
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(number))
|
||||
(return_statement
|
||||
(number))
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(number))
|
||||
(return_statement
|
||||
(number))
|
||||
(return_statement
|
||||
(number))))
|
||||
(dollar_quote))))
|
||||
|
||||
================================================================================
|
||||
nested
|
||||
================================================================================
|
||||
do $$ begin
|
||||
if true then return 1; else if var = 4 then return 2; end if; end if;
|
||||
end $$;
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(do_block
|
||||
(block
|
||||
(dollar_quote)
|
||||
(body
|
||||
(if_statement
|
||||
(true)
|
||||
(return_statement
|
||||
(number))
|
||||
(if_statement
|
||||
(op_expression
|
||||
(identifier)
|
||||
(comparison_op)
|
||||
(number))
|
||||
(return_statement
|
||||
(number)))))
|
||||
(dollar_quote))))
|
11
grammar.js
11
grammar.js
|
@ -384,12 +384,23 @@ module.exports = grammar({
|
|||
$._statement,
|
||||
$.assign_statement,
|
||||
$.return_statement,
|
||||
$.if_statement,
|
||||
$.execute_statement,
|
||||
$.perform_statement,
|
||||
),
|
||||
";",
|
||||
),
|
||||
|
||||
if_statement: $ => seq(
|
||||
kw("if"), $._value_expression, kw("then"), repeat1($._plpgsql_statement),
|
||||
repeat(seq(
|
||||
choice(kw("elsif"), kw("elseif")),
|
||||
$._value_expression, kw("then"), repeat1($._plpgsql_statement)
|
||||
)),
|
||||
optional(seq(kw("else"), repeat1($._plpgsql_statement))),
|
||||
kw("end"), kw("if"),
|
||||
),
|
||||
|
||||
execute_statement: $ => seq(
|
||||
kw("execute"),
|
||||
$._value_expression,
|
||||
|
|
Loading…
Reference in a new issue