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

trap invalid opcode #35

Closed
ihrwein opened this issue Oct 14, 2015 · 2 comments
Closed

trap invalid opcode #35

ihrwein opened this issue Oct 14, 2015 · 2 comments

Comments

@ihrwein
Copy link

ihrwein commented Oct 14, 2015

When I try to use the following grammar I get this error in dmesg and the build scipt stops with signal 4:

traps: build-script-bu[7480] trap invalid opcode ip:7f1febafb8f0 sp:7fff55edf848 error:0 in libstd-198068b3.so[7f1feb9ff000+1c1000]

Grammar (It's just an example I can reproduce this with other grammars as well)

grammar;

pub Message: Vec<String> =
  <Token*>;

Token: Token = {
  Ipv4,
  Prec1
};

Prec1 = {
  Float,
  Prec2
};

Prec2 = {
  r".*" => { <>.to_string() }
};

Ipv4: Token = {
  "." <o0:Octet> "." <o1:Octet> "." <o2:Octet> "." <o3:Octet> => {
    format!("{}.{}.{}.{}", o0, o1, o2, o3)
  }
};

Octet =
  r"(25[0-5]|2[0-4][0-9]|[01]?[1-9][0-9]?)\.";

Float: Token = {
  r"[-+]?[0-9]*\.?[0-9]+" => { <>.to_string() }
};
@nikomatsakis
Copy link
Collaborator

Woah. Let me check it out.

@nikomatsakis
Copy link
Collaborator

Ah, I think this is a duplicate of #32. The problem has to do with this:

Prec2 = {
  r".*" => { <>.to_string() }
};

I need to figure out what is going on here, but this is surely not going to work for you in any case. The problem is that LALRPOP operates on a two-stage tokenize-and-then-parse model, and here you have specified a token of "._". This will surely conflict with all the other tokens (e.g., r"[-+]?[0-9]_.?[0-9]+"). In other words, the way that LR(1) parsers work, the generated code must first (unambiguously) decide which regular expression the text belongs to, without consider where we are in the grammar. (It might be interesting, though, to add a PEG mode, which would accept things like this, or perhaps some other similar hybrid.)

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

No branches or pull requests

2 participants