Syntax error, unexpected tSTRING_BEG ROR - ruby-on-rails

Below is my code:
gem_package 'cucumber' do
clear_sources true
source https://chefrubyaehq.kdc.example.com/
gem_binary '/opt/chef/embedded/bin/gem'
action :install
end
And I am getting the following error:
FATAL: zng937-test/recipes/default.rb:43: unknown regexp options - chfrbyahq
FATAL: zng937-test/recipes/default.rb:44: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
FATAL: gem_binary '/opt/chef/embedded/bin/gem'
Does anyone have any idea why I would be getting this?

You need to put the source (https://chefrubyaehq.kdc.capitalone.com/) inside quotes to make it a string. Either single or double quotes is fine for this case.

Just as the message says.
Your regex //chefrubyaehq is invalid. Ruby regex only has i, o, x, m options.
You forgot to put a period after your regex /\n gem_binary '/ before the method opt.
And when you fix those, you will still encounter more errors.

Related

Rails: mongodb error when using $lt

this code return an error
db[:zips].find(city: {$lt: 'd'}).limit(2).to_a.each{|r| pp r}
syntax error, unexpected '}', expecting end-of-input
However, this code works well
db[:zips].find(city: {:$lt=> 'd'}).limit(2).to_a.each{|r| pp r}
Why can not use :$lt like the first one?
You can't use the JSON-like {key: value} syntax in this case , because the key starts with $. Either use the older hash syntax or, since ruby 2.2,
{'$lt': 'd'}
I couldn't find a reference for when quoting is required (emojis are OK for example) - I suspect you would have to delve into the ruby source for this.

Determining ANTLR version to use, or converting between?

I want to take the .g files from Apache Hive and build a parser (targeting JavaScript) -- initially, as just a way to validate user-input Hive queries. The files I'm using come from apache-hive-1.0.0-src\ql\src\java\org\apache\hadoop\hive\ql\parse from the Hive tgz: HiveLexer.g, HiveParser.g, FromClauseParser.g, IdentifiersParser.g, SelectClauseParser.g.
I see no indication within the grammar files which version of ANTLR to use, so I've tried running antlr (from apt-get pccts), antlr3 and antlr4. they all throw errors of some sort, so I have no clue which one to run or if I can (or need to) convert the .g files between versions.
The errors I'm getting are as follows:
antlr -Dlanguage=JavaScript HiveParser.g (looks like it doesn't support JS anyway):
warning: invalid option: '-Dlanguage=JavaScript'
HiveParser.g, line 17: syntax error at "grammar" missing { QuotedTerm PassAction ! \< \> : }
HiveParser.g, line 17: syntax error at "HiveParser" missing { QuotedTerm PassAction ! \< \> : }
HiveParser.g, line 17: syntax error at ";" missing Eof
HiveParser.g, line 28: lexical error: invalid token (text was ',')
antlr3 -Dlanguage=JavaScript HiveParser.g:
error(10): internal error: Exception FromClauseParser.g:302:85: unexpected char: '-'#org.antlr.grammar.v2.ANTLRLexer.nextToken(ANTLRLexer.java:347): unexpected stream error from parsing FromClauseParser.g
error(150): grammar file FromClauseParser.g has no rules
error(100): FromClauseParser.g:0:0: syntax error: assign.types: <AST>:299:68: unexpected AST node: ->
error(100): FromClauseParser.g:0:0: syntax error: define: <AST>:299:68: unexpected AST node: ->
error(106): SelectClauseParser.g:151:18: reference to undefined rule: tableAllColumns
antlr4 -Dlanguage=JavaScript HiveParser.g:
warning(202): HiveParser.g:30:0: tokens {A; B;} syntax is now tokens {A, B} in ANTLR 4
error(50): HiveParser.g:636:34: syntax error: '->' came as a complete surprise to me while looking for rule element
error(50): HiveParser.g:636:37: syntax error: '^' came as a complete surprise to me
error(50): HiveParser.g:638:50: syntax error: '->' came as a complete surprise to me while looking for rule element
error(50): HiveParser.g:638:53: syntax error: '^' came as a complete surprise to me
The antlr3 error referencing #org.antlr.grammar.v2.ANTLRLexer.nextToken seems suspect. Is it using the v2 lexer instead of v3? If so, maybe v3 is what I should target, but it's somehow not hitting it?
Or is this not an issue with versioning and instead with invocation? Or is Hive built in a way that provides additional files needed?
According to Hive source code, they use ANTLR 3.4. But before you start remove the last string from FromClauseParser.g
//------------------------------------------------------------------------

Rails generate model syntax error

I'm trying to generate a model from the command line. Here is my command:
rails generate model User first_name:string last_name:string email_address:string age:integer
And it keeps giving me this error:
SyntaxError: (irb):2: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
User first_name:str last_name:**str** email_address:str age:int
(irb):2: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
name:str email_address:str age:**integer**
I'm lost. I learned this yesterday and the syntax is exactly the same as before when it worked fine.
Thanks
Edit: StackOverflow wouldnt let me post this unless I formatted that error as code FYI
You should put this command in your system console, not Rails console.

how to use getText function in cucumber with ruby-on-rails

I am trying to use getText function ,but its giving error.
assert_equal "Comment List", find(:xpath,'//div[#id='pageContainer']/div[2]/h2').getText()
and error is -
C:/Workspace/cucumber-project/features/step_definitions/comment_steps.rb:135: sy ntax error, unexpected ')', expecting kEND ...d='pageContainer']/div[2]/h2').text ^ (SyntaxError)
Can anybody help me in that, i just want to compare the text by finding through xpath with the expected text
This isn't a Cucumber issue, it's a Ruby syntax error. Your quotes are the problem, you need to do either:
"//div[#id='pageContainer']/div[2]/h2"
or
'//div[#id="pageContainer"]/div[2]/h2'

Ruby on Rails Error in rake db:migrate syntax error, unexpected $end, expecting '}'

I get this error when I run rake db:migrate
*db/migrate//004_add_data_to_measurement_type_and_measurement_unit.rb:3: invalid multibyte char (US-ASCII)
db/migrate//004_add_data_to_measurement_type_and_measurement_unit.rb:3: invalid multibyte char (US-ASCII)
db/migrate//004_add_data_to_measurement_type_and_measurement_unit.rb:3: syntax error, unexpected $end, expecting '}'
...celeration' => [{:name =>'m/s²', :si => true, :conversion_f...*
Then I checked it using *$ ruby -wc db/migrate/004_add_data_to_measurement_type_and_measurement_unit.rb* and got the same error.
I was sure that I have all the right gems in place, so I tested by removing the superscript in the line, making it :name =>'m/s' from :name =>'m/s²'. This removed the error.
But problem is that I need the superscript and do not know how previous developer managed to run the db:migrate on this. Have you seen something similar?
Thanks
The problem is that the superscript is not ASCII.
The previous developer may have set something so that UTF-8 was always assumed, but you should be able to do it for this script specifically by adding the magic comment
# coding: utf-8
near the top of the script.

Resources