Erl_parse Syntax Error Before
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might
Json Parse Syntax Error
have Meta Discuss the workings and policies of this site About angular parse syntax error Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting parse error before else ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7
Parse Error Before ' ' Token
million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up What am I doing wrong with erl_parse:parse_form? up vote 1 down vote favorite I wrote a Hello-World module and compiled it successfully. And then I tried to learn the things under the hood by using erl_scan and erl_parse.
Parse Error Before String Constant
-module(useless). -export([hello/0]). hello() -> io:format("hello world\n"). and I type in the erl shell {ok, S} = file:read_file("useless.erl"). and {ok, T, _} = erl_scan:string(binary_to_list(S)). It works fine apparently. But when I try erl_parse:parse_form(T). It gives {error,{2,erl_parse,["syntax error before: ","'-'"]}} What am I doing wrong? Edit: the module compile is helpful. Also this is cool. erlang share|improve this question edited Jan 23 '15 at 6:20 asked Jan 22 '15 at 8:30 user1937358 9417 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted The function erl_parse:parse_form/1 works on one form only. So you must split the result of erl_scan:string/1 into individual forms first. you can use erl_scan:tokens to achieve this (this code wors, but I am not sure I use the function in the right way): -module(useless). -export([eval/1]). eval(File) -> {ok, B} = file:read_file(File), Forms = scan(erl_scan:tokens([],binary_to_list(B),1),[]), F = fun(X) -> {ok,Y} = erl_parse:parse_form(X), Y end, [F(X) || X <- Forms]. scan({done,{ok,T,N},S},Res) -> scan(erl_scan:tokens([],S,N),[T|Res]); scan(_,Res) -> lists:reverse(Res). share|improve this a
sorted by: [ date ] [ thread ] [ subject ] [ parse error before char author ] I just stumbled upon an interesting
C Parse Error
erlc error message. It's not a big issue, but when I saw the error I wondered if this is desired behavior. I mean, is this something that can and should be improved http://stackoverflow.com/questions/28084192/what-am-i-doing-wrong-with-erl-parseparse-form to provide a more descriptive error message? Thoughts? $ cat foo.erl -module(foo). -include("foo.hrl"). -export([foo/0]). foo() -> io:format("foo"). $ cat foo.hrl -define(FOO, bar). baz $ erlc foo.erl foo.hrl:3: syntax error before: $ erl 1> compile:file("foo.erl", [return]). {error,[{"foo.hrl", [{3,erl_parse,["syntax error before: ",[]]}]}], []} http://erlang.org/pipermail/erlang-questions/2014-January/076591.html Same message if you append "foo\n" to foo.erl: $ cat foo.erl -module(foo). -include("foo.hrl"). -export([foo/0]). foo() -> io:format("foo."). foo $ erlc foo.erl foo.erl:8: syntax error before: $ erl 1> compile:file("foo.erl",[return]). {error,[{"foo.erl", [{8,erl_parse,["syntax error before: ",[]]}]}, {"foo.hrl",[{3,erl_parse,["syntax error before: ",[]]}]}], []} As a test I've replaced line 2 in foo.hrl with "foo\n": $ cat foo.hrl -define(FOO, bar). foo baz $ erlc foo.erl foo.erl:8: syntax error before: foo.hrl:3: syntax error before: baz $ erl 1> compile:file("foo.erl",[return]). {error,[{"foo.erl", [{8,erl_parse,["syntax error before: ",[]]}]}, {"foo.hrl",[{3,erl_parse,["syntax error before: ","baz"]}]}], []} Previous message: [erlang-questions] Generating fake data with PropEr? Next message: [erlang-questions] erlc: interesting error message Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] More information about the erlang-questions mailing list
Sign in Pricing Blog Support Search GitHub This repository Watch 26 Star 286 Fork 59 hexpm/hex Code https://github.com/hexpm/hex/issues/279 Issues 1 Pull requests 0 Projects 0 Pulse Graphs New issue http://erlang-questions.erlang.narkive.com/GAVJDiA6/clarify-escaping-strings-in-erl-scan-string-erl-parse-parse-term Ugly error when ~/.mix/hex.config is wrong #279 Closed sinetris opened this Issue Aug 3, 2016 · 3 comments Projects None yet Labels Kind:Bug Level:Starter Note:Help wanted Milestone v0.14.0 Assignees No one assigned 3 participants sinetris commented Aug 3, error before 2016 I had an old configuration line in ~/.mix/hex.config and after a mix local.hex I was getting this error: Could not start Hex. Try fetching a new version with "mix local.hex" or uninstalling it with "mix archive.uninstall hex.ez" 12:24:16.865 [info] Application hex exited: Hex.start(:normal, []) returned an error: shutdown: failed to start child: Hex.State parse error before ** (EXIT) an exception was raised: ** (MatchError) no match of right hand side value: {:error, {1, :erl_parse, ['syntax error before: ', []]}} (hex) lib/hex/config.ex:5: Hex.Config.read/0 (hex) lib/hex/state.ex:21: Hex.State.start_link/0 (stdlib) supervisor.erl:365: :supervisor.do_start_child/2 (stdlib) supervisor.erl:348: :supervisor.start_children/3 (stdlib) supervisor.erl:314: :supervisor.init_children/2 (stdlib) gen_server.erl:328: :gen_server.init_it/6 (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 The error came from: {:ok, term} = decode_term(binary) https://github.com/hexpm/hex/blob/v0.13.0/lib/hex/config.ex#L5 It would be nice to have a better error message, or a warning saying something like "Line N is not valid, will be ignored" 😄 ericmj added Kind:Bug Level:Starter Note:Help wanted labels Aug 3, 2016 ericmj added this to the v0.14.0 milestone Aug 3, 2016 smeevil commented Aug 14, 2016 If anyone could paste their ~/.mix/hex.config that generates the error, before throwing it away, that would help :) Hex member ericmj commented Aug 14, 2016 The issue is this commit: d588507. It needs to be reverted and when we read an elixir config when to make sure to write an erlang config to ensure th
tokenizing / parsing witherl_scan:string/1 and erl_parse:parse_term/1 ?E.g. in the interactive Erlang shell I simply do:1> {a_string, "foo(\"hi\")"}.{a_string,"foo(\"hi\")"}But if I try to do the same with erl_scan:string anderl_parse:parse_term, it is tokenizing not as expected and parsinggives an error:2> {ok,Tokens,_}=erl_scan:string("{a_string, \"foo(\"hi\")\"}.").{ok,[{'{',1},{atom,1,a_string},{',',1},{string,1,"foo("},{atom,1,hi},{string,1,")"},{'}',1},{dot,1}],1}3> erl_parse:parse_term(Tokens).{error,{1,erl_parse,["syntax error before: ","hi"]}}4>So what is the proper way to escape strings in this context ?--Roberto Sacconhttp://rsaccon.com vladdu55 (Vlad Dumitrescu) 2007-12-28 13:38:37 UTC PermalinkRaw Message Hi,Post by rsaccon (Roberto Saccon)But if I try to do the same with erl_scan:string anderl_parse:parse_term, it is tokenizing not as expected and parsing2> {ok,Tokens,_}=erl_scan:string("{a_string, \"foo(\"hi\")\"}.").You have to escape even the backslashes in the inside string, like this:{ok,Tokens,_}=erl_scan:string("{a_string, \"foo(\\\"hi\\\")\"}.").best regards,Vlad--Some people see things that are and ask, Why?Some people dream of things that never were and ask, Why not?Some people have to go to work and don't have time for all that.--- George Carlin csanto (Corrado Santoro) 2007-12-28 13:52:05 UTC PermalinkRaw Message You have to quote the backslashes:7> {ok,Tokens,_}=erl_scan:string("{a_string, \"foo(\\\"hi\\\")\"}.").{ok,[{'{',1},{atom,1,a_string},{',',1},{string,1,"foo(\"hi\")"},{'}',1},{dot,1}],1}8> erl_parse:parse_term(Tokens).{ok,{a_string,"foo(\"hi\")"}}:-)Cheers,--CorradoPost by rsaccon (Roberto Saccon)How do I escape strings in Erlang before tokenizing / parsing witherl_scan:string/1 and erl_parse:parse_term/1 ?1> {a_string, "foo(\"hi\")"}.{a_string,"foo(\"hi\")"}But if I try to do the same with erl_scan:string anderl_parse:parse_term, it is tokenizing not as expected and parsing2> {ok,Tokens,_}=erl_scan:string("{a_string, \"foo(\"hi\")\"}.").{ok,[{'{',1},{atom,1,a_string},{',',1},{string,1,"foo("},{atom,1,hi},{string,1,")"},{'}',1},{dot,1}],1}3> erl_parse:parse_term(Tokens).{error,{1,erl_parse,["syntax error before: ","hi