ptal / oak

A typed parser generator embedded in Rust code for Parsing Expression Grammars
Apache License 2.0
142 stars 14 forks source link

Types reduce too early in Depth #94

Closed ptal closed 8 years ago

ptal commented 8 years ago

Consider the following grammar:

  underscore = "_"
  digits = (underscore* digit)+ > id
  digit = ["0-9"]

  fn id(v: Vec<char>) -> Vec<char> {
    v
  }

There is a type mismatch because the type inferred of (underscore* digit)+ is Vec<(Vec<()>, char)> instead of Vec<char>. The problem is due to the depth algorithm:

  1. Surface is called and underscore has the type (^), however (underscore* digit)+ is not typed since it is under a semantic action.
  2. Depth is called and reduce the type of underscore to () because of the final type reduction (TypeRewriting::final_reduce).
  3. Surface is called by depth on (underscore* digit)+ but it is too late because underscore has already be reduced.

The possible solutions are: