Skip to content

Commit 78b927e

Browse files
committed
wip
1 parent e8f1e7e commit 78b927e

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

open_fortran_parser/ast_transformer.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,14 @@ def _transform_mpi_call(
484484
def _assignment(self, node: ET.Element):
485485
target = self.transform_all_subnodes(node.find('./target'))
486486
value = self.transform_all_subnodes(node.find('./value'))
487-
assert len(target) == 1, (ET.tostring(node).decode().rstrip(), target)
488-
assert len(value) == 1, (ET.tostring(node).decode().rstrip(), value)
487+
if len(target) != 1:
488+
raise SyntaxError(
489+
'exactly 1 target expected but {} given {} in:\n{}'
490+
.format(len(target), target, ET.tostring(node).decode().rstrip()))
491+
if len(value) != 1:
492+
raise SyntaxError(
493+
'exactly 1 value expected but {} given {} in:\n{}'
494+
.format(len(value), value, ET.tostring(node).decode().rstrip()))
489495
return typed_ast3.Assign(targets=[target], value=value, type_comment=None)
490496

491497
def _operation(self, node: ET.Element) -> typed_ast3.AST:
@@ -646,6 +652,31 @@ def _operator(
646652
# Invert: (typed_ast3.UnaryOp, typed_ast3.Invert)
647653
}[node.attrib['operator'].lower()]
648654

655+
def _array_constructor(self, node: ET.Element) -> typed_ast3.ListComp:
656+
values = node.findall('./value')
657+
if len(values) != 2:
658+
raise NotImplementedError('not implemented handling of:\n{}'.format(ET.tostring(node).decode().rstrip()))
659+
value = values[0]
660+
sub_values = value.find('./array-constructor-values')
661+
header_node = value.find('./header')
662+
header = self.transform_all_subnodes(header_node, warn=False)
663+
assert len(header) == 1
664+
comp_target, comp_iter = header[0]
665+
return typed_ast3.ListComp(
666+
elt=typed_ast3.Call(
667+
func=typed_ast3.Name(id='do_nothing', ctx=typed_ast3.Load()),
668+
args=[], keywords=[], starargs=None, kwargs=None),
669+
generators=[
670+
typed_ast3.comprehension(target=comp_target, iter=comp_iter, ifs=[], is_async=0)])
671+
672+
# "[ord(c) for line in file for c in line]"
673+
#_(elt=Call(func=Name(id='ord', ctx=Load()), args=[
674+
# Name(id='c', ctx=Load()),
675+
#], keywords=[], starargs=None, kwargs=None), generators=[
676+
# comprehension(target=Name(id='line', ctx=Store()), iter=Name(id='file', ctx=Load()), ifs=[], is_async=0),
677+
# comprehension(target=Name(id='c', ctx=Store()), iter=Name(id='line', ctx=Load()), ifs=[], is_async=0),
678+
#])
679+
649680
def _dimension(self, node: ET.Element) -> t.Union[typed_ast3.Num, typed_ast3.Index]:
650681
dim_type = node.attrib['type']
651682
if dim_type == 'simple':

src/fortran/ofp/XMLPrinter.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,21 @@ public void derived_type_spec(Token typeName, boolean hasTypeParamSpecList) {
530530
super.derived_type_spec(typeName, hasTypeParamSpecList);
531531
}
532532

533+
public void array_constructor() {
534+
context = contextNode(-1); // temporarily reopen previously-closed context
535+
if (verbosity >= 100)
536+
super.array_constructor();
537+
contextRename("array-constructor-values", "array-constructor");
538+
contextClose(); // re-close previously closed context
539+
}
540+
541+
public void ac_spec() {
542+
context = contextNode(-1); // temporarily reopen previously-closed context
543+
if (verbosity >= 100)
544+
super.ac_spec();
545+
contextClose(); // re-close previously closed context
546+
}
547+
533548
public void ac_value() {
534549
contextClose("value");
535550
if (verbosity >= 100)

0 commit comments

Comments
 (0)