mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
Introduce QualifiedIdentifer syntax
This commit is contained in:
parent
2d91f699f6
commit
e7ef9596b0
@ -126,6 +126,25 @@ instance ( Addressable (LocationFor v) es
|
|||||||
instance FreeVariables1 Identifier where
|
instance FreeVariables1 Identifier where
|
||||||
liftFreeVariables _ (Identifier x) = point x
|
liftFreeVariables _ (Identifier x) = point x
|
||||||
|
|
||||||
|
newtype QualifiedIdentifier a = QualifiedIdentifier a
|
||||||
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
|
instance Eq1 QualifiedIdentifier where liftEq = genericLiftEq
|
||||||
|
instance Ord1 QualifiedIdentifier where liftCompare = genericLiftCompare
|
||||||
|
instance Show1 QualifiedIdentifier where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
|
instance ( Addressable (LocationFor v) es
|
||||||
|
, Member Fail es
|
||||||
|
, Member (Reader (EnvironmentFor v)) es
|
||||||
|
, Member (State (StoreFor v)) es
|
||||||
|
, FreeVariables t
|
||||||
|
) => Evaluatable es t v QualifiedIdentifier where
|
||||||
|
eval (QualifiedIdentifier xs) = do
|
||||||
|
env <- ask
|
||||||
|
let name = qualifiedName (subterm xs)
|
||||||
|
maybe (fail ("free variable: " <> unpack name)) deref (envLookup name env)
|
||||||
|
|
||||||
|
|
||||||
newtype Program a = Program [a]
|
newtype Program a = Program [a]
|
||||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
|
@ -195,35 +195,7 @@ instance Ord1 MemberAccess where liftCompare = genericLiftCompare
|
|||||||
instance Show1 MemberAccess where liftShowsPrec = genericLiftShowsPrec
|
instance Show1 MemberAccess where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
-- TODO: Implement Eval instance for MemberAccess
|
-- TODO: Implement Eval instance for MemberAccess
|
||||||
instance ( FreeVariables t
|
instance Member Fail es => Evaluatable es t v MemberAccess
|
||||||
, Ord l
|
|
||||||
, Show l
|
|
||||||
, Show t
|
|
||||||
, Show (Cell l (Value l t))
|
|
||||||
, CellValue l (Value l t)
|
|
||||||
, Member Fail es
|
|
||||||
, Member (State (EnvironmentFor (Value l t))) es
|
|
||||||
, Member (Reader (EnvironmentFor (Value l t))) es
|
|
||||||
, Member (State (StoreFor (Value l t))) es
|
|
||||||
) => Evaluatable es t (Value l t) MemberAccess where
|
|
||||||
eval (MemberAccess a b) = do
|
|
||||||
let scope = qualifiedName (subterm a)
|
|
||||||
env <- get @(EnvironmentFor (Value l t))
|
|
||||||
case envLookup scope env of
|
|
||||||
Nothing -> fail ("qualified name not found: " <> show scope)
|
|
||||||
Just addr -> do
|
|
||||||
store <- get @(StoreFor (Value l t))
|
|
||||||
case storeLookup addr store of
|
|
||||||
Nothing -> fail "address not found"
|
|
||||||
Just c -> do
|
|
||||||
let interface = val c
|
|
||||||
Interface _ env <- maybe
|
|
||||||
(fail ("expected an interface, but got: " <> show interface))
|
|
||||||
pure
|
|
||||||
(prj interface :: Maybe (Interface l t))
|
|
||||||
local (const env) (subtermValue b)
|
|
||||||
|
|
||||||
instance Member Fail es => Evaluatable es t Type.Type MemberAccess where
|
|
||||||
|
|
||||||
-- | Subscript (e.g a[1])
|
-- | Subscript (e.g a[1])
|
||||||
data Subscript a
|
data Subscript a
|
||||||
|
@ -79,6 +79,7 @@ type Syntax =
|
|||||||
, Syntax.Empty
|
, Syntax.Empty
|
||||||
, Syntax.Error
|
, Syntax.Error
|
||||||
, Syntax.Identifier
|
, Syntax.Identifier
|
||||||
|
, Syntax.QualifiedIdentifier
|
||||||
, Syntax.Program
|
, Syntax.Program
|
||||||
, Type.Annotation
|
, Type.Annotation
|
||||||
, []
|
, []
|
||||||
@ -451,8 +452,14 @@ slice = makeTerm <$> symbol Slice <*> children
|
|||||||
<*> (term expression <|> emptyTerm))
|
<*> (term expression <|> emptyTerm))
|
||||||
|
|
||||||
call :: Assignment
|
call :: Assignment
|
||||||
call = makeTerm <$> symbol Call <*> children (Expression.Call <$> pure [] <*> term expression <*> (symbol ArgumentList *> children (manyTerm expression)
|
call = makeTerm <$> symbol Call <*> children (Expression.Call <$> pure [] <*> term qualifiedIdentifier <*> (symbol ArgumentList *> children (manyTerm expression) <|> someTerm comprehension) <*> emptyTerm)
|
||||||
<|> someTerm comprehension) <*> emptyTerm)
|
where
|
||||||
|
qualifiedIdentifier = makeQualifiedIdentifier <$> symbol Attribute <*> children (some identifier)
|
||||||
|
<|> plainIdentifier
|
||||||
|
plainIdentifier = makeTerm <$> location <*> (Syntax.QualifiedIdentifier <$> identifier)
|
||||||
|
makeQualifiedIdentifier loc [x] = makeTerm loc (Syntax.QualifiedIdentifier x)
|
||||||
|
makeQualifiedIdentifier loc xs = makeTerm loc (Syntax.QualifiedIdentifier (makeTerm' loc (inj xs)))
|
||||||
|
|
||||||
|
|
||||||
boolean :: Assignment
|
boolean :: Assignment
|
||||||
boolean = makeTerm <$> token Grammar.True <*> pure Literal.true
|
boolean = makeTerm <$> token Grammar.True <*> pure Literal.true
|
||||||
|
Loading…
Reference in New Issue
Block a user