Форматирование расширенного foreach

This commit is contained in:
Mikhalkovich Stanislav 2020-11-28 13:07:03 +03:00
parent 2c252b2b0c
commit 02c92a378d
14 changed files with 2279 additions and 1880 deletions

View file

@ -3441,9 +3441,28 @@ namespace CodeFormatters
}
public override void visit(bigint_const bi)
{
visit(new uint64_const(bi.val,bi.source_context));
visit(new uint64_const(bi.val, bi.source_context));
//sb.Append("bi");
}
public override void visit(foreach_stmt_formatting fe)
{
WriteKeyword("foreach");
SetKeywordOffset("foreach");
sb.Append(" var (");
visit_node(fe.il);
add_space_after = true;
add_space_before = true;
visit_node(fe.in_what);
if (!in_one_row(fe.stmt))
add_newline_after = true;
add_space_before = true;
bool need_off = !(fe.stmt is statement_list);
if (need_off)
IncOffset();
visit_node(fe.stmt);
if (need_off)
DecOffset();
}
#endregion
}
}

View file

@ -0,0 +1,6 @@
begin
var a := Arr(1..4);
repeat
a.Println;
until not NextPermutation(a);
end.

View file

@ -2,7 +2,7 @@
// This CSharp output file generated by Gardens Point LEX
// Version: 1.1.3.301
// Machine: DESKTOP-G8V08V4
// DateTime: 25.11.2020 21:07:09
// DateTime: 28.11.2020 12:31:01
// UserName: ?????????
// GPLEX input file <ABCPascal.lex>
// GPLEX frame file <embedded resource>

View file

@ -2980,6 +2980,23 @@ foreach_stmt
{
$$ = new foreach_stmt($3, new no_type_foreach(), $5, (statement)$7, @$);
}
| tkForeach tkVar tkRoundOpen ident_list tkRoundClose tkIn expr_l1 tkDo unlabelled_stmt // ñàõàðíîå ïðàâèëî
{
if (parsertools.build_tree_for_formatter)
{
var il = $4 as ident_list;
il.source_context = LexLocation.MergeAll(@4,@5);
$$ = new foreach_stmt_formatting(il,$7,$9 as statement,@$);
}
else
{
var id = NewId("#fe",@4);
var tttt = new assign_var_tuple($4 as ident_list, id, @$);
statement_list nine = $9 is statement_list ? $9 as statement_list : new statement_list($9 as statement,@9);
nine.Insert(0,tttt);
$$ = new foreach_stmt(id, new no_type_foreach(), $7, nine, @$);
}
}
;
foreach_stmt_ident_dype_opt

File diff suppressed because it is too large Load diff

View file

@ -290,6 +290,8 @@ script=

View file

@ -1287,6 +1287,11 @@ namespace PascalABCCompiler.SyntaxTree
{
DefaultVisit(_bigint_const);
}
public virtual void visit(foreach_stmt_formatting _foreach_stmt_formatting)
{
DefaultVisit(_foreach_stmt_formatting);
}
}

View file

@ -2053,6 +2053,14 @@ namespace PascalABCCompiler.SyntaxTree
{
}
public virtual void pre_do_visit(foreach_stmt_formatting _foreach_stmt_formatting)
{
}
public virtual void post_do_visit(foreach_stmt_formatting _foreach_stmt_formatting)
{
}
public override void visit(expression _expression)
{
DefaultVisit(_expression);
@ -4238,6 +4246,16 @@ namespace PascalABCCompiler.SyntaxTree
pre_do_visit(_bigint_const);
post_do_visit(_bigint_const);
}
public override void visit(foreach_stmt_formatting _foreach_stmt_formatting)
{
DefaultVisit(_foreach_stmt_formatting);
pre_do_visit(_foreach_stmt_formatting);
visit(foreach_stmt_formatting.il);
visit(foreach_stmt_formatting.in_what);
visit(foreach_stmt_formatting.stmt);
post_do_visit(_foreach_stmt_formatting);
}
}

View file

@ -532,6 +532,8 @@ namespace PascalABCCompiler.SyntaxTree
return new semantic_ith_element_of();
case 255:
return new bigint_const();
case 256:
return new foreach_stmt_formatting();
}
return null;
}
@ -4459,6 +4461,20 @@ namespace PascalABCCompiler.SyntaxTree
_bigint_const.val = br.ReadUInt64();
}
public void visit(foreach_stmt_formatting _foreach_stmt_formatting)
{
read_foreach_stmt_formatting(_foreach_stmt_formatting);
}
public void read_foreach_stmt_formatting(foreach_stmt_formatting _foreach_stmt_formatting)
{
read_statement(_foreach_stmt_formatting);
_foreach_stmt_formatting.il = _read_node() as ident_list;
_foreach_stmt_formatting.in_what = _read_node() as expression;
_foreach_stmt_formatting.stmt = _read_node() as statement;
}
}

