Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Harrison Houghton
    @hrhino
    This message was deleted
    Roman Janusz
    @ghik
    Hi! Can scalameta parser be used in "best-effort" mode, i.e. can it parse code that contains some recoverable syntax errors like missing closing braces? Something like this is essential for implementing interactive code editing environments. Judging from the fact that metals is based on scalameta, it should be able to do that, right?
    Ólafur Páll Geirsson
    @olafurpg
    @ghik the scalameta parser does not do error recovery, there's an open issue about it here scalameta/scalameta#1170 but I don't think it will be worked on anytime soon.
    In Metals we only use Scalameta trees for source code that parses successfully
    Parser recovery is definitely essential for implementing interactive features like completions, but we use the presentation compiler for that in Metals so the lack of parser recovery in Scalameta hasn't been an issue in Metals so far.
    Roman Janusz
    @ghik
    I swear I'll end up writing my own parser at some point...
    Ólafur Páll Geirsson
    @olafurpg
    @ghik what's your use-case?
    the parser in the Scala compiler does decent error recovery
    Roman Janusz
    @ghik
    Well, a programming language, to be honest... but a simple one, for very specific, company-internal use case. I wanted to use a small subset of Scala.
    Yes, scalac parser does that well, but it loses a lot of information
    Lossless parsing is one of the selling points of scalameta
    Ólafur Páll Geirsson
    @olafurpg
    If you're doing a new programming language then I think it's totally reasonable to write your own parser
    even if it's only a subset of Scala
    btw, the dotty parser doesn't loose as much information as the scalac parser
    Roman Janusz
    @ghik
    That's interesting, how public/reusable its API is?
    Ólafur Páll Geirsson
    @olafurpg
    there is also a nice parser in https://github.com/twitter/rsc/ that you could base off
    Roman Janusz
    @ghik
    I'd be fine if I could just fork some existing parser and modify it to my needs
    Ólafur Páll Geirsson
    @olafurpg
    I think you can consider all dotty compiler apis as private
    Roman Janusz
    @ghik
    Oh yeah I forgot about rsc, thanks
    Ólafur Páll Geirsson
    @olafurpg
    best approach is probably to copy-paste and adapt
    so find the code you understand the best and feel most comfortable changing
    I BTW found the link to the tolerant-php-parser in https://github.com/scalameta/scalameta/issues/1170#issuecomment-403751263 interesting
    Roman Janusz
    @ghik
    I'll look into it, thanks for help and all the references!
    Ólafur Páll Geirsson
    @olafurpg
    One somewhat interesting observation I found while working on diagnostics in Metals is that it seems to be totally fine to publish only a single syntax error
    it's usually the first syntax error that's most helpful in tracking down the problem, if the parser recovers from the first error and continues to publish 10 more syntax errors then it makes it harder to track the source of the error
    Roman Janusz
    @ghik
    yeah but even that single syntax error prevents the parser from returning an actual tree that could be used for things like completion
    Ólafur Páll Geirsson
    @olafurpg
    so Metals actually runs the Scalameta parser on every keystroke even if it has no parser recovery and publishes at most a single syntax error
    the thing is that you wouldn't be able to implement completions anyways with the impartial scalameta tree
    for completions you need a typechecker
    Roman Janusz
    @ghik
    scala presentation compiler has no problem with that
    it can typecheck on best-effort manner
    Ólafur Páll Geirsson
    @olafurpg
    yeah, we use the presentation compiler with completions and it's working pretty great in my experience
    Roman Janusz
    @ghik
    yes I'm also using it in my "current version" of this "programming language"
    but lossy parsing is really biting me
    Ólafur Páll Geirsson
    @olafurpg
    the desugared scalac trees simplify a lot of semantic analysis
    Roman Janusz
    @ghik
    the thing that i hoped for is scalameta for syntactic analysis and presentation compiler for potential typechecking and completion
    presentation compiler unfortunately has a lot of limitations
    for example: it doesn't handle scala.Dynamic well
    Ólafur Páll Geirsson
    @olafurpg
    we have an mtags module in metals that adds several feature improvements to the scala presentation compiler APIs, including support for Dynamic
    the dynamic fixes could be upstreamed into the compiler, but other improvements include for example auto-importing symbols that are in the workspace but not in scope
    we do several syntactic analyses using the scalameta parser such as code folding and document outlines
    but they only run on valid source code, in between that we adjust positions based on token edit distance between the last successful parse and the current dirty buffer
    Kiko
    @kikofernandez
    Hi there. I was wondering if there is any way to get transform a semanticdb class into its pretty printed form, so that I can get interesting information from semantic db and use the AST facilities of scalameta
    Ólafur Páll Geirsson
    @olafurpg
    @kikofernandez the scalafix apis combine the Scalameta ast and SemanticDB
    Kiko
    @kikofernandez
    right, so I have to go for scalafix them. Thanks
    I am really new into Scala and Scalameta et al. Is there any way I can use Scalafix to generate code (not visible to the developer) that gets compiled?
    Anthony Garo
    @agaro1121
    Hi everyone, I want to match on imports that start with a specific string.
    What’s the best way to do that?
    something like:
    case importer"scala.$eref.{..$importeesnel}" =>
          println(eref)
          println(importeesnel)
          println()
    mohnishkodnani
    @mohnishkodnani
    Hi,
    I am trying to create a service , where given certain parameters, you create code for a new usecase. I have a scala.meta.Type from parsing the case class() extends ... with ... > i want to use that scala.meta.Type with reflection to find all the methods I have to override and generate them ? Is there a way to do this ?