Call a token of rule B from rule A - antlr

I would like to know if and how I can call a token of rule B from rule A, as in the example below:
//Rule A
description
:'Description' ':' primaryActor.actorName ...... //I tried this way, but it doesn't work.
;
//Rule B1
primaryActor
:actorName PA_TYPE
;
//Rule B2
secondaryActor
:actorName SA_TYPE
;
actorName
:ARTICLE SMALL_NOUN
;
/* ... */
So, 'primaryActor' and 'secondaryActor' both have an 'actorName'. If we write a test in the interpreter such as "Description: a Doctor...", 'Doctor should be assigned to 'primaryActor.actorName. Because 'actorName' is of the same type for both primary and secondary actors, I don't want to create an actorName for each one of them but being able to distinguish the actorName through its including rule.

Related

Asterisk in variable not considered like % in SQL

I created these three radio buttons to define values to the variable TEST.
The first two work just fine: if I click in p_r1 it assigns B and if I click p_r2 it assigns A.
I wanted the third to assign * to get all status i.e A, B, C.
Why doesn't it work? Isn't * a special character that means all like % in SQL?
DATA: TEST TYPE C.
PARAMETERS:
P_R1 RADIOBUTTON GROUP GRP1 DEFAULT 'X',
P_R2 RADIOBUTTON GROUP GRP1,
P_R3 RADIOBUTTON GROUP GRP1.
IF P_R1 = 'X'.
TEST = 'B'.
ELSEIF P_R2 = 'X'.
TEST = 'A'.
ELSEIF P_R3 = 'X'.
TEST = '*'.
ENDIF.
SELECT VBELN,GBSTK
FROM LIKP
WHERE GBSTK = #TEST
INTO TABLE #DATA(IT_FINAL).
CL_DEMO_OUTPUT=>DISPLAY( IT_FINAL ).
A few things to keep in mind to make your requirement work:
An = or EQ in the where condition does not allow for wildcards. I.e. when test equals '*' in your example it will only find entries in the database table where GBSTK equals '*', most probably zero entries
To use wildcards you need to use LIKE instead of = or EQ
The general wild card to mach any string is '%' and not '*'
For more details check the SAP help for SELECT - WHERE for your specific version. Here is the one for 752: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapwhere.htm?file=abapwhere.htm

extract sub string from string in oracle

I have one of the following string :
(,QUESTION-3914~Please enter the unique identification number associated with the IRQ.|3~Greater Than|5~5,AND,QUESTION-3920~Select the contract action that applies to this IRQ.|5~Equal To|LOV1274~New Agreement,),AND,QUESTION-3921~If "New Agreement#comma#" which type of New Agreement is being requested?|5~Equal To|y~Yes,OR,NOT,(,QUESTION-3923~Will the Third Party Relationship support the implementation#comma# pilot#comma# launch#comma# or operation of a New Activity (as defined in the New Activity Risk Management Policy)?|5~Equal To|y~Yes,)
I want required ouput for this string is like :-
(,QUESTION-3914|3|5,AND,QUESTION-3920|5|LOV1274,),AND,QUESTION-3921|5|y,OR,NOT,(,QUESTION-3923)|5|y,)
What should i do for this ?
Use a regular expression to replace everything from each ~ tilde character until the next comma , or pipe | character (exclusive of that final character):
Oracle Setup:
CREATE TABLE your_data ( input_string ) AS
SELECT '(,QUESTION-3914~Please enter the unique identification number associated with the IRQ.|3~Greater Than|5~5,AND,QUESTION-3920~Select the contract action that applies to this IRQ.|5~Equal To|LOV1274~New Agreement,),AND,QUESTION-3921~If "New Agreement#comma#" which type of New Agreement is being requested?|5~Equal To|y~Yes,OR,NOT,(,QUESTION-3923~Will the Third Party Relationship support the implementation#comma# pilot#comma# launch#comma# or operation of a New Activity (as defined in the New Activity Risk Management Policy)?|5~Equal To|y~Yes,)' FROM DUAL
Query:
SELECT REGEXP_REPLACE( input_string, '~.*?([|,])', '\1' ) AS output
FROM your_data d
Output:
| OUTPUT |
| :--------------------------------------------------------------------------------------------------- |
| (,QUESTION-3914|3|5,AND,QUESTION-3920|5|LOV1274,),AND,QUESTION-3921|5|y,OR,NOT,(,QUESTION-3923|5|y,) |
db<>fiddle here