View file

@ -6972,6 +6972,45 @@ namespace PascalABCCompiler.SyntaxTree
bw.Write(_bigint_const.val);
}
public void visit(foreach_stmt_formatting _foreach_stmt_formatting)
{
bw.Write((Int16)256);
write_foreach_stmt_formatting(_foreach_stmt_formatting);
}
public void write_foreach_stmt_formatting(foreach_stmt_formatting _foreach_stmt_formatting)
{
write_statement(_foreach_stmt_formatting);
if (_foreach_stmt_formatting.il == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_foreach_stmt_formatting.il.visit(this);
}
if (_foreach_stmt_formatting.in_what == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_foreach_stmt_formatting.in_what.visit(this);
}
if (_foreach_stmt_formatting.stmt == null)
{
bw.Write((byte)0);
}
else
{
bw.Write((byte)1);
_foreach_stmt_formatting.stmt.visit(this);
}
}
}

View file

@ -54517,6 +54517,229 @@ namespace PascalABCCompiler.SyntaxTree
}
///<summary>
///// для форматирования только
///</summary>
[Serializable]
public partial class foreach_stmt_formatting : statement
{
///<summary>
///Конструктор без параметров.
///</summary>
public foreach_stmt_formatting()
{
}
///<summary>
///Конструктор с параметрами.
///</summary>
public foreach_stmt_formatting(ident_list _il,expression _in_what,statement _stmt)
{
this._il=_il;
this._in_what=_in_what;
this._stmt=_stmt;
FillParentsInDirectChilds();
}
///<summary>
///Конструктор с параметрами.
///</summary>
public foreach_stmt_formatting(ident_list _il,expression _in_what,statement _stmt,SourceContext sc)
{
this._il=_il;
this._in_what=_in_what;
this._stmt=_stmt;
source_context = sc;
FillParentsInDirectChilds();
}
protected ident_list _il;
protected expression _in_what;
protected statement _stmt;
///<summary>
///
///</summary>
public ident_list il
{
get
{
return _il;
}
set
{
_il=value;
if (_il != null)
_il.Parent = this;
}
}
///<summary>
///
///</summary>
public expression in_what
{
get
{
return _in_what;
}
set
{
_in_what=value;
if (_in_what != null)
_in_what.Parent = this;
}
}
///<summary>
///
///</summary>
public statement stmt
{
get
{
return _stmt;
}
set
{
_stmt=value;
if (_stmt != null)
_stmt.Parent = this;
}
}
/// <summary> Создает копию узла </summary>
public override syntax_tree_node Clone()
{
foreach_stmt_formatting copy = new foreach_stmt_formatting();
copy.Parent = this.Parent;
if (source_context != null)
copy.source_context = new SourceContext(source_context);
if (attributes != null)
{
copy.attributes = (attribute_list)attributes.Clone();
copy.attributes.Parent = copy;
}
if (il != null)
{
copy.il = (ident_list)il.Clone();
copy.il.Parent = copy;
}
if (in_what != null)
{
copy.in_what = (expression)in_what.Clone();
copy.in_what.Parent = copy;
}
if (stmt != null)
{
copy.stmt = (statement)stmt.Clone();
copy.stmt.Parent = copy;
}
return copy;
}
/// <summary> Получает копию данного узла корректного типа </summary>
public new foreach_stmt_formatting TypedClone()
{
return Clone() as foreach_stmt_formatting;
}
///<summary> Заполняет поля Parent в непосредственных дочерних узлах </summary>
public override void FillParentsInDirectChilds()
{
if (attributes != null)
attributes.Parent = this;
if (il != null)
il.Parent = this;
if (in_what != null)
in_what.Parent = this;
if (stmt != null)
stmt.Parent = this;
}
///<summary> Заполняет поля Parent во всем поддереве </summary>
public override void FillParentsInAllChilds()
{
FillParentsInDirectChilds();
attributes?.FillParentsInAllChilds();
il?.FillParentsInAllChilds();
in_what?.FillParentsInAllChilds();
stmt?.FillParentsInAllChilds();
}
///<summary>
///Свойство для получения количества всех подузлов без элементов поля типа List
///</summary>
public override Int32 subnodes_without_list_elements_count
{
get
{
return 3;
}
}
///<summary>
///Свойство для получения количества всех подузлов. Подузлом также считается каждый элемент поля типа List
///</summary>
public override Int32 subnodes_count
{
get
{
return 3;
}
}
///<summary>
///Индексатор для получения всех подузлов
///</summary>
public override syntax_tree_node this[Int32 ind]
{
get
{
if(subnodes_count == 0 || ind < 0 || ind > subnodes_count-1)
throw new IndexOutOfRangeException();
switch(ind)
{
case 0:
return il;
case 1:
return in_what;
case 2:
return stmt;
}
return null;
}
set
{
if(subnodes_count == 0 || ind < 0 || ind > subnodes_count-1)
throw new IndexOutOfRangeException();
switch(ind)
{
case 0:
il = (ident_list)value;
break;
case 1:
in_what = (expression)value;
break;
case 2:
stmt = (statement)value;
break;
}
}
}
///<summary>
///Метод для обхода дерева посетителем
///</summary>
///<param name="visitor">Объект-посетитель.</param>
///<returns>Return value is void</returns>
public override void visit(IVisitor visitor)
{
visitor.visit(this);
}
}
}

