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

Hack previous parser behaviour for AccSection #311

Merged
merged 2 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions syntax/text/parser3/src/Luna/Pass/Parsing/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ buildIR = \(Spanned cs ast) -> addCodeSpan cs =<< case ast of

Ast.InfixApp l f r -> do
let tok = Ast.unspan f
dot = tok == Ast.Operator Name.acc
specialOp = case tok of
Ast.Operator op -> if
| op == Name.assign -> Just IR.unify'
Expand All @@ -305,22 +306,46 @@ buildIR = \(Spanned cs ast) -> addCodeSpan cs =<< case ast of
| otherwise -> Nothing
_ -> Nothing
realNumber =
let dot = tok == Ast.Operator Name.acc
isNumber ast = case Ast.unspan ast of
let isNumber ast = case Ast.unspan ast of
Ast.Number _ -> True
_ -> False
lIsNum = isNumber l
rIsNum = isNumber r
in dot && lIsNum && rIsNum

-- The old parser translates a .foo.bar to application
-- between Var "a" and AccSection ["foo", "bar"], a core
-- constructor of form AccSection { path :: Vec16 Name }.
-- The constructor is deprecated, as it supports only named
-- sections and discards information about code spans.
-- The real solution should be implemented in passes,
-- probably in desugaring, as this situation is very similar
-- to wildcard handling.
-- See luna/luna#301 for more info
hackAccSection left op = do
let noHack = do
r' <- buildIR $! Ast.prependAsOffset f r
op left r'
if dot then do
Layer.read @IR.Model left >>= \case
Uni.AccSection accSec' -> do
case Ast.unspan r of
Ast.Var r' -> do
oldSection <- Mutable.toList accSec'
newSection <- Mutable.fromList
(oldSection <> [r'])
IR.accSection' newSection
_ -> noHack
_ -> noHack
else noHack

case specialOp of
Just op -> do
if realNumber then do
buildRealIR l r
else do
l' <- buildIR l
r' <- buildIR $! Ast.prependAsOffset f r
op l' r'
hackAccSection l' op
Nothing -> do
f' <- buildIR f
l' <- buildIR l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ unitSpec :: Spec
unitSpec = describe "unit" $ do
it "empty" $ e_x "" ""

accSectionSpec :: Spec
accSectionSpec = describe "acc section" $ do
ite "[1,2,3].each .succ.pred" "[1, 2, 3] . each .succ.pred"
ite "[1,2,3].each .succ.pred.foo" "[1, 2, 3] . each .succ.pred.foo"
ite "[1,2,3].each .succ.pred.foo.bar" "[1, 2, 3] . each .succ.pred.foo.bar"

debugSpec :: Spec
debugSpec = xdescribe "error" $ it "debug" $ do

let input = [qqStr|.asText|]
let input = [qqStr|a .succ.pred.foo|]

putStrLn "\n\n"
pprint $ PP.evalVersion1With Macro.unit (convert input)
Expand All @@ -102,5 +108,6 @@ spec = do
functionDefSpec
caseSpec
unitSpec
accSectionSpec

debugSpec