OCaml: error in list function - syntax-error

Hello I am working on list of function in Ocaml I am getting this error why is that?
Error: Syntax error
# let headOf lst=
match lst with
|??[ ] -> failwith "harun"
Warning 3: deprecated: ISO-Latin1 characters in identifiers

If your input encoding is ISO-LATIN-1, then what you're doing is typing non-breaking spaces sometimes. These are non-ASCII characters that look like spaces, with a character code of 160. You should remove them all and replace with ordinary spaces (character code 32).
If you're using an input system that sometimes inputs non-breaking spaces without your specifically asking for them, you should use a different input system for working with OCaml :-)
Update
In fact, my input system inputs a non-breaking space if I type Option-Space (iTerm2 on macOS 10.12.4). It looks like this:
# let f x��= 14;;
Warning 3: deprecated: ISO-Latin1 characters in identifiers
Error: Illegal character (\160)
The solution in my case is never to type Option-Space. Just type space (no option key).

Related

Escaping custom character in objective-c

I am working on macOS, not iOS, XCode 11.
My app allows in a specific location to enter text. This text can be anything. Once done it exports a csv which will be passed to an external process i cannot influence.
The issue: the external process uses semicolon ";" as a separator (csv is separated differently). If the user writes semicolon the external process will fail.
If I manually add an escaping backslash before each semicolon to the csv and then pass it to the external app it works.
What I need: having each semicolon escaped with ONE backslash in the final csv
What I tried
Escaping the whole text with quotation marks - fail
Escaping semicolons in objective-c before writing csv by trying
stringByReplacingOccurrencesOfString (look for #";" replace with #"\;" - compiler throws a warning that escape character is unknown - fail
Appreciate any help
UPDATE:
I also tried to set a double backslash like #Corbell mentioned but this leads in a double backslash in the exported CSV -> fail
I also tried to set a single backslash by using its unicode character:
[NSString stringWithFormat:#"%C;",0x5C]; --> "\\;"
Also failed and produces two backslashes in the final CSV (where i need ONE only).
In your stringByReplacingOccurencesOfString call, second parameter, try escaping your backslash with a backslash to make it a literal character to insert, i.e. #"\\;" - otherwise the compiler thinks you're trying to specify #"\;" as an escape sequence (backslash-semicolon) which is invalid.
Solved. It was the CSV Parser that added additional escaping characters. Once solved that it worked like a charm.

How to split on unicode whitespace in kotlin

In Kotlin if we use:
string.split(Regex("\\s+"))
Then we can split a string into words separated by whitespace. However the string:
val string = "a\u2000b"
doesn't split since the regex doesn't match unicode whitespace characters.
I there a way to split the string on all whitespace characters?
Since Java 7 Pattern allows to specify the UNICODE_CHARACTER_CLASS-flag which would basically also work for your current issue:
Pattern.compile("\\s+", Pattern.UNICODE_CHARACTER_CLASS)
Unfortunately this isn't directly supported via RegexOption with Kotlins Regex yet. There is a known issue that also describes a workaround (KT-21094):
string.split("""(?U)\s+""".toRegex())
You (most probably) require Java 7+ for that to actually work. Alternatives could be to use other predefined character classes instead. However, you need to lookup the appropriate Pattern-javadoc for your Java version to ensure that it is actually working (or do it in a trial-error-manner ;-)).
I've used the following regex to match Unicode whitespace:
Regex("[\\p{javaWhitespace}\u00A0\u2007\u202F]+")
This works because while \s matches only Latin-1 whitespace, \p{javaWhitespace} matches everything for which Character.isWhitespace() is true.  For some reason, this doesn't include a few particular characters, which I've listed separately.
More info in the docs for Pattern.
Related fact: although java.lang.String.trim() doesn't remove non-breaking spaces or figure spaces, kotlin.String.trim() does!

sql code not working in oraclesqldeveloper: Invalid Character error

I wrote a code to find few items by a particular number but it keeps saying that is something is an "invalid character"."ORA-00911: invalid character
00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action: Error at Line: 14 Column: 23"
My brain is blown,I am not sure where the problem exists.
Need Help. Thanks.
select
a.app_num,
a.crs_pol_num,
kl.score,
kl.risk_level_desc
from
application a,
kyc_new_risk_level kl
where
a.app_num = kl.app_num
and a.app_num = (select max(to_number(a1.app_num)) from
application a1,
kyc_new_risk_level kl1 where kl1.app_num = a1.app_num and a1.crs_pol_num = a.crs_pol_num)
and a.crs_pol_num in (‘CG0147511’,
‘CG0133662’,
‘CG0138107’,
‘493186’,
‘CG0142230’,
‘CS0138382’,
‘CG0147509’,
‘CG0147545’,
‘921141048001’,
‘CG0347239’,
‘CG0142212’,
‘CG0147518’,
‘CG0134057’,
‘CG0143158’,
‘CG0147536’,
‘CG0244124’,
‘CG0134102’,
‘CG0241709’,
‘CG0147197’,
‘CG0137204’,
‘CG0347496’,
‘CG0147490’,
‘CG0143467’,
‘CG0135689’,
‘CG0146904’,
‘CS0132517’,
‘CG0145455’,
‘CG0147554’,
‘CG0133626’,
‘CG0147560’,
‘CG0135359’,
‘CG0133303’,
‘921165287001’,
‘CG0147546’,
‘CG0114581,
‘CG0122266’,
‘CG0236577’,
‘CG0345349’,
‘CG0132670’,
‘CG0147413’,
‘CG0241646’,
‘CG0143783’,
‘CG0245160’,
‘CG0124066’,
‘CG0124830’,
‘CG0145956’,
‘CG0232953’,
‘CG0144479’,
‘CG0147569’,
‘CG0147555’,
‘CG0244857’,
‘CG0147562’,
‘CG0347578’,
‘CG0346461’,
‘CS0133352’,
‘512097’,
‘CS0127026’,
‘CG0147583’,
‘CG0233314’,
‘CG0247096’,
‘CG0131282’,
‘CG0123462’,
‘CS0124502’,
‘CG0146034’,
‘CG0140236’,
‘CS0126420’,
‘CG0147557’,
‘CG0123182’,
‘CG0233300’,
‘CG0132782’,
‘CG0147501’,
‘CS0141693’,
‘CG0145237’,
‘CG0141763’,
‘CG0147591’,
‘CG0144107’,
‘CG0125208’,
‘CG0132306’);
SQL Developer is showing you the problem before you even run your query
That's not a quote, it's a smart quote. Which is nice for browsers and word processors - but not so much for the database engine.
If you click on that hint, it will replace it with a real single quote.
But with so many to fix, would be much faster, better to use search and replace.
But your cursor on the bad character, and hit Ctrl+R
And then hit 'replace all', then repeat for the closing smart quote.
But in case you missed all that, the error also back from the DB tells you where the issue is

antlr4: need to convert sequences of symbols to characters in lexer

I am writing a parser for Wolfram Language. The language has a concept of "named characters", which are specified by a name delimited by \[, and ]. For example: \[Pi].
Suppose I want to specify a regular expression for an identifier. Identifiers can include named characters. I see two ways to do it: one is to have a preprocessor that would convert all named characters to their unicode representation, and two is to enumerate all possible named characters in their source form as part of the regular expression.
The second approach does not seem feasible because there are a lot of named characters. I would prefer to have ranges of unicode characters in my regex.
So I want to preprocess my token stream. In other words, it seems to me that the lexer needs to check if the named characters syntax is correct and then look up the name and convert it to unicode.
But if the syntax is incorrect or the name does not exist I need to tell the user about it. How do I propagate this error to the user and yet let antlr4 recover from the error and resume? Maybe I can sort of "pipe" lexers/parsers? (I am new to antlr).
EDIT:
In Wolfram Language I can have this string as an identifier: \[Pi]Squared. The part between brackets is called "named character". There is a limited set of named characters, each of which corresponds to a unicode code point. I am trying to figure out how to tokenize identifiers like this.
I could have a rule for my token like this (simplified to just a combination of named characters and ASCII characters):
NAME : ('\\[' [a-z]+ ']'|[a-zA-Z])+ ;
but I would like to check if the named character actually exists (and other attributes such as if it is a letter, but the latter part is outside of the scope of the question), so this regex won't work.
I considered making a list of allowed named characters and just making a long regex that enumerates all of them, but this seems ugly.
What would be a good approach to this?
END OF EDIT
A common approach is to write the lexer/parser to allow syntactically correct input and defer semantic issues to the analysis of the generated parse tree. In this case, the lexer can naively accept named characters:
NChar : NCBeg .? RBrack ;
fragment NCBeg : '\\[' ;
fragment LBrack: '[' ;
fragment RBrack: ']' ;
Update
In the parser, allow the NChar's to exist in the parse-tree as discrete terminal nodes:
idents : ident+ ;
ident : NChar // named character string
| ID // simple character string?
| Literal // something quoted?
| ....
;
This makes analysis of the parse tree considerably easier: each ident context will contain only one non-null value for a discretely identifiable alt; and isolates analysis of all ordering issues to the idents context.
Update2
For an input \[Pi]Squared, the parse tree form that would be easiest to analyze would be an idents node with two well-ordered children, \[Pi] and Squared.
Best practice would not be to pack both children into the same token - would just have to later manually break the token text into the two parts to check if it is contains a valid named character and whether the particular sequence of parts is allowable.
No regex is going to allow conclusive verification of the named characters. That will require a list. Tightening the lexer definition of an NChar can, however, achieve a result equivalent to a regex:
NChar : NCBeg [A-Z][A-Za-z]+ RBrack ;
If the concern is that there might be a space after the named character, consider that this circumstance is likely better treated with a semantic warning as opposed to a syntactic error. Rather than skipping whitespace in the lexer, put the whitespace on the hidden channel. Then, in the verification analysis of each idents context, check the hidden channel for intervening whitespace and issue a warning as appropriate.
----
A parse-tree visitor can then examine, validate, and warn as appropriate regarding unknown or misspelled named characters.
To do the validation in the parser, if more desirable, use a predicated rule to distinguish known from unknown named characters:
#members {
ArrayList<String> keyList = .... // list of named chars
public boolean inList(String id) {
return keyList.contains(id) ;
}
}
nChar : known
| unknown
;
known : NChar { inList($NChar.getText()) }? ;
unknown : NChar { error("Unknown " + $NChar.getText()); } ;
The inList function could implement a distance metric to detect misspellings, but correcting the text directly in the parse-tree is a bit complex. Easier to do when implemented as a parse-tree decoration during a visitor operation.
Finally, a scrape and munge of the named characters into a usable map (both unicode and ascii) is likely worthwhile to handle both representations as well as conversions and misspelling.

