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

Core parser #205

Merged
merged 7 commits into from
Dec 6, 2022
Merged

Core parser #205

merged 7 commits into from
Dec 6, 2022

Conversation

b-studios
Copy link
Collaborator

@b-studios b-studios commented Dec 6, 2022

Still missing:

  • Match

This is an example of how to use the parser:

object ParserExample extends scala.App {

  val parserPositions = new Positions
  val names = new Names(Map("Int" -> symbols.builtins.IntSymbol))
  object messages extends DebugMessaging

  val parsers = CoreParsers(parserPositions, names)

  given ErrorReporter with { var focus = NoSource; val messaging = messages; val positions = parserPositions }

  val result = parsers.parse(StringSource(
    s"""module foo
       |
       |import list/foo
       |
       |type List['A] {
       |  Nil()
       |  Cons(head: 'A, tail: List['A])
       |}
       |
       |interface Exc['E] { raise: ['A]('E) => 'A }
       |
       |extern "my extern"
       |
       |extern {io} def foo['A2](): 'A2 = "my decl"
       |extern {} def bar() {f@f: MyInterface}: Foo at {f} = "my decl"
       |extern {} def bar() {g: MyInterface}: Foo at {g} = "my decl"
       |
       |def hof = { ['b](){ f@f: MyInterface } => (f: (){g:MyIDC} => (Sig at {g}) @ {})(){ f:NyInterface@{hello} } }
       |def prim = { () => return 42 }
       |def union = { () => if (true) (f: () => Int @ {f})() else (g: () => Unit @ {g})() }
       |def baz = { ['b](){ f@f: MyInterface } => (f: () => Unit @ {})() }
       |def bar = { ['b](){ f@f: MyInterface } => return box {f} (f : MyInterface @ {f}) }
       |
       |let myList = !(Cons : (Int, List[Int]) => List[Int] @ {io})(1, (Cons : (Int, List[Int]) => List[Int] @ {io})(2, (Nil : () => List[Int] @ {io})()))
       |
       |export bam
       |""".stripMargin, "input.effekt"))

  def showType(tpe: ValueType) =
    PrettyPrinter.pretty(PrettyPrinter.toDoc(tpe), 30).layout

  def showType(tpe: BlockType) =
    PrettyPrinter.pretty(PrettyPrinter.toDoc(tpe), 30).layout

  println(result)
  println("----")
  result.foreach { module =>
    println(core.PrettyPrinter.format(module).layout)
    module.definitions(0) match {
      case Definition.Def(id, block) =>
        println(showType(block.tpe))
        println(block.capt)
      case Definition.Let(id, binding) => ()
    }
  }
  messages.buffer.foreach {
    msg => println(msg)
  }
}

@b-studios b-studios marked this pull request as ready for review December 6, 2022 18:08
@b-studios
Copy link
Collaborator Author

I am merging this, since this can be of help for @marzipankaiser and @fritzladwig.
However, it would be great to discuss the design-aspect of the compiler pipeline in #204 and maybe revert / change that part, later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant