Coder Social home page Coder Social logo

Add quasi quotation about language-rust HOT 3 OPEN

harpocrates avatar harpocrates commented on August 27, 2024
Add quasi quotation

from language-rust.

Comments (3)

harpocrates avatar harpocrates commented on August 27, 2024

Here is a simple example of why we need the ViewPatterns approach:

> let x = [expr| 1 |]
> let y = [stmt| $x; |]
<interactive>:42:9: error:
    • Exception when trying to run compile-time code:
        Subst x
      Code: Language.Haskell.TH.Quote.quoteExp stmt " $x; "
    • In the quasi-quotation: [stmt| $x; |]

Even more insidiously (check -ddump-splices and you'll see the error is "leaking")

> let x = [expr| 1 + 2 |]
> let y = [expr| $x * 3 |]
<interactive>:11:15: error:
    • Couldn't match expected type ‘Language.Rust.Data.Position.Span’
                  with actual type ‘Language.Rust.Syntax.AST.Expr
                                      Language.Rust.Data.Position.Span’
    • In the fifth argument of ‘Language.Rust.Syntax.AST.Binary’, namely
        ‘x’
      In the expression:
        (Language.Rust.Syntax.AST.Binary
           []
           Language.Rust.Syntax.AST.MulOp
           x
           (Language.Rust.Syntax.AST.Lit
              []
              (Language.Rust.Syntax.AST.Int
                 Language.Rust.Syntax.AST.Dec
                 3
                 Language.Rust.Syntax.AST.Unsuffixed
                 (Language.Rust.Data.Position.Span
                    (Language.Rust.Data.Position.Position 6 11 21)
                    (Language.Rust.Data.Position.Position 7 11 22)))
              (Language.Rust.Data.Position.Span
                 (Language.Rust.Data.Position.Position 6 11 21)
                 (Language.Rust.Data.Position.Position 8 11 23)))
           x)
      In an equation for ‘y’:
          y = (Language.Rust.Syntax.AST.Binary
                 []
                 Language.Rust.Syntax.AST.MulOp
                 x
                 (Language.Rust.Syntax.AST.Lit
                    []
                    (Language.Rust.Syntax.AST.Int
                       Language.Rust.Syntax.AST.Dec
                       3
                       Language.Rust.Syntax.AST.Unsuffixed
                       (Language.Rust.Data.Position.Span
                          (Language.Rust.Data.Position.Position 6 11 21)
                          (Language.Rust.Data.Position.Position 7 11 22)))
                    (Language.Rust.Data.Position.Span
                       (Language.Rust.Data.Position.Position 6 11 21)
                       (Language.Rust.Data.Position.Position 8 11 23)))
                 x)

from language-rust.

harpocrates avatar harpocrates commented on August 27, 2024

Alright. I've mulled over this for a week and I've come up with a new approach, which isn't a hack:

  • wrap all recursive ASTs in m (so data ExprT m a = PlusT (m (ExprT m a)) (m (ExprT m a)) a...)
  • update production rules to be parametrized over Context m => ExprT m Span where Context defines functions that need to look at the contents of parsed values (like the path case of patterns which checks for one identifier patterns)
  • make type synonyms (type Expr = ExprT Identity) and patterns (pattern Plus x y = PlusT (Identity x) (Identity y)). This also means fixing how Haddock handles pattern synonyms
  • re-make Quote!

This may take some time...

from language-rust.

harpocrates avatar harpocrates commented on August 27, 2024

This won't make the 0.1.0.0 release. Instead, Language.Rust.Quote quasiquoters will not support $x or $x:ty splices/extractors.

from language-rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.