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

Parser: possible to recover from missing "? #7677

Closed
magnus-madsen opened this issue May 4, 2024 · 5 comments
Closed

Parser: possible to recover from missing "? #7677

magnus-madsen opened this issue May 4, 2024 · 5 comments
Assignees

Comments

@magnus-madsen
Copy link
Member

/// A type alias introduces a short-hand for an existing type.

/// A type alias for the type Map[Int32, String].
type alias M = Map[Int32 /**/,  String]

/// A function that returns a map of type M.
def f(): M = Map#{ 1 /**/=>/**/ "Hello

/// A function that returns a map of type N.
def g(): N[Int32] = Map#{ /**/ 1 => Ok(123 /**/), 2 => Err("Hello") }

/// Another function that returns a map of type N.
def h(): N[Bool] = Map#{ true => Ok(456) }

This is not a bug.

@herluf-ba
Copy link
Contributor

As things are now I don't think it is feasible. I think this is tied pretty directly to how many restrictions we are willing to place on strings, and right now there just isn't enough to make recovery possible.

If for instance we disallow multi-line strings, recovery is possible and easy to reason about. But then perhaps we need special syntax for multi-line strings ala

/// Multi line strings could use "escaped newlines" for instance
def f(): M = Map#{ 1 /**/=>/**/ "Hello \
"

@magnus-madsen
Copy link
Member Author

Do we allow multi line strings? In the old parser?

I don't think we should, in any case.

@herluf-ba
Copy link
Contributor

I believe the old parser did. Here are the rule(s):

def Str: Rule1[ParsedAst.Literal.Str] = rule {
  SP ~ "\"" ~ zeroOrMore(!("\"" | atomic("${") | atomic("%{")) ~ Chars.CharCode) ~ "\"" ~ SP ~> ParsedAst.Literal.Str
}
    
 // And then Chars is defined like this
object Chars {

  def Literal: Rule1[ParsedAst.CharCode.Literal] = rule {
    SP ~ !("\\" | EOI) ~ capture(CharPredicate.All) ~ SP ~> ParsedAst.CharCode.Literal
  }

  def Escape: Rule1[ParsedAst.CharCode.Escape] = rule {
    SP ~ "\\" ~ capture(CharPredicate.All) ~ SP ~> ParsedAst.CharCode.Escape
  }

  def CharCode: Rule1[ParsedAst.CharCode] = rule {
    Escape | Literal
  }
}

@magnus-madsen
Copy link
Member Author

Hmm!

@magnus-madsen
Copy link
Member Author

Ok; we can discuss this later. I don't think its important for now :)

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