Skip to content

Commit 21685f5

Browse files
committed
Restructure block layout to be simpler
1 parent fe5e382 commit 21685f5

File tree

24 files changed

+256
-304
lines changed

24 files changed

+256
-304
lines changed

src/bash/bin/lingy-to-bash

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ sub make_data {
234234
for my $block (@{$ast->{data}}) {
235235
$i++;
236236
push @bash, '';
237-
push @bash, "TestML.block:$i:Label() { echo '$block->{label}'; }";
238-
for my $point (sort keys %{$block->{point}}) {
239-
my $value = $block->{point}{$point};
237+
push @bash, "TestML.block:$i:Label() { echo '$block->{Label}'; }";
238+
for my $point (sort keys %$block) {
239+
next if $point =~ /^[A-Z]/;
240+
my $value = $block->{$point};
240241
$value =~ s/([\\\"\`\$])/\\$1/g;
241242
if ($value =~ /\n/) {
242243
push @bash, qq<TestML.block:$i:$point() { echo \\\n"$value"; }>;

src/coffee/lib/testml/run.coffee

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class TestML.Run
290290
for block in @data
291291
@block = block
292292

293-
if block.point.ONLY and not @warned_only
293+
if block.ONLY and not @warned_only
294294
@err "Warning: TestML 'ONLY' in use."
295295
@warned_only = true
296296

@@ -303,8 +303,8 @@ class TestML.Run
303303
pick_exec: (list, expr)->
304304
pick = true
305305
for point in list
306-
if (point.match(/^\*/) and not @block.point[point[1..]]?) or
307-
(point.match(/^\!\*/) and @block.point[point[2..]]?)
306+
if (point.match(/^\*/) and not @block[point[1..]]?) or
307+
(point.match(/^\!\*/) and @block[point[2..]]?)
308308
pick = false
309309
break
310310

@@ -355,7 +355,7 @@ class TestML.Run
355355
#----------------------------------------------------------------------------
356356
getp: (name)->
357357
return unless @block
358-
value = @block.point[name]
358+
value = @block[name]
359359
value = @exec value if value?
360360
value
361361

@@ -429,7 +429,7 @@ class TestML.Run
429429
label = @exec label_expr
430430

431431
label ||= @getv('Label') || ''
432-
block_label = if @block? then @block.label else ''
432+
block_label = if @block? then @block.Label else ''
433433

434434
if label
435435
label = label.replace /^\+/, block_label
@@ -461,5 +461,5 @@ class TestML.Run
461461
@transform value, label
462462

463463
transform2: (name, label)=>
464-
return '' unless (value = @block?.point[name])?
464+
return '' unless (value = @block?[name])?
465465
@transform value, label

src/coffee/lib/testml/stdlib.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestML.StdLib
2424
block: (selector)->
2525
return @run.block if not selector?
2626
for block in @run.data
27-
if block.label == selector
27+
if block.Label == selector
2828
return block
2929
null
3030

src/perl/lib/TestML/Run.pm

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ sub each_pick {
410410
for my $block (@{$self->{ast}{data}}) {
411411
$self->{block} = $block;
412412

413+
if (defined $block->{ONLY} and not $self->{warned_only}) {
414+
$self->err("Warning: TestML 'ONLY' in use.");
415+
$self->{warned_only} = true;
416+
}
417+
413418
$self->exec_expr(['<>', $list, $expr]);
414419
}
415420

@@ -422,7 +427,7 @@ sub pick_exec {
422427
my ($self, $list, $expr) = @_;
423428

424429
my $pick = 1;
425-
if (my $when = $self->{block}{point}{WHEN}) {
430+
if (my $when = $self->{block}{WHEN}) {
426431
if ($when =~ /^Env:(\w+)$/) {
427432
$pick = 0 unless $ENV{$1};
428433
}
@@ -432,9 +437,9 @@ sub pick_exec {
432437
for my $point (@$list) {
433438
if (
434439
($point =~ /^\*/ and
435-
not exists $self->{block}{point}{substr($point, 1)}) or
440+
not exists $self->{block}{substr($point, 1)}) or
436441
($point =~ /^!*/) and
437-
exists $self->{block}{point}{substr($point, 2)}
442+
exists $self->{block}{substr($point, 2)}
438443
) {
439444
$pick = 0;
440445
last;
@@ -512,7 +517,7 @@ sub or_set_var {
512517
sub getp {
513518
my ($self, $name) = @_;
514519
return unless $self->{block};
515-
my $value = $self->{block}{point}{$name};
520+
my $value = $self->{block}{$name};
516521
$self->exec($value) if defined $value;
517522
}
518523

@@ -607,8 +612,8 @@ sub get_label {
607612

608613
my $block_label = (
609614
defined($self->{block}) and
610-
defined($self->{block}{label})
611-
) ? $self->{block}{label}
615+
defined($self->{block}{Label})
616+
) ? $self->{block}{Label}
612617
: '';
613618

614619
if ($label) {
@@ -668,7 +673,7 @@ sub transform1 {
668673
sub transform2 {
669674
my ($self, $name, $label) = @_;
670675
return '' unless $self->{block};
671-
my $value = $self->{block}{point}{$name};
676+
my $value = $self->{block}{$name};
672677
return '' unless defined $value;
673678
$self->transform($value, $label);
674679
}

src/perl/lib/TestML/StdLib.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ sub block {
1616
return $self->{run}{block}
1717
if not defined $selector;
1818
for my $block (@{$self->{run}{ast}{data}}) {
19-
if ($block->{label} eq $selector) {
19+
if ($block->{Label} eq $selector) {
2020
return $block;
2121
}
2222
}

src/python/lib/testml/run/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf8 -*-
22

3+
from __future__ import print_function
34
import json, os, re, sys
45

56
from testml.util import *
@@ -303,7 +304,7 @@ def each_pick(self, list_, expr):
303304
for block in self.ast.get('data', []):
304305
self.block = block
305306

306-
if block['point'].get('ONLY') and not self.warned_only:
307+
if block.get('ONLY') and not self.warned_only:
307308
self.err("Warning: TestML 'ONLY' in use.")
308309
self.warned_only = True
309310

@@ -315,9 +316,9 @@ def pick_exec(self, list_, expr):
315316
pick = True
316317
for point in list_:
317318
if (re.match(r'\*', point) and
318-
self.block['point'].get(point[1:])) == None or \
319+
self.block.get(point[1:])) == None or \
319320
(re.match(r'\!\*', point) and
320-
self.block['point'].get(point[2:])):
321+
self.block.get(point[2:])):
321322
pick = False
322323
break
323324

@@ -380,7 +381,7 @@ def or_set_var(self, name, expr):
380381
def getp(self, name):
381382
if not self.block:
382383
return
383-
value = self.block['point'].get(name)
384+
value = self.block.get(name)
384385
if value is not None:
385386
value = self.exec_(value)
386387
return value
@@ -453,7 +454,7 @@ def get_label(self, label_expr=''):
453454
if not label:
454455
label = ''
455456

456-
block_label = self.block['label'] if self.block else ''
457+
block_label = self.block['Label'] if self.block else ''
457458

458459
if label:
459460
label = re.sub(r'^\+', block_label, label)
@@ -490,7 +491,10 @@ def transform1(self, m, label):
490491

491492
def transform2(self, m, label):
492493
if not self.block: return ''
493-
value = self.block['point'].get(m.group(1))
494+
value = self.block.get(m.group(1))
494495
return self.transform(value, label) if value != None else ''
495496

497+
def err(self, msg):
498+
print(msg, file=sys.stderr)
499+
496500
# vim: sw=2:

src/python/lib/testml/stdlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def block(self, selector=None):
1818
return self.run.block
1919

2020
for block in self.run.ast.get('data', []):
21-
if block['label'] == selector:
21+
if block['Label'] == selector:
2222
return block
2323

2424
def blocks(self):

src/raku/lib/TestML/Run.pm6

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ method each-pick($list, $expr) {
345345
for |$!data -> $block {
346346
$!block = $block;
347347

348+
if defined $!block<ONLY> and not self.warned-only {
349+
self.err("Warning: TestML 'ONLY' in use.");
350+
self.warned-only = True;
351+
}
352+
348353
self.exec-expr(['<>', $list, $expr]);
349354
}
350355

@@ -357,9 +362,9 @@ method pick-exec($list, $expr) {
357362
my $pick = True;
358363
for |$list -> $point {
359364
if ($point ~~ /^\*/ and
360-
not $!block<point>{substr($point, 1)}:exists) or
365+
not $!block{substr($point, 1)}:exists) or
361366
($point ~~ /^\!\*/ and
362-
$!block<point>{substr($point, 2)}:exists
367+
$!block{substr($point, 2)}:exists
363368
) {
364369
$pick = False;
365370
last;
@@ -427,7 +432,7 @@ method or-set-var($name, $expr) {
427432
#------------------------------------------------------------------------------
428433
method getp($name) {
429434
return unless $!block;
430-
my $value = $!block<point>{$name};
435+
my $value = $!block{$name};
431436
self.exec($value) if $value.defined;
432437
}
433438

@@ -504,7 +509,7 @@ method get-label($label-expr='') {
504509

505510
$label ||= self.getv('Label') || '';
506511

507-
my $block-label = $!block ?? $!block<label> !! '';
512+
my $block-label = $!block ?? $!block<Label> !! '';
508513

509514
if $label {
510515
$label ~~ s/^\+/$block-label/;
@@ -553,7 +558,7 @@ method transform1($name, $label) {
553558

554559
method transform2($name, $label) {
555560
return '' unless $.block;
556-
my $value = $.block<point>{$name} // return '';
561+
my $value = $.block{$name} // return '';
557562
self.transform($value, $label);
558563
}
559564

src/raku/lib/TestML/StdLib.pm6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ method block($selector=Nil) {
1414
return $.run.block
1515
if not defined $selector;
1616
for $.run.data -> $block {
17-
if $block<label> eq $selector {
17+
if $block<Label> eq $selector {
1818
return $block;
1919
}
2020
}

src/ruby/lib/testml/run.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ def each_pick(list, expr)
412412

413413
@ast["data"].each do |block|
414414
@block = block
415+
416+
if @block["ONLY"] and not @warned_only
417+
self.err("Warning: TestML 'ONLY' in use")
418+
@warned_only = true
419+
end
420+
415421
self.exec_expr ['<>', list, expr]
416422
end
417423

@@ -424,8 +430,8 @@ def pick_exec(list, expr)
424430
pick = true
425431

426432
list.each do |point|
427-
if point.match /^\*/ and not @block["point"].key? point[1..-1] or
428-
point.match /^!*/ and @block["point"].key? point[2..-1]
433+
if point.match /^\*/ and not @block.key? point[1..-1] or
434+
point.match /^!*/ and @block.key? point[2..-1]
429435
throw point
430436
pick = false
431437
break
@@ -499,7 +505,7 @@ def get_point(name)
499505
# #------------------------------------------------------------------------------
500506
def getp(name)
501507
return unless @block
502-
value = @block["point"][name]
508+
value = @block[name]
503509
value = self.exec value if defined? value
504510
return value
505511
end
@@ -597,7 +603,7 @@ def get_label(label_expr)
597603

598604
# $label ||= $self->getv('Label') || '';
599605

600-
block_label = @block ? @block['label'] : ''
606+
block_label = @block ? @block['Label'] : ''
601607

602608
if label
603609
# $label =~ s/^\+/$block_label/;

0 commit comments

Comments
 (0)