View file

@ -2025,4 +2025,4 @@ namespace PascalABCCompiler.SyntaxTree
{
public object sl = null;
}
}
}

View file

@ -1540,6 +1540,12 @@ namespace PascalABCCompiler.SyntaxTree
///<param name="_bigint_const">Node to visit</param>
///<returns> Return value is void </returns>
void visit(bigint_const _bigint_const);
///<summary>
///Method to visit foreach_stmt_formatting.
///</summary>
///<param name="_foreach_stmt_formatting">Node to visit</param>
///<returns> Return value is void </returns>
void visit(foreach_stmt_formatting _foreach_stmt_formatting);
}

View file

@ -3301,6 +3301,18 @@
<TagIndices />
</Tags>
</SyntaxNode>
<SyntaxNode Name="foreach_stmt_formatting" BaseName="statement">
<Fields>
<SyntaxField Name="il" SyntaxType="ident_list" />
<SyntaxField Name="in_what" SyntaxType="expression" />
<SyntaxField Name="stmt" SyntaxType="statement" />
</Fields>
<Methods />
<Tags>
<CategoryIndices />
<TagIndices />
</Tags>
</SyntaxNode>
</SyntaxNodes>
<Settings>
<FileName>Tree.cs</FileName>
@ -3370,6 +3382,8 @@
<HelpData Key=".i" Value="" />
<HelpData Key=".if_false" Value="" />
<HelpData Key=".if_true" Value="" />
<HelpData Key=".il" Value="" />
<HelpData Key=".in_what" Value="" />
<HelpData Key=".index" Value="" />
<HelpData Key=".index_expr" Value="" />
<HelpData Key=".inverted" Value="" />
@ -3400,6 +3414,7 @@
<HelpData Key=".stat" Value="" />
<HelpData Key=".statements" Value="" />
<HelpData Key=".step" Value="" />
<HelpData Key=".stmt" Value="" />
<HelpData Key=".string" Value="" />
<HelpData Key=".subprogram_definitions" Value="" />
<HelpData Key=".substitution" Value="" />
@ -3411,6 +3426,7 @@
<HelpData Key=".to" Value="" />
<HelpData Key=".typ" Value="" />
<HelpData Key=".type" Value="" />
<HelpData Key=".type_name" Value="" />
<HelpData Key=".types" Value="" />
<HelpData Key=".unknown_foreach" Value="" />
<HelpData Key=".usings" Value="" />
@ -3846,6 +3862,11 @@
<HelpData Key="foreach_stmt.in_what" Value="" />
<HelpData Key="foreach_stmt.stmt" Value="" />
<HelpData Key="foreach_stmt.type_name" Value="" />
<HelpData Key="foreach_stmt_formatting" Value="// для форматирования только" />
<HelpData Key="foreach_stmt_formatting.il" Value="" />
<HelpData Key="foreach_stmt_formatting.in_what" Value="" />
<HelpData Key="foreach_stmt_formatting.stmt" Value="" />
<HelpData Key="foreach_stmt_formatting.type_name" Value="" />
<HelpData Key="formal_parameters" Value="" />
<HelpData Key="formal_parameters.formal_parameters Add(typed_parameters _typed_parameters)" Value="" />
<HelpData Key="formal_parameters.formal_parameters Add(typed_parameters _typed_parameters, SourceContext sc)" Value="" />