I'm making custom "if" formatting. For example:
if (
some_expression
&& some_expression
&& some_expression
&& some_expression
)
But when I use format my custom formatting become broken
if ( some_expression && some_expression && some_expression && some_expression )
Have find this answer
PHP-Netbeans: How to change formatting for multi-conditional if statements
It is not complete but more useful
You could define in
Menu Tools -> Options -> Editor -> tab Formating
Choose Language "Java"
There you have several categories.
I think that in Category "Wrapping" you could find something that will help.
At the end of the list you have "Binary Operators, Ternary operators.
Try to play around and choose what suites you best.
Related
I'm trying to use this expression #sys-time >'19:00:00' || #sys-time <'8:00:00' as if on watson assistant but it is recgnising any time as input. Any idea how to solve it?
There is expression language that allows you to work with dates.
https://console.bluemix.net/docs/services/conversation/dialog-methods.html#date-time
Your example would be:
#sys-time.after('19:00:00') || #sys-time.before('8:00:00')
Is there any difference between the two following expressions in jq?
Expression 1match("prefix.*if you do";"gmi")
Expression 2match(["prefix.*if you do","gmi"])
Findings
They both return the expected data:
{
"caveats": "The command has been installed with the prefix \"g\".\nIf you do not want the prefix, install using the \"with-default-names\"\noption.\n"
}
Removing the case insensitive (i) flag or the multi-line flag (m) on both expressions will cause the match to fail.
Using either syntax [regex,flags] or regex;flags works as according to the manual:
The jq regex filters are defined so that they can be used using one of
these patterns:
STRING | FILTER( REGEX ) STRING | FILTER( REGEX; FLAGS )STRING | FILTER( [REGEX] )STRING | FILTER( [REGEX, FLAGS] )
Mixing the ; and , between the square bracketed versions causes unexpected results.
Technically everything is behaving as expected.
But are these results circumstantial because of the simplicity of my example ?
Specifically:
Is this just convenience syntax ?
Is there some convention I am missing where the implementation choice is more important than flipping a coin ?
Is there any functional difference at all between the two versions ?
There was a time when multi-arity functions were not supported in jq. I believe that the duality that you describe is a legacy of those days. Any discrepancy would be a bug worthy of being reported.
(Perhaps some people got into the habit of typing [x,y] rather than x;y and preferred the former?)
I just started using velocity for a new job and I really don't like what I have found already. At this point, i would actually prefer freemarker =X.
Anyways, i'm trying to do a regular expression and i saw this little bit (search "regular expression"), but that isn't quite the implementation I am doing.
I do not have any access to the java so that option of writing something custom to do this stuff is not there (i'm not even sure if that is possible).
This is what i have right now:
#set ( $envCheck = "(localhost|staging|qa|cms)\\.site" )
#set ( $envCheck = $envCheck.matches($gatewayURL) )
but $envCheck always just comes out as "false". $gatewayURL is defined on the page as well, so that is not the issue.
is this even possible? i was reading that any regexp method that the java String class has is available in the velocity template.
Assuming your $gatewayURL is somethign like this:
#set ( $gatewayURL = "localhost.site" )
Then:
#set ( $envCheck = "(localhost|staging|qa|cms)\.site" )
#set ( $envCheck = $gatewayURL.matches($envCheck) )
No need to mask backslash, and you should be calling matches() on gatewayURL, not regular expression.
Velocity doesn't have its own regexp implementation, it just passes parameters you provide to corresponding native java methods, that's all. So you have pretty much full Java SDK at your disposal.
This answer is way late but probably still good as a reference for Velocity users encountering the same issue.
We use Velocity 1.5 (too big a task to upgrade to 1.7/1.6 as they broke too many templates) and encountered the same issue. The answer above would not work - backlash without escape (\) results in Lexical error and with escape (\\) return false always as I think it is being interpreted literally. The right way to solve it is by using single quote instead of double quotes when defining the regex expression so Velocity would not attempt to interpret the string that is meant for Java.
#set ( $envCheck = '(localhost|staging|qa|cms)\.site' )
#set ( $envCheck = $envCheck.matches($gatewayURL) )
How can I beautify C++ code to add brackets to conditional statements? What I need to do is change:
if ( myCondition )
setDateTime( date, time );
to
if ( myCondition )
{
setDateTime( date, time );
}
but I've got to do this hundreds of times. I've used AStyle but I couldn't find how to do this with it.
Apart from meeting the clients coding standards, the reason I want to do this is that I have to replace certain calls such as the above call to setDateTime( date, time ) with setDate( date ) and setTime( time ) which I can easily enough do with regular expressions but ends up like this:
if ( myCondition )
setDate( date );
setTime( time );
Obviously not right!!!
static inline void setDateTime(date, time) { setDate(date); setTime(time); }
Regarding the if: does the astyle option --add-brackets not work for you, combined with brackets=break? When I've used astyle, I've found it difficult to get it to do exactly what I want. So if you're going to use it at all, it's easiest to define the coding style guidelines in terms of a set of astyle parameters and then use astyle to enforce them.
I'm not so bothered by inconsistent style that I personally think that's worth it, but then the customer is always grudgingly tolerated right.
s/setDateTime(date, time)/{ setDate(date); setTime(time); }/
This is my use case: Input is a string representing an Oracle PL/SQL statement of arbitray complexity. We may assume it's a single statement (not a script).
Now, several bits of this input string have to be rewritten.
E.g. table names need to be prefixed, aggregate functions in the selection list that don't use a column alias should be assigned a default one:
SELECT SUM(ABS(x.value)),
TO_CHAR(y.ID,'111,111'),
y.some_col
FROM
tableX x,
(SELECT DISTINCT ID
FROM tableZ z
WHERE ID > 10) y
WHERE
...
becomes
SELECT SUM(ABS(x.value)) COL1,
TO_CHAR(y.ID,'111,111') COL2,
y.some_col
FROM
pref.tableX x,
(SELECT DISTINCT ID, some_col
FROM pref.tableZ z
WHERE ID > 10) y
WHERE
...
(Disclaimer: just to illustrate the issue, statement does not make sense)
Since aggregate functions might be nested and subSELECTs are a b_tch, I dare not use regular expressions. Well, actually I did and achieved 80% of success, but I do need the remaining 20%.
The right approach, I presume, is to use grammars and parsers.
I fiddled around with c++ ANTLR2 (although I do not know much about grammars and parsing with the help of such). I do not see an easy way to get the SQL bits:
list<string> *ssel = theAST.getSubSelectList(); // fantasy land
Could anybody maybe provide some pointers on how "parsing professionals" would pursue this issue?
EDIT: I am using Oracle 9i.
Maybe you can use this, it changes an select statement into an xml block:
declare
cl clob;
begin
dbms_lob.createtemporary (
cl,
true
);
sys.utl_xml.parsequery (
user,
'select e.deptno from emp e where deptno = 10',
cl
);
dbms_output.put_line (cl);
dbms_lob.freetemporary (cl);
end;
/
<QUERY>
<SELECT>
<SELECT_LIST>
<SELECT_LIST_ITEM>
<COLUMN_REF>
<SCHEMA>MICHAEL</SCHEMA>
<TABLE>EMP</TABLE>
<TABLE_ALIAS>E</TABLE_ALIAS>
<COLUMN_ALIAS>DEPTNO</COLUMN_ALIAS>
<COLUMN>DEPTNO</COLUMN>
</COLUMN_REF>
....
....
....
</QUERY>
See here: http://forums.oracle.com/forums/thread.jspa?messageID=3693276�
Now you 'only' need to parse this xml block.
Edit1:
Sadly I don't fully understand the needs of the OP but I hope this can help (It is another way of asking the 'names' of the columns of for example query select count(*),max(dummy) from dual):
set serveroutput on
DECLARE
c NUMBER;
d NUMBER;
col_cnt PLS_INTEGER;
f BOOLEAN;
rec_tab dbms_sql.desc_tab;
col_num NUMBER;
PROCEDURE print_rec(rec in dbms_sql.desc_rec) IS
BEGIN
dbms_output.new_line;
dbms_output.put_line('col_type = ' || rec.col_type);
dbms_output.put_line('col_maxlen = ' || rec.col_max_len);
dbms_output.put_line('col_name = ' || rec.col_name);
dbms_output.put_line('col_name_len = ' || rec.col_name_len);
dbms_output.put_line('col_schema_name= ' || rec.col_schema_name);
dbms_output.put_line('col_schema_name_len= ' || rec.col_schema_name_len);
dbms_output.put_line('col_precision = ' || rec.col_precision);
dbms_output.put_line('col_scale = ' || rec.col_scale);
dbms_output.put('col_null_ok = ');
IF (rec.col_null_ok) THEN
dbms_output.put_line('True');
ELSE
dbms_output.put_line('False');
END IF;
END;
BEGIN
c := dbms_sql.open_cursor;
dbms_sql.parse(c,'select count(*),max(dummy) from dual ',dbms_sql.NATIVE);
dbms_sql.describe_columns(c, col_cnt, rec_tab);
for i in rec_tab.first..rec_tab.last loop
print_rec(rec_tab(i));
end loop;
dbms_sql.close_cursor(c);
END;
/
(See here for more info: http://www.psoug.org/reference/dbms_sql.html)
The OP also want to be able to change the schema name of the table in a query. I think the easiest say to achieve that is to query the table names from user_tables and search in sql statement for those table names and prefix them or to do a 'alter session set current_schema = ....'.
If the source of the SQL statement strings are other coders, you could simply insist that the parts that need changing are simply marked by special escape conventions, e.g., write $TABLE instead of the table name, or $TABLEPREFIX where one is needed. Then finding the places that need patching can be accomplished with a substring search and replacement.
If you really have arbitrary SQL strings and cannot get them nicely marked, you need to somehow parse the SQL string as you have observed. The XML solution certainly is one possible way.
Another way is to use a program transformation system. Such a tool can parse a string for a language instance, build ASTs, carry out analysis and transformation on ASTs, and then spit a revised string.
The DMS Software Reengineering Toolkit is such a system. It has PLSQL front end parser. And it can use pattern-directed transformations to accomplish the rewrites you appear to need. For your example involving select items:
domain PLSQL.
rule use_explicit_column(e: expression):select_item -> select_item
"\e" -> "\e \column\(\e\)".
To read the rule, you need to understand that the stuff inside quote marks represents abstract trees in some computer langauge which we want to manipulate. What the "domain PLSQL" phrase says is, "use the PLSQL parser" to process the quoted string content, which is how it knows. (DMS has lots of langauge parsers to choose from). The terms
"expression" and "select_item" are grammatical constructs from the language of interest, e.g., PLSQL in this case. See the railroad diagrams in your PLSQL reference manual.
The backslash represents escape/meta information rather than target langauge syntax.
What the rule says is, transform those parsed elements which are select_items
that are composed solely of an expression \e, by converting it into a select_item consisting of the same expression \e and the corresponding column ( \column(\e) ) presumably based on position in the select item list for the specific table. You'd have to implement a column function that can determine the corresponding name from the position of the select item. In this example, I've chosen to define the column function to accept the expression of interest as argument; the expression is actually passed as the matched tree, and thus the column function can determine where it is in the select_items list by walking up the abstract syntax tree.
This rule handles just the select items. You'd add more rules to handle the other various cases of interest to you.
What the transformation system does for you is:
parse the language fragment of interest
build an AST
let you pattern match for places of interest (by doing AST pattern matching)
but using the surface syntax of the target langauge
replace matched patterns by other patterns
compute aritrary replacements (as ASTs)
regenerate source text from the modified ASTs.
While writing the rules isn't always trivial, it is what is necessary if your problem
is stated as posed.
The XML suggested solution is another way to build such ASTs. It doesn't have the nice pattern matching properties although you may be able to get a lot out of XSLT. What I don't know is if the XML has the parse tree in complete detail; the DMS parser does provide this by design as it is needed if you want to do arbitrary analysis and transformation.