Check constraint for Emails in an Oracle Database

I've searched everywhere for a decent and logical CHECK constraint to validate that an email is in the right format. So far I've found really long and unnecessary expressions like:
create table t (
email varchar2(320) check (
regexp_like(email, '[[:alnum:]]+#[[:alnum:]]+\.[[:alnum:]]')
)
);
and
create table stk_t (
email varchar2(320) check (
email LIKE '%#%.%' AND email NOT LIKE '#%' AND email NOT LIKE '%#%#%'
)
);
Surely there is a simpler way?
I'm using Oracle 11g database and SQL Developer IDE.
This is what I have:
constraint Emails_Check check (Emails LIKE '%_#%_._%')
Can someone please let me know if this is the most efficient way of validating emails?
You can try this
email varchar2(255) check (
email LIKE '%#%.%' AND email NOT LIKE '#%' AND email NOT LIKE '%#%#%' )
CREATE TABLE MYTABLE(
EMAIL VARCHAR2(30) CHECK(REGEXP_LIKE (EMAIL,'^[A-Za-z]+[A-Za-z0-9.]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$'))
)
Explanation of Regular Expression
^ #start of the line
[_A-Za-z0-9-]+ # must start with string in the bracket [ ], must contains one or more (+)
( # start of group #1
\\.[_A-Za-z0-9-]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #1, this group is optional (*)
# # must contains a "#" symbol
[A-Za-z0-9]+ # follow by string in the bracket [ ], must contains one or more (+)
( # start of group #2 - first level TLD checking
\\.[A-Za-z0-9]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #2, this group is optional (*)
( # start of group #3 - second level TLD checking
\\.[A-Za-z]{2,} # follow by a dot "." and string in the bracket [ ], with minimum length of 2
) # end of group #3
$ #end of the line
Stumbled upon this answer while hunting for a simple solution on the internet:
ALTER TABLE YourTableName
ADD CONSTRAINT YourConstraintName CHECK(YourColumnName LIKE '%___#___%.__%')
All points to #bhanu_nz here

Passing a module name as parameter

I want to create this generic wrapper for a bunch of modules I am writing. The wrapper should provide the ability to connect these modules to different type of NoCs without having to change the behavior of the inner modules.
I thought that one way to do this would be the following.
Considering a very simple module to wrap:
module add #(
parameter COLUMN_WIDTH = 32
)
(
//data in
input logic [COLUMN_WIDTH-1:0] col_1,
input logic [COLUMN_WIDTH-1:0] col_2,
//data out
output logic [COLUMN_WIDTH-1:0] col_o
);
assign col_o = col_1 + col_2;
endmodule
The wrapper should be the following:
module wrapper #(
parameter COLUMN_WIDTH = 32,
parameter WRAPPED_MODULE = add
)
(
//data in
input logic [COLUMN_WIDTH-1:0] col_1,
input logic [COLUMN_WIDTH-1:0] col_2,
//data out
output logic [COLUMN_WIDTH-1:0] col_o,
/* std signals */
input logic clk,
input logic reset_i // reset everything
);
logic [COLUMN_WIDTH-1:0] max_result;
WRAPPED_MODULE #(.COLUMN_WDITH(COLUMN_WIDTH),
) a(
.*
);
always #(posedge clk) begin
if (reset_i)
max_result <= 0;
else
max_result <= (col_o > max_result) ? col_o : max_result;
end
endmodule
The error I get is the following:
Error-[IND] Identifier not declared
wrapper.sv, 4
Identifier 'add' has not been declared yet. If this error is not expected,
please check if you have set `default_nettype to none.
Which makes sense since a parameter is not the same as a macro.
A complete design should possibly instantiate a bunch of wrapped modules and I don't want to duplicate code by creating a wrapper for each inner module.
How can I do that?
A parameter cannot be a module name. It can be a data_type, implicit data_type, or type
IEEE Std 1800-2012 ยง A.2.1.1 Module parameter declarations:
parameter_declaration ::=
parameter data_type_or_implicit list_of_param_assignments
| parameter type list_of_type_assignments
A workaround is to use a generate block and compare the value of the parameter.
module wrapper #(
parameter COLUMN_WIDTH = 32,
parameter string WRAPPED_MODULE = "add"
)
(
// ...
);
// ...
generate
if (WRAPPED_MODULE=="add") begin
add #(.COLUMN_WDITH(COLUMN_WIDTH) ) a( .* );
end
else begin
// ...
end
endgenerate
// ...
endmodule
If you're using Vivado and SystemVerilog (only tested on 2017.4, likely would work on later versions too), I've been able to use something like parameter type WRAPPED_MODULE = add and it will synthesize as well.

Partial SQL insert in haskelldb

I just started a new project and wanted to use HaskellDB in the beginning. I created a database with 2 columns:
create table sensor (
service text,
name text
);
..found out how to do the basic HaskellDB machinery (ohhh..the documentation) and wanted to do an insert. However, I wanted to do a partial insert (there are supposed to be more columns), something like:
insert into sensor (service) values ('myservice');
Translated into HaskellDB:
transaction db $ insert db SE.sensor (SE.service <<- (Just $ senService sensor))
But...that simply doesn't work. What also does not work is if I specify the column names in different order, which is not exactly conenient as well. Is there a way to do a partial insert in haskelldb?
The error codes I get are - when I just inserted a different column (the 'name') as the first one:
Couldn't match expected type `SEI.Service'
against inferred type `SEI.Name'
Expected type: SEI.Intsensor
Inferred type: Database.HaskellDB.HDBRec.RecCons
SEI.Name (Expr String) er
When using functional dependencies to combine
Database.HaskellDB.Query.InsertRec
(Database.HaskellDB.HDBRec.RecCons f (e a) r)
(Database.HaskellDB.HDBRec.RecCons f (Expr a) er),
etc..
And when I do the 'service' as the first - and only - field, I get:
Couldn't match expected type `Database.HaskellDB.HDBRec.RecCons
SEI.Name
(Expr String)
(Database.HaskellDB.HDBRec.RecCons
SEI.Time
(Expr Int)
(Database.HaskellDB.HDBRec.RecCons
SEI.Intval (Expr Int) Database.HaskellDB.HDBRec.RecNil))'
against inferred type `Database.HaskellDB.HDBRec.RecNil'
(I have a couple of other columns in the table)
This looks really like 'by design', unfortunately :(
You're right, that does look intentional. The HaskellDB.Query docs show that insert has a type of:
insert :: (ToPrimExprs r, ShowRecRow r, InsertRec r er) => Database -> Table er -> Record r -> IO ()
In particular, the relation InsertRec r er must hold. That's defined elsewhere by the recursive type program:
InsertRec RecNil RecNil
(InsertExpr e, InsertRec r er) => InsertRec (RecCons f (e a) r) (RecCons f (Expr a) er)
The first line is the base case. The second line is an inductive case. It really does want to walk every element of er, the table. There's no short-circuit, and no support for re-ordering. But in my own tests, I have seen this work, using _default:
insQ db = insert db test_tbl1 (c1 <<- (Just 5) # c2 << _default)
So if you want a partial insert, you can always say:
insC1 db x = insert db test_tbl1 (c1 <<- (Just x) # c2 << _default)
insC2 db x = insert db test_tbl2 (c1 << _default # c2 <<- (Just x))
I realize this isn't everything you're looking for. It looks like InsertRec can be re-written in the style of HList, to permit more generalization. That would be an excellent contribution.