Skip to content

Commit

Permalink
Small fix for the parser to handle functions with no arguments
Browse files Browse the repository at this point in the history
Reuses the `unit` approach
Added test cases for the parse rules
Updated core ref
  • Loading branch information
JustusAdam committed Sep 27, 2018
1 parent 0a5b68a commit a8bd949
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/Ohua/Compat/Clike/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Ohua.Compat.Clike.Types
import Ohua.ALang.Lang
import Ohua.Types
import Ohua.ALang.NS
import Ohua.Unit
import qualified Data.HashMap.Strict as HM
import qualified Ohua.ParseTools.Refs as Refs
import Ohua.ALang.Refs (mkTuple)
Expand Down Expand Up @@ -123,7 +124,7 @@ Vars
Apply
:: { RawExpressionProducer }
: ApplyParams { $1 }
| { identity }
| { (`Apply` someUnitExpr) }

ApplyParams
:: { RawExpressionProducer }
Expand Down
4 changes: 2 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ packages:
- .
- location:
git: https://github.com/ohua-dev/ohua-core
commit: 843bcdca4abc1393076e3ae69d750af095ed7d59
commit: f29a82cd8119a26ddd443324f4509d9c55e4e92f
extra-dep: true
extra-deps: []
resolver: lts-12.6
resolver: lts-12.10
45 changes: 26 additions & 19 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import qualified Data.ByteString.Lazy as B
import Ohua.ALang.Lang
import Ohua.ALang.NS
import Ohua.ALang.Refs (mkTuple)
import Ohua.Unit
import Ohua.Compat.Clike.Parser
import Ohua.Compat.Clike.Types
import Ohua.Types
Expand Down Expand Up @@ -46,25 +47,31 @@ main = hspec $
-- it "parses an if" $
-- lp "if (add (x, y)) { fn a () { return b; } return a; } else { return c; }"
-- `shouldBe`
it "ignores a line comment preceding an expression" $
lp "// some content\na" `shouldBe` "a"
it "ignores consecutive line comments" $
lp "// some content\n //something\na" `shouldBe` "a"
it "ignores a line comment following an expression" $
lp "a // some content" `shouldBe` "a"
it "ignores a line comment between an expression" $ do
lp "a(// some content\n b)" `shouldBe` ("a" `Apply` "b")
lp "a// some content\n( b)" `shouldBe` ("a" `Apply` "b")
it "ignores a block comment preceding an expression" $ do
lp "/* ignore this */ a" `shouldBe` "a"
it "ignores a block comment following an expression" $ do
lp "a /* ignore this */" `shouldBe` "a"
it "ignores a block comment in between an expression" $ do
lp "a /* ignore this */(b)" `shouldBe` ("a" `Apply` "b")
lp "a (/* ignore this */b)" `shouldBe` ("a" `Apply` "b")
lp "a (b/* ignore this */)" `shouldBe` ("a" `Apply` "b")
it "ignores a block comment with newline preceding an expression" $ do
lp "/* ignore this\n */ a" `shouldBe` "a"
describe "comments" $ do
it "ignores a line comment preceding an expression" $
lp "// some content\na" `shouldBe` "a"
it "ignores consecutive line comments" $
lp "// some content\n //something\na" `shouldBe` "a"
it "ignores a line comment following an expression" $
lp "a // some content" `shouldBe` "a"
it "ignores a line comment between an expression" $ do
lp "a(// some content\n b)" `shouldBe` ("a" `Apply` "b")
lp "a// some content\n( b)" `shouldBe` ("a" `Apply` "b")
it "ignores a block comment preceding an expression" $ do
lp "/* ignore this */ a" `shouldBe` "a"
it "ignores a block comment following an expression" $ do
lp "a /* ignore this */" `shouldBe` "a"
it "ignores a block comment in between an expression" $ do
lp "a /* ignore this */(b)" `shouldBe` ("a" `Apply` "b")
lp "a (/* ignore this */b)" `shouldBe` ("a" `Apply` "b")
lp "a (b/* ignore this */)" `shouldBe` ("a" `Apply` "b")
it "ignores a block comment with newline preceding an expression" $ do
lp "/* ignore this\n */ a" `shouldBe` "a"
describe "functions with no inputs" $ do
it "parses a simple call" $
lp "a()" `shouldBe` ("a" `Apply` someUnitExpr)
it "parses chains" $
lp "a(b())" `shouldBe` ("a" `Apply` ("b" `Apply` someUnitExpr))
it "parses a function with signature" $ (parseTLFunDef "fn func (x : int, y : Maybe<String>, z : T<B, a>) -> Q { x }")
`shouldBe`
("func", Annotated (FunAnn [ Immutable $ TyRef "int"
Expand Down

0 comments on commit a8bd949

Please sign in to comment.