Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmaCC_Elixir: Identifier misfires #32

Open
mariari opened this issue Oct 28, 2024 · 2 comments · May be fixed by #35
Open

SmaCC_Elixir: Identifier misfires #32

mariari opened this issue Oct 28, 2024 · 2 comments · May be fixed by #35

Comments

@mariari
Copy link
Contributor

mariari commented Oct 28, 2024

EDIT

See my followup comment in this thread, I've identified the real issue, which is bracket_identifiers etc apply even when they should not.

This applies to the other Identifier rules in general.

To give another example:

iex(ex-mariari@Gensokyo)4> with (5) <- 5 do 5 end
5

Fails to parse as I believe it's parsing as a paren_identifier

Original Message

I'm unsure where the grammar goes wrong on this one.

Picture below is a few code examples.

with %{} <- a,
     b <- height do
	5
end

with [a|_] <- a do
	5
end

with %{} <- a,
     b <- height do
	5
end

with [a, b] <- a,
     b <- height do
	5
end

Namely it has issues parsing the last one, where you have a list followed with a comma, this is true for both improper and normal lists, however structs and maps seem to parse fine.

@mariari mariari changed the title SmaCC Issue with parsing lists in expressions SmaCC_Elixir Issue with parsing lists in expressions Oct 28, 2024
@mariari
Copy link
Contributor Author

mariari commented Nov 3, 2024

After investigating a bit, I've found a possible explanation:

Let us look at the parser on the following examples both in SmaCC and in what Elixir itself gives us

f[:a]

f [:a]

In SmaCC I see these are the same

These are expressions 4 and 5.

However when looking at it via iex and the yrl file I see the following

iex(10)> quote do f[:a] end
{{:., [from_brackets: true], [Access, :get]}, [from_brackets: true],
 [{:f, [], Elixir}, :a]}
iex(11)> quote do f [:a] end
{:f, [], [[:a]]}

Which the first corresponds to their rule on bracket_expr while the last is not

bracket_expr -> access_expr bracket_arg : build_access('$1', meta_with_from_brackets('$2')).
...
Erlang code .
...
build_access(Expr, {List, Meta}) ->
  {{'.', Meta, ['Elixir.Access', get]}, Meta, [Expr, List]}.

I believe this is relevant due to how the with parses, as with this finding, I got the following to parse

@mariari mariari changed the title SmaCC_Elixir Issue with parsing lists in expressions SmaCC_Elixir: dot_bracket_identifier misfires Nov 3, 2024
@mariari mariari changed the title SmaCC_Elixir: dot_bracket_identifier misfires SmaCC_Elixir: Identifier misfires Nov 3, 2024
@mariari
Copy link
Contributor Author

mariari commented Nov 3, 2024

To give a few more examples of identifiers improperly ignoring spaces:

iex(mariari@Gensokyo)9> quote do f (1,2,3) end
** (SyntaxError) invalid syntax found on iex:9:12:
    error: unexpected parentheses. If you are making a function call, do not insert spaces between the function name and the opening parentheses. Syntax error before: '('9quote do f (1,2,3) end^
    │
    └─ iex:9:12
    (iex 1.17.3) lib/iex/evaluator.ex:295: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.17.3) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.17.3) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 6.1) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
iex(mariari@Gensokyo)9> quote do f(1,2,3) end
{:f, [], [1, 2, 3]}

mariari added a commit to mariari/SmaCC that referenced this issue Nov 3, 2024
@mariari mariari linked a pull request Nov 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant