It fails here,
message = "{\"response\":{\"billDetails\":\"[{\"name\":\"Account ID\"}]\"}}"
JSON.parse(message)
JSON::ParserError (809: unexpected token at '{"response":{"billDetails":"[{"name":"Account ID"}]"}}')
I'm not sure this will be helpful. But your json string should be written from
"{
"response":{
"billDetails": "[{"name":"Account ID"}]"}
}"
To:
'{
"response":{
"billDetails": [{"name":"Account ID"}]
}
}'
In the array from billDetails, you have two aditional ", that provokes an error when parsing that string.
Was trying to install a wp plugin- dt world clock and got this error msg.
The actual error msg:
Parse error: syntax error, unexpected '[' in /var/www/html/wp-content/plugins/dt-world-clock/dt-world-clock.php on line 415
And the line 415 is:
function DT_World_Clock_Shortcode($atts = [], $content = null, $tag = '') {
I have no idea where to edit-
Would really appreciate help...
try this
function DT_World_Clock_Shortcode($atts = array(), $content = null, $tag = "") {
I have tried to execute the below grammar. But, it is throwing an error.
Phase: SvP_updates_featuretype
Input: Macro_Requirement updates_KW
Options: control = appelt debug = true
Rule: updates_featuretype
Priority:20
(
(Macro_Requirement contains updates_KW)
)
:updates_featuretypeFired
-->
:updates_featuretypeFired.Macro_Requirement_updates = {category = "Macro_Requirement_updates", rule = "updates_featuretype"}
Error:
gate.creole.ResourceInstantiationException: Error while parsing the grammar (file:/C:/Users/Singo/Dropbox/Gayatri%20Kumari%20Damarasingu/Identification%20Stage%20Resources/GATE-Resources/Processing_resources/main_POSTINGAPPROACH.jape):
at gate.creole.Transducer.init(Transducer.java:127)
at gate.creole.AbstractProcessingResource.reInit(AbstractProcessingResource.java:65)
at gate.gui.NameBearerHandle$ReloadAction$1.run(NameBearerHandle.java:1456)
at java.lang.Thread.run(Thread.java:745)
Caused by: gate.jape.JapeException: Batch: error parsing transducer: Cannot parse a phase in file:/C:/Users/Singo/Dropbox/Gayatri%20Kumari%20Damarasingu/Identification%20Stage%20Resources/GATE-Resources/Processing_resources/SvP/SvP_database_featuretype.jape: file:/C:/Users/Singo/Dropbox/Gayatri%20Kumari%20Damarasingu/Identification%20Stage%20Resources/GATE-Resources/Processing_resources/SvP/SvP_database_featuretype.jape:22:2: unknown macro name Macro_Requirement
at gate.jape.Batch.parseJape(Batch.java:175)
at gate.jape.Batch.<init>(Batch.java:101)
at gate.creole.Transducer.init(Transducer.java:109)
... 3 more
Could not able to figure out how come the macro name Macro_requirement is not correct here. Can someone please help me in this
You forgot curly braces around Macro Requirement contains updates KW:
Phase: SvP_updates_featuretype
Input: Macro_Requirement updates_KW
Options: control = appelt debug = true
Rule: updates_featuretype
Priority:20
(
({Macro_Requirement contains updates_KW})
)
:updates_featuretypeFired
-->
:updates_featuretypeFired.Macro_Requirement_updates = {category = "Macro_Requirement_updates", rule = "updates_featuretype"}
I want to change every entry in csv file to 'BlahBlah'
For that I have antlr grammar as
grammar CSV;
file : hdr row* row1;
hdr : row;
row : field (',' value1=field)* '\r'? '\n'; // '\r' is optional at the end of a row of CSV file ..
row1 : field (',' field)* '\r'? '\n'?;
field
: TEXT
{
$setText("BlahBlah");
}
| STRING
|
;
TEXT : ~[,\n\r"]+ ;
STRING : '"' ('""' | ~'"')* '"' ;
But when I run this on antlr4
error(63): CSV.g4:13:3: unknown attribute reference setText in $setText
make: *** [run] Error 1
why is setText not supported in antlr4 and is there any other alternative to replace text?
Couple of problems here:
First, have to identify the receiver of the setText method. Probably want
field : TEXT { $TEXT.setText("BlahBlah"); }
| STRING
;
Second is that setText is not defined in the Token class.
Typically, create your own token class extending CommonToken and corresponding token factory class. Set the TokenLableType (in the options block) to your token class name. The setText method in CommonToken will then be visible.
tl;dr:
Given the following grammar (derived from original CSV.g4 sample and grammar attempt of OP (cf. question)):
grammar CSVBlindText;
#header {
import java.util.*;
}
/** Derived from rule "file : hdr row+ ;" */
file
locals [int i=0]
: hdr ( rows+=row[$hdr.text.split(",")] {$i++;} )+
{
System.out.println($i+" rows");
for (RowContext r : $rows) {
System.out.println("row token interval: "+r.getSourceInterval());
}
}
;
hdr : row[null] {System.out.println("header: '"+$text.trim()+"'");} ;
/** Derived from rule "row : field (',' field)* '\r'? '\n' ;" */
row[String[] columns] returns [Map<String,String> values]
locals [int col=0]
#init {
$values = new HashMap<String,String>();
}
#after {
if ($values!=null && $values.size()>0) {
System.out.println("values = "+$values);
}
}
// rule row cont'd...
: field
{
if ($columns!=null) {
$values.put($columns[$col++].trim(), $field.text.trim());
}
}
( ',' field
{
if ($columns!=null) {
$values.put($columns[$col++].trim(), $field.text.trim());
}
}
)* '\r'? '\n'
;
field
: TEXT
| STRING
|
;
TEXT : ~[',\n\r"]+ {setText( "BlahBlah" );} ;
STRING : '"' ('""'|~'"')* '"' ; // quote-quote is an escaped quote
One has:
$> antlr4 -no-listener CSVBlindText.g4
$> grep setText CSVBlindText*java
CSVBlindTextLexer.java: setText( "BlahBlah" );
Compiling it works flawlessly:
$> javac CSVBlindText*.java
Testdata (the users.csv file just renamed):
$> cat blinded_by_grammar.csv
User, Name, Dept
parrt, Terence, 101
tombu, Tom, 020
bke, Kevin, 008
Yields in test:
$> grun CSVBlindText file blinded_by_grammar.csv
header: 'BlahBlah,BlahBlah,BlahBlah'
values = {BlahBlah=BlahBlah}
values = {BlahBlah=BlahBlah}
values = {BlahBlah=BlahBlah}
3 rows
row token interval: 6..11
row token interval: 12..17
row token interval: 18..23
So it looks as if the setText() should be injected before the semicolon of a production and not between alternatives (wild guessing here ;-)
Previous iterations below:
Just guessing, as I 1) have no working antlr4 available currently and 2) did not write ANTLR4 grammars for quite some time now - maybe without the Dollar ($) ?
grammar CSV;
file : hdr row* row1;
hdr : row;
row : field (',' value1=field)* '\r'? '\n'; // '\r' is optional at the end of a row of CSV file ..
row1 : field (',' field)* '\r'? '\n'?;
field
: TEXT
{
setText("BlahBlah");
}
| STRING
|
;
TEXT : ~[,\n\r"]+ ;
STRING : '"' ('""' | ~'"')* '"' ;
Update: Now that an antlr 4.5.2 (at least via brew) instead of a 4.5.3 is available, I digged into that and answering some comment below from OP: the setText() will be generated in lexer java module if the grammar is well defined. Unfortunately debugging antlr4 grammars for a dilettant like me is ... but nevertheless very nice language construction kit IMO.
Sample session:
$> antlr4 -no-listener CSV.g4
$> grep setText CSVLexer.java
setText( String.valueOf(getText().charAt(1)) );
The grammar used:
(hacked up from example code retrieved via:
curl -O http://media.pragprog.com/titles/tpantlr2/code/tpantlr2-code.tgz )
grammar CSV;
#header {
import java.util.*;
}
/** Derived from rule "file : hdr row+ ;" */
file
locals [int i=0]
: hdr ( rows+=row[$hdr.text.split(",")] {$i++;} )+
{
System.out.println($i+" rows");
for (RowContext r : $rows) {
System.out.println("row token interval: "+r.getSourceInterval());
}
}
;
hdr : row[null] {System.out.println("header: '"+$text.trim()+"'");} ;
/** Derived from rule "row : field (',' field)* '\r'? '\n' ;" */
row[String[] columns] returns [Map<String,String> values]
locals [int col=0]
#init {
$values = new HashMap<String,String>();
}
#after {
if ($values!=null && $values.size()>0) {
System.out.println("values = "+$values);
}
}
// rule row cont'd...
: field
{
if ($columns!=null) {
$values.put($columns[$col++].trim(), $field.text.trim());
}
}
( ',' field
{
if ($columns!=null) {
$values.put($columns[$col++].trim(), $field.text.trim());
}
}
)* '\r'? '\n'
;
field
: TEXT
| STRING
| CHAR
|
;
TEXT : ~[',\n\r"]+ ;
STRING : '"' ('""'|~'"')* '"' ; // quote-quote is an escaped quote
/** Convert 3-char 'x' input sequence to string x */
CHAR: '\'' . '\'' {setText( String.valueOf(getText().charAt(1)) );} ;
Compiling works:
$> javac CSV*.java
Now test with a matching weird csv file:
a,b
"y",'4'
As:
$> grun CSV file foo.csv
line 1:0 no viable alternative at input 'a'
line 1:2 no viable alternative at input 'b'
header: 'a,b'
values = {a="y", b=4}
1 rows
row token interval: 4..7
So in conclusion, I suggest to rework the logic of the grammar (I presume inserting "BlahBlahBlah" was not essential but a mere debugging hack).
And citing http://www.antlr.org/support.html :
ANTLR Discussions
Please do not start discussions at stackoverflow. They have asked us to
steer discussions (i.e., non-questions/answers) away from Stackoverflow; we
have a discussion forum at Google specifically for that:
https://groups.google.com/forum/#!forum/antlr-discussion
We can discuss ANTLR project features, direction, and generally argue about
whatever we want at the google discussion forum.
I hope this helps.
I'd like to remove this part :
"company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}" but an error appears syntax error, unexpected '}', expecting ':'
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}"
You can't use double quotes(") inside double quotes. You need to escape those quotes:
"Hello, "are you there?" # doesn't make sense in Ruby
"Hello, \"are you there?" # escaped double quotes inside the string
#VtrKanna
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}"
this is work fine
but my problem is just to keep this part
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/#{current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}"}"
this is result an error
Try like this
val = current_user.has_role?(:administrator) ? "companies.html?#{admin_token_url}" : "company.html?#{token_url}&company=#{URI.encode(current_company.trylive_name)}"
#iframe_statistics_url = "#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/}#{val}"
Or
g = "https://www.google.co.in/"
q = %[helo #{"world #{g}"}]
=> "helo world https://www.google.co.in/"
Try it
#iframe_statistics_url = %[#{Gaston.amazon.cloudfront.host}/trylive_dashboard/iframe/companies.html?#{current_user.has_role?(:administrator) ? admin_token_url : "#{token_url}&company=#{URI.encode(current_company.trylive_name)}"}]