Why do I get syntax error before: '{'? - erlang

While playing with Erlang getting started section
I have met bizarre syntax error on trivial use case (simple map initialization). Are there any suggestion why does that happen?
1> #{ "key" => 42}.
1: syntax error before: '{'
Details: Erlang R16B03 (erts-5.10.4), Eshell V5.10.4.

Because maps were introduced in Erlang 17.
You have to upgrade your installation or do not use maps.

Related

Why does dialyzer fail on nocatch?

I ran Dialyzer and got the following error:
Checking whether the PLT /tmp/.BRANCH.service.deps.plt is up-to-date...
{"init terminating in do_boot",
{{case_clause,
{{nocatch,
{dialyzer_error,
[78,111,116,32,97,32,114,101,103,117,108,97,114,32,102,105,108,
101,58,32,
"/usr/lib/erlang/lib/compiler-6.0.3/ebin/beam_a.beam",10]}},
[{dialyzer_plt,compute_md5_from_file,1,
[{file,"dialyzer_plt.erl"},{line,543}]},
{dialyzer_plt,compute_new_md5_1,3,
[{file,"dialyzer_plt.erl"},{line,509}]},
{dialyzer_plt,check_plt1,3,[{file,"dialyzer_plt.erl"},{line,485}]},
{dialyzer_plt,'-subproc/1-fun-0-',1,
[{file,"dialyzer_plt.erl"},{line,603}]}]}},
[{dialyzer_cl,check_plt,3,[{file,"dialyzer_cl.erl"},{line,249}]},
{dialyzer_cl,plt_common,3,[{file,"dialyzer_cl.erl"},{line,182}]},
{dialyzer,'-cl_check_init/1-fun-0-',1,[{file,"dialyzer.erl"},{line,94}]},
{dialyzer,doit,1,[{file,"dialyzer.erl"},{line,236}]},
{dialyzer,plain_cl,0,[{file,"dialyzer.erl"},{line,75}]},
{init,start_em,1,[]},
{init,do_boot,3,[]}]}}
What went wrong and how do I fix it? What do the list of integers mean?
The print-out inside the dialyzer_error tuple is an iolist. We can pretty print it using the Erlang shell (started with erl):
1> [78,111,116,32,97,32,114,101,103,117,108,97,114,32,102,105,108,101,58,32].
"Not a regular file: "
2>
You realize it is complaining about bytecode (.beam) from a previous compiler version than the current one I am running. I removed them, and then it ran.

Some error occurred concerning record in erlang when compile

I'm new to erlang, and here's my code:
-module(main).
-author("jasonzhu").
%% API
-export([new/2]).
-record(person, {name, age}).
new(Name, Age) ->
#person(name=Name, age=Age).
When compiling in prompt via erl main.erl, the following error occurred:
$ erlc main.erl
main.erl:20: syntax error before: '('
main.erl:13: function new/2 undefined
main.erl:15: Warning: record person is unused
Could anyone help me out? I didn't see any explicit culprit against my problem.
Thanks in advance.
On the last line it should be braces, not parentheses:
new(Name, Age) ->
#person{name=Name, age=Age}.
See the documentation on records for more information (and examples)

ROBLOX Lua Error in script: '=' expected near '<eof>'

Hello I am writing a scipt on ROBLOX and I have encountered a problem.
function showVictoryMessage(playerName)
local message = Instance.new("Message")
message.Text = playerName .." has won!"
message.Parent = game.Workspace
wait (2)
message.Destroy()
end
Upon running this function, or more specifically the "message.Destroy" command, I get the error: Error in script: '=' expected near '< eof >'
I have never seen this error before, and the ROBLOX wiki page on Lua errors doesn't mention it.
I would very much appreciate help in this, because I don't personally know anyone who has coded in Lua.
Looks like a syntax error. message.Destroy() should be message:Destroy() according to this Roblox wiki page http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy
Also see the section Explosions, Messages, and More at URL http://wiki.roblox.com/index.php?title=Basic_Scripting which provides similar syntax using the colon (:) operator.
See also Difference between . and : in Lua and explanation of "possible side-effects of calculations/access are calculated only once" with colon notation.
Instead of message.Destroy() it should be message:Destroy()
Remember that '.' are used directory-wise and ":' are used for inbuilt functions.
WOOOOOOOO! It was a syntax error. The correct command is message:Destroy. Cause why would object.Destroy work and message.Destroy not?

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
//------------------------------------------------------------------------

Trying to compile my first program in Erlang

I am getting compiler issue when trying to compile a simple test program on erlang. I have tried both on mac os x (lion) and windows 7 (64)
~module(tut).
~export([double/1]).
double (N) ->
N*2.
I have checked that the file is named correctly and the correct modules seem to be installed I am using the otp_win64_R16B on my windows machine. I get the following error on both platforms
16> c(tut).
tut.erl:1: syntax error before: '~'
tut.erl:2: syntax error before: '~'
tut.erl:4: no module definition
tut.erl:4: Warning: function double/1 is unused
Can anyone help?
Well, it should be: -module and -export, with the - not with ~.
You should replace ~ with -. Please take a try.

Resources