mirror of
https://github.com/github/semantic.git
synced 2024-12-27 00:44:57 +03:00
First attempt at compiling string literals.
This commit is contained in:
parent
cd69e8aab5
commit
b5d6e7186f
@ -19,6 +19,7 @@ import Data.Coerce
|
||||
import Data.Foldable
|
||||
import Data.Function
|
||||
import Data.List.NonEmpty (NonEmpty (..))
|
||||
import Data.Traversable
|
||||
import GHC.Records
|
||||
import Source.Span (Span)
|
||||
import Syntax.Stack (Stack (..))
|
||||
@ -355,7 +356,15 @@ instance Compile Py.SetComprehension
|
||||
|
||||
deriving instance Compile Py.SimpleStatement
|
||||
|
||||
instance Compile Py.String
|
||||
instance Compile Py.String where
|
||||
compile it@Py.String { extraChildren } cc _ = do
|
||||
contents <- for extraChildren $ \case
|
||||
Prj Py.EscapeSequence { text } -> pure text
|
||||
other -> fail ("Couldn't string-desugar " <> show other)
|
||||
|
||||
let new = pure "__semantic_prelude" ... "str" ... "__class" ... "__new__"
|
||||
cc $ locate it (new $$ Core.string (mconcat contents))
|
||||
|
||||
instance Compile Py.Subscript
|
||||
|
||||
instance Compile Py.True where
|
||||
|
@ -2,7 +2,13 @@
|
||||
type <- \name -> \bases -> \dict ->
|
||||
#record { __name: name, __bases: bases, __dict: dict };
|
||||
|
||||
instance <- \class -> \prim -> \slots ->
|
||||
#record { __class: class, __prim: prim, __slots: slots }
|
||||
|
||||
object <- type "object" #unit #record{};
|
||||
|
||||
#record { type: type, object: object }
|
||||
str <- type "str" object #record { }
|
||||
str.__class.__new__ = \contents -> instance str contents #record{}
|
||||
|
||||
#record { type: type, object: object, string: string }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user