How can I write special character in VB code

I have a Sql statament using special character (ex: ('), (/), (&)) and I don't know how to write them in my VB.NET code. Please help me. Thanks.
Find out the Unicode code point for the character (from http://www.unicode.org) and then use ChrW to convert from the code point to the character. (To put this in another string, use concatenation. I'm somewhat surprised that VB doesn't have an escape sequence, but there we go.)
For example, for the Euro sign (U+20AC) you'd write:
Dim euro as Char = ChrW(&H20AC)
The advantage of this over putting the character directly into source code is that your source code stays "just pure ASCII" - which means you won't have any strange issues with any other program trying to read it, diff it, etc. The disadvantage is that it's harder to see the symbol in the code, of course.
The most common way seems to be to append a character of the form Chr(34)... 34 represents a double quote character. The character codes can be found from the windows program "charmap"... just windows/Run... and type charmap
If you are passing strings to be processed as SQL statement try doubling the characters for example.
"SELECT * FROM MyRecords WHERE MyRecords.MyKeyField = ""With a "" Quote"" "
The '' double works with the other special characters as well.
The ' character can be doubled up to allow it into a string e.g
lSQLSTatement = "Select * from temp where name = 'fred''s'"
Will search for all records where name = fred's
Three points:
1) The example characters you've given are not special characters. They're directly available on your keyboard. Just press the corresponding key.
2) To type characters that don't have a corresponding key on the keyboard, use this:
Alt + (the ASCII code number of the special character)
For example, to type ¿, press Alt and key in 168, which is the ASCII code for that special character.
You can use this method to type a special character in practically any program not just a VB.Net text editor.
3) What you probably looking for is what is called 'escaping' characters in a string. In your SQL query string, just place a \ before each of those characters. That should do.
Chr() is probably the most popular.
ChrW() can be used if you want to generate unicode characters
The ControlChars class contains some special and 'invisible' characters, plus the quote - for example, ControlChars.Quote