search for a string between repetitive tags in a txt file - perl

Need some help with respect to search for a string between repetitive tags
I have a text file with following format repeating many times within a file
========== File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_1 START ==========
Block 1
TC ID OK
Block 2
Input section OK
data section OK
Block 3
Input section OK
data section OK
Block 4
Input section OK
data section OK
========== File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_2 START ========
Block 1
TC ID OK
Block 2
Input section OK
line mismatch:
output line: "Buffer allocated from pool: MIF_CTRL_POOL, buffer_id: 1, size (words): 4"
reference line: "pdcp_pdu_delete_count = 0, reset_cip_rdy = 1"
line mismatch:
output line: "pdcp_pdu_delete_count = 0, reset_cip_rdy = 1"
reference line: "-- MIF CTRL output: --------------------------------------------------------------------------------"
line mismatch:
output line: "-- MIF CTRL output: --------------------------------------------------------------------------------"
reference line: "mif_ctrl_rlc_am_um_reset_reestablish_ind_t.rlc_reset_reestablish_ind = 3 (0x0003)"
line mismatch:
output line: "mif_ctrl_rlc_am_um_reset_reestablish_ind_t.rlc_reset_reestablish_ind = 3 (0x0003)"
reference line: "Buffer released from pool: MIF_CTRL_POOL, buffer_id 0, size (words) 6 (used 5)"
line count mismatch:
last output line: "mif_ctrl_rlc_am_um_reset_reestablish_ind_t.rlc_reset_reestablish_ind = 3 (0x0003)"
last reference line: "Buffer released from pool: MIF_CTRL_POOL, buffer_id 0, size (words) 6 (used 5)"
data section DIFFERS
Block 3
Input section OK
data section OK
Block 4
Input section OK
data section OK
========== File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_3 START ========
Block 1
TC ID OK
Block 2
Input section OK
data section OK
Block 3
Input section OK
data section OK
Block 4
Input section OK
data section OK
**I need to find if anything other than 'OK' exists between the Start tags and if yes i have to mark the particular block as failed
for example if i find any other than OK between Test Case: Test_Case_1 START and Test Case: Test_Case_2 START i have to mark Test Case: Test_Case_1 as failed
UPDATED
Expected Output in somewhat this format
File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_1 Status: PASS
(if there is no string as 'DIFFERS' between tags (==)
File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_2 Status: FAILED
(if there is string 'DIFFERS' between tags (==)
UPDATE -2
If in case Test Case fails
File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_2 Status: FAILED
Section of block differing is:
Block 2
Input section OK
line mismatch:
output line: "Buffer allocated from pool: MIF_CTRL_POOL, buffer_id: 1, size (words): 4"
reference line: "pdcp_pdu_delete_count = 0, reset_cip_rdy = 1"
line mismatch:
output line: "pdcp_pdu_delete_count = 0, reset_cip_rdy = 1"
reference line: "-- MIF CTRL output: --------------------------------------------------------------------------------"
line mismatch:
output line: "-- MIF CTRL output: --------------------------------------------------------------------------------"
reference line: "mif_ctrl_rlc_am_um_reset_reestablish_ind_t.rlc_reset_reestablish_ind = 3 (0x0003)"
line mismatch:
output line: "mif_ctrl_rlc_am_um_reset_reestablish_ind_t.rlc_reset_reestablish_ind = 3 (0x0003)"
reference line: "Buffer released from pool: MIF_CTRL_POOL, buffer_id 0, size (words) 6 (used 5)"
line count mismatch:
last output line: "mif_ctrl_rlc_am_um_reset_reestablish_ind_t.rlc_reset_reestablish_ind = 3 (0x0003)"
last reference line: "Buffer released from pool: MIF_CTRL_POOL, buffer_id 0, size (words) 6 (used 5)"
data section DIFFERS

Wild guess:
while(<>) {print '**FAIL**' unless /TC ID OK/; print $_; }
But really, you should specify your requirements.

Maybe something quirky along the lines of the following:
#!/usr/bin/env perl
use strict;
use warnings;
my ($failed, $file, $test);
while (<>)
{
chomp;
next if /^$/;
if (/^=/)
{
print "$file $test Status: $failed\n" if $failed;
($file, $test) = ($_ =~ /(File Name:\s+\S+).+\b(Test Case: Test_Case_\d+)\b/);
$failed = 'PASSED';
next;
};
$failed = 'FAILED' if /\bDIFFERS\b/g;
}
print "$file $test Status: $failed\n";
Data
$ cat testdata
========== File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_1 START ==========
Block 1 TC ID OK
Block 2 Input section OK data section OK
Block 3 Input section OK data section OK
Block 4 Input section OK data section OK
========== File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_2 START ========
Block 1 TC ID OK
Block 2 Input section OK data section DIFFERS
Block 3 Input section OK data section OK
Block 4 Input section OK data section OK
Invocation
$ ./t.pl < testdata
File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_1 Status: PASSED
File Name: fixed_am_7bitLI_HE10.txt Test Case: Test_Case_2 Status: FAILED

Related

PF_RING 7.9.0 issue with deb package creation

I am trying to create deb packages for my work and have run into the following trouble.
The version of dkms being used as shown in the screen shot is 2.2.1.0. I have tried it out even with dkms 2.8.3 but I get the same error.
I am unsure what to do next or try next as I cannot understand.A little guidance is requested.
the exact issue that is being shown is the following. There is a Perl module named Dh_Lib.pm with a subroutine should_use_root() as shown below the error and the issue has been marked there.
Building binary package...dpkg-buildpackage: warning: using a gain-root-command while being root
dpkg-source --before-build .
fakeroot debian/rules clean
Initialization of state variables in list context currently forbidden at /usr/share/perl5/Debian/Debhelper/Dh_Lib.pm line 2021, near ");"
BEGIN not safe after errors--compilation aborted at /usr/share/perl5/Debian/Debhelper/Dh_Lib.pm line 2743.
Compilation failed in require at /usr/bin/dh_testdir line 11.
BEGIN failed--compilation aborted at /usr/bin/dh_testdir line 11.
make[1]: *** [debian/rules:25: clean] Error 2
dpkg-buildpackage: error: fakeroot debian/rules clean subprocess returned exit status 2
(bad exit status: 2)
Error! There was a problem creating your deb.
make: *** [Makefile.dkms:28: deb] Error 7
root#VEHERE:/home/vehere/Release/probe/deps/PF_RING-7.9.0/kernel#
# Return true if we should use root.
# - Takes an optional keyword; if passed, this will return true if the keyword is listed in R^3 (Rules-Requires-Root)
# - If the optional keyword is omitted or not present in R^3 and R^3 is not 'binary-targets', then returns false
# - Returns true otherwise (i.e. keyword is in R^3 or R^3 is 'binary-targets')
sub should_use_root {
my ($keyword) = #_;
my $rrr_env = $ENV{'DEB_RULES_REQUIRES_ROOT'} // 'binary-targets';
$rrr_env =~ s/^\s++//;
$rrr_env =~ s/\s++$//;
return 0 if $rrr_env eq 'no';
return 1 if $rrr_env eq 'binary-targets';
return 0 if not defined($keyword);
state %rrr = map { $_ => 1 } split(' ', $rrr_env); << ---- issues
return 1 if exists($rrr{$keyword});
return 0;
}
The version of perl being used is 5.24.1

How does mro, goto, and set_subname interact?

This is a complex question with regard to mro.pm, and the interplay with set_subname, and goto
In troubleshooting a problem, I think the core of my misunderstanding relates to how mro.pm works -- especially with regard to set_subname.
What is the difference between these three constructs,
Plain call to set_subname
*Foo::bar = set_subname( 'Foo::bar', $codeRef );
Anon sub which wraps a set_subname
*Foo::bar = sub {
my $codeRef2 = set_subname('Foo::bar', $codeRef);
goto $codeRef2
};
Anon sub which has its name set with set_subname
*Foo::bar = set_subname(
'Foo::bar',
sub { goto $codeRef }
);
Specifically, the Mojo test suits fails with either of these modifications with anon subs applied to Mojo::Utils's monkey_patch Running the two variants above against t/mojo/websocket_proxy.t,
With the 2 (second) option I have
*{"${class}::$k"} = sub {
my $cr = set_subname("${class}::$k", $patch{$k});
goto $cr;
};
And I get
Mojo::Reactor::Poll: Timer failed: Can't locate object method "send" via package "Mojo::Transaction::HTTP" at t/mojo/websocket_proxy.t line 66.
With the 3 (third) option I have,
*{"${class}::$k"} = set_subname("${class}::$k", sub { goto $patch{$k} })
And I get
No next::method 'new' found for Mojolicious::Routes at /usr/lib/x86_64-linux-gnu/perl/5.28/mro.pm line 30.
Obviously, the first version works (it's from the code I linked), the question is why are the other two variants giving me different errors (especially the second variant) and what's happening there -- why don't they work?
Your second option is not working because the sub you are using as a wrapper does not match the prototype of the inner sub. monkey_patch is not only used for methods, and this changes how some functions are parsed. In particular, Mojo::Util::steady_time has an empty prototype and is often called without using parenthesis.
*{"${class}::$k"} = Sub::Util::set_prototype(
Sub::Util::prototype( $patch{$k} ),
Sub::Util::set_subname(
"${class}::$k",
sub {
my $cr = Sub::Util::set_subname("${class}::$k", $patch{$k});
goto $cr;
}
)
);
The third construct is not working because you are using goto to remove the renamed wrapper sub from the call stack, leaving only the inner sub which has no name. This breaks next::method's ability to find the correct method name.
That is indeed complicated, but maybe you overcomplicated it?
Remember that MRO is only concerned with locating a method, which is just a symbol table entry to a coderef, through a defined order of package names. The internal subname only has to do with what caller() reports AFAIK.
From: Mojo
*{"${class}::$_"} = ## symbol table entry
set_subname("${class}::$_", ## an internal name
$patch{$_}) ## for a code ref
for keys %patch;
HTH
Edit After Seeing Error Messages:
The subroutines have not been validly installed. I suspect that since in option 2 and 3 you are deferring the calls to set_subname() to call time, the coderef $patch{$k} never has a subname assigned to it and that breaks a link in the chain of mro::_nextcan()'s XS magic. Particularly if $patch{$k} calls next::method. The closures seem to be valid though.
Although I must say my testing seems to show that option 2 is valid.
Enter command: my ($class, $k) = qw/W S/; my %patch = (S =>
sub {print "patch here\n"; decall;}); *{"${class}::$k"} =
sub { print "goto'r here\n"; my $cr = set_subname("${class}::$k",
$patch{$k}); goto $cr;};
Enter command: decall
0 "console"
1 "console.pl"
2 "114"
3 "(eval)"
4 "0"
5 0
6 "package W; decall"
7 ""
8 "256"
9 "\020\001\000\000\000P\004\000\000\000\000\000\000U\025U\005"
10 0
Enter command: S
goto'r here
patch here
0 "W"
1 "(eval 110)"
2 "1"
3 "W::S"
4 "1"
5 0
6 0
7 0
8 "256"
9 "\020\001\000\000\000P\004\000\000\000\000\000\000U\025U\005"
10 0
You might have to start looking farther afield for the problem with option 2.
After modifying Mojo/Util.pm with
foreach my $k (keys %patch) {
*{"${class}::$k"} = sub {
my $cr = set_subname("${class}::$k", $patch{$k});
goto $cr;
};
}
and isolating the test case, I get:
$ perl -MCarp::Always t/mojo/websocket_proxy2.t
Mojo::Reactor::Poll: Timer failed: Can't locate object method "send" via package "Mojo::Transaction::HTTP" at t/mojo/websocket_proxy2.t line 59.
main::__ANON__(Mojo::UserAgent=HASH(0x60280dad0), Mojo::Transaction::HTTP=HASH(0x6029ee7b0)) called at blib/lib/Mojo/UserAgent.pm line 252
Mojo::UserAgent::_finish(Mojo::UserAgent=HASH(0x60280dad0), "927210c53042c6142eda3f4010c8b17c", 1) called at blib/lib/Mojo/UserAgent.pm line 220
Mojo::UserAgent::_error(Mojo::UserAgent=HASH(0x60280dad0), "927210c53042c6142eda3f4010c8b17c", "Connect timeout") called at blib/lib/Mojo/UserAgent.pm line 128
Mojo::UserAgent::__ANON__(Mojo::IOLoop=HASH(0x601f9abb8), "Connect timeout", undef) called at blib/lib/Mojo/IOLoop.pm line 63
Mojo::IOLoop::__ANON__(Mojo::IOLoop::Client=HASH(0x601e34598)) called at blib/lib/Mojo/EventEmitter.pm line 15
Mojo::EventEmitter::emit(Mojo::IOLoop::Client=HASH(0x601e34598), "error", "Connect timeout") called at blib/lib/Mojo/IOLoop/Client.pm line 39
Mojo::IOLoop::Client::__ANON__(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/Reactor/Poll.pm line 143
eval {...} called at blib/lib/Mojo/Reactor/Poll.pm line 143
Mojo::Reactor::Poll::_try(Mojo::Reactor::Poll=HASH(0x6001a8390), "Timer", CODE(0x601e24ca0)) called at blib/lib/Mojo/Reactor/Poll.pm line 81
Mojo::Reactor::Poll::one_tick(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/Reactor/Poll.pm line 99
Mojo::Reactor::Poll::start(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/IOLoop.pm line 134
Mojo::IOLoop::start("Mojo::IOLoop") called at t/mojo/websocket_proxy2.t line 62
at blib/lib/Mojo/IOLoop.pm line 23.
Mojo::IOLoop::__ANON__(Mojo::Reactor::Poll=HASH(0x6001a8390), "Timer failed: Can't locate object method \"send\" via package \"Mojo::Transaction::HTTP\" at t/mojo/websocket_proxy2.t line 59.\x{a}\x{9}main::__ANON__(Mojo::UserAgent=HASH(0x60280dad0), Mojo::Transaction::HTTP=HASH(0x6029ee7b0)) called at blib/lib/Mojo/UserAgent.pm line 252\x{a}\x{9}Mojo::UserAgent::_finish(Mojo::UserAgent=HASH(0x60280dad0), \"927210c53042c6142eda3f4010c8b17c\", 1) called at blib/lib/Mojo/UserAgent.pm line 220\x{a}\x{9}Mojo::UserAgent::_error(Mojo::UserAgent=HASH(0x60280dad0), \"927210c53042c6142eda3f4010c8b17c\", \"Connect timeout\") called at blib/lib/Mojo/UserAgent.pm line 128\x{a}\x{9}Mojo::UserAgent::__ANON__(Mojo::IOLoop=HASH(0x601f9abb8), \"Connect timeout\", undef) called at blib/lib/Mojo/IOLoop.pm line 63\x{a}\x{9}Mojo::IOLoop::__ANON__(Mojo::IOLoop::Client=HASH(0x601e34598)) called at blib/lib/Mojo/EventEmitter.pm line 15\x{a}\x{9}Mojo::EventEmitter::emit(Mojo::IOLoop::Client=HASH(0x601e34598), \"error\", \"Connect timeout\") called at blib/lib/Mojo/IOLoop/Client.pm line 39\x{a}\x{9}Mojo::IOLoop::Client::__ANON__(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/Reactor/Poll.pm line 143\x{a}\x{9}eval {...} called at blib/lib/Mojo/Reactor/Poll.pm line 143\x{a}\x{9}Mojo::Reactor::Poll::_try(Mojo::Reactor::Poll=HASH(0x6001a8390), \"Timer\", CODE(0x601e24ca0)) called at blib/lib/Mojo/Reactor/Poll.pm line 81\x{a}\x{9}Mojo::Reactor::Poll::one_tick(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/Reactor/Poll.pm line 99\x{a}\x{9}Mojo::Reactor::Poll::start(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/IOLoop.pm line 134\x{a}\x{9}Mojo::IOLoop::start(\"Mojo::IOLoop\") called at t/mojo/websocket_proxy2.t line 62\x{a}") called at blib/lib/Mojo/EventEmitter.pm line 15
Mojo::EventEmitter::emit(Mojo::Reactor::Poll=HASH(0x6001a8390), "error", "Timer failed: Can't locate object method \"send\" via package \"Mojo::Transaction::HTTP\" at t/mojo/websocket_proxy2.t line 59.\x{a}\x{9}main::__ANON__(Mojo::UserAgent=HASH(0x60280dad0), Mojo::Transaction::HTTP=HASH(0x6029ee7b0)) called at blib/lib/Mojo/UserAgent.pm line 252\x{a}\x{9}Mojo::UserAgent::_finish(Mojo::UserAgent=HASH(0x60280dad0), \"927210c53042c6142eda3f4010c8b17c\", 1) called at blib/lib/Mojo/UserAgent.pm line 220\x{a}\x{9}Mojo::UserAgent::_error(Mojo::UserAgent=HASH(0x60280dad0), \"927210c53042c6142eda3f4010c8b17c\", \"Connect timeout\") called at blib/lib/Mojo/UserAgent.pm line 128\x{a}\x{9}Mojo::UserAgent::__ANON__(Mojo::IOLoop=HASH(0x601f9abb8), \"Connect timeout\", undef) called at blib/lib/Mojo/IOLoop.pm line 63\x{a}\x{9}Mojo::IOLoop::__ANON__(Mojo::IOLoop::Client=HASH(0x601e34598)) called at blib/lib/Mojo/EventEmitter.pm line 15\x{a}\x{9}Mojo::EventEmitter::emit(Mojo::IOLoop::Client=HASH(0x601e34598), \"error\", \"Connect timeout\") called at blib/lib/Mojo/IOLoop/Client.pm line 39\x{a}\x{9}Mojo::IOLoop::Client::__ANON__(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/Reactor/Poll.pm line 143\x{a}\x{9}eval {...} called at blib/lib/Mojo/Reactor/Poll.pm line 143\x{a}\x{9}Mojo::Reactor::Poll::_try(Mojo::Reactor::Poll=HASH(0x6001a8390), \"Timer\", CODE(0x601e24ca0)) called at blib/lib/Mojo/Reactor/Poll.pm line 81\x{a}\x{9}Mojo::Reactor::Poll::one_tick(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/Reactor/Poll.pm line 99\x{a}\x{9}Mojo::Reactor::Poll::start(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/IOLoop.pm line 134\x{a}\x{9}Mojo::IOLoop::start(\"Mojo::IOLoop\") called at t/mojo/websocket_proxy2.t line 62\x{a}") called at blib/lib/Mojo/Reactor/Poll.pm line 143
Mojo::Reactor::Poll::_try(Mojo::Reactor::Poll=HASH(0x6001a8390), "Timer", CODE(0x601e24ca0)) called at blib/lib/Mojo/Reactor/Poll.pm line 81
Mojo::Reactor::Poll::one_tick(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/Reactor/Poll.pm line 99
Mojo::Reactor::Poll::start(Mojo::Reactor::Poll=HASH(0x6001a8390)) called at blib/lib/Mojo/IOLoop.pm line 134
Mojo::IOLoop::start("Mojo::IOLoop") called at t/mojo/websocket_proxy2.t line 62
I can also confirm that setting the prototype fixes it.

How to save names in a Qbasic file?

I am trying to create a program in Qbasic wherein a person can enter their name and label themselves as admin or unwanted user. How do I save these preferences in my program?
If you have inputed the username with something like,
INPUT "Type your username: ", uName$
To save it to a file, simply use these commands:
OPEN "User.dat" FOR OUTPUT AS #1
PRINT #1, uName$
CLOSE #1
Here's a complete program:
DEFINT A-Z
'Error handler for the first time we run the program. The data file won't exist, so we create it.
ON ERROR GOTO FileNotExist
'Create a type and an Array of users that would include Username and the Status (adminstrator vs. Unwanted user)
TYPE user
Uname AS STRING * 16
Status AS STRING * 1
END TYPE
DIM Users(1 TO 100) AS user
'Gets all the users stored in the file. i is a variable which represents the number of users before adding a new user
i = 0
OPEN "User.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
i = i + 1
INPUT #1, Users(i).Uname
INPUT #1, Users(i).Status
WEND
CLOSE #1
TryAgain:
'Gets info for the new user
CLS
INPUT "User name: ", Users(i + 1).Uname
PRINT "Admin (a), Unwanted user (u), or Regular user (r) ?"
Users(i + 1).Status = LCASE$(INPUT$(1))
'Ensure there are no blank lines in the file
IF Users(i + 1).Uname = "" OR Users(i + 1).Status = "" THEN GOTO TryAgain
'Outputs user data to the file "User.txt"
OPEN "User.txt" FOR OUTPUT AS #1
FOR j = 1 TO i + 1
PRINT #1, Users(j).Uname
PRINT #1, Users(j).Status
NEXT j
CLOSE #1
'Just for a closer: Prints all the current users.
CLS
FOR j = 1 TO i + 1
PRINT Users(j).Uname,
IF Users(j).Status = "a" THEN PRINT "Amdinistrator" ELSE IF Users(j).Status = "u" THEN PRINT "Unwanted User" ELSE IF Users(j).Status = "r" THEN PRINT "Regular user" ELSE PRINT Users(j).Status
NEXT j
END
'*** ERROR HANDLER: ***
FileNotExist:
OPEN "User.txt" FOR OUTPUT AS #1
CLOSE
RESUME
To save a name into a file, you will need to use the WRITE statement.
Eg:
OPEN "Name.txt" FOR OUTPUT AS #1
INPUT"Enter a name";a$
WRITE #1,a$
CLOSE #1
END

Xtext 2.8+ formatter, formatting HiddenRegion with comment

I am using Xtext 2.9 formatter and I am trying to format hiddenRegion which contains comment. Here is part of my document region i am trying to format:
Columns: 1:offset 2:length 3:kind 4: text 5:grammarElement
Kind: H=IHiddenRegion S=ISemanticRegion B/E=IEObjectRegion
35 0 H
35 15 S ""xxx::a::b"" Refblock:namespace=Namespace
50 0 H
50 1 S "}" Refblock:RCBRACKET
E Refblock PackageHead:Block=Refblock path:PackageHead/Block=Package'xxx_constants'/head=Model/packages[0]
51 0 H
51 1 S ":" PackageHead:COLON
E PackageHead Package:head=PackageHead path:Package'xxx_constants'/head=Model/packages[0]
52 >>>H "\n " Whitespace:TerminalRule'WS'
"# asd" Comment:TerminalRule'SL_COMMENT'
15 "\n " Whitespace:TerminalRule'WS'<<<
B Error'ASSD' Package:expressions+=Expression path:Package'xxx_constants'/expressions[0]=Model/packages[0]
67 5 S "error" Error:'error'
72 1 H " " Whitespace:TerminalRule'WS'
and corresponding part of the grammar
Model:
{Model}
(packages+=Package)*;
Expression:
Error | Warning | Enum | Text;
Package:
{Package}
'package' name=Name head=PackageHead
(BEGIN
(imports+=Import)*
(expressions+=Expression)*
END)?;
Error:
{Error}
('error') name=ENAME parameter=Parameter COLON
(BEGIN
(expressions+=Estatement)+
END)?;
PackageHead:
Block=Refblock COLON;
Problem is that when i try prepend some characters before error keyword
for example
error.regionFor.keyword('error').prepend[setSpace("\n ")]
This indentation is prepended before the comment and not behind it. This results into improper formatting in case of single line comment before the 'error' keyword.
To provide more clarity, here is example code from my grammar and description of desired behavior:
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
This is expected result: (one space to the left)
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
and this is the actual result with prepend method
package xxx_constants {namespace="xxx::a::b"}:
# asd
error ASSD {0}:
Hello {0,world}
As the document structure says, the HiddenRegion is in this case is the statement:
# asd
error
How can i prepend my characters directly before the keyword 'error' and not before the comment? Thanks.
I assume you're creating an indentation-sensitive language, because you're explicitly calling BEGIN and END.
For indentation-sensitive language my answer is: You'll want to overwrite
org.eclipse.xtext.formatting2.internal.HiddenRegionReplacer.applyHiddenRegionFormatting(List<ITextReplacer>)
The methods append[] and prepend[] you're using are agnostic to comments and at a later time applyHiddenRegionFormatting() is called to decide how that formatting is weaved between comments.
To make Xtext use your own subclass of HiddenRegionReplacer, overwrite
org.eclipse.xtext.formatting2.AbstractFormatter2.createHiddenRegionReplacer(IHiddenRegion, IHiddenRegionFormatting)
For languages that do not do whitespace-sensitive lexing/parsing (that's the default) the answer is to not call setSpace() to create indentation or line-wraps.
Instead, do
pkg.interior[indent]
pkg.regionFor.keyword(":").append[newLine]
pkg.append[newLine]

Re-Use of a line fails as "`r" doesn't move the 'line-pointer' ("`b" fails as well)

As C# does not has the options of powershell's write-progress I start to try to 're-use' the same line:
function ReUseFails {
$x=0
$nDec = 10
while ($true) {
$x++
$a = $x.ToString().PadLeft($nDec)
$z = $x.ToString().PadLeft($nDec)
Write-Host "`r$a $z" -noNewLine
Start-Sleep -s 1
}
}
ReUseFails
I expected because of `r (carriage return) to see in the same line (the next line overrides the prev.):
1 1 # and after 1 Second in that line:
2 2 # after the 2nd second
3 3 # (and so on)
but what I get is
1 1 2 2 3 3 4 4 ...
So the carriage return r has no effect?<br>
Is there a way to 'enable' thisr??
Even when I try to use `b I see additional spots but not a back-space.
Can it be that the DOS-console can do that (to show a spinning wheel) but bot the PS-console?
Regards