-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a basic expression parser and add some unit tests.
- Loading branch information
0 parents
commit dacd318
Showing
18 changed files
with
663 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.stack-work/ | ||
Contua.cabal | ||
*~ | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Changelog for Contua | ||
|
||
## Unreleased changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="HASKELL_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/.stack-work" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="base-4.12.0.0" level="project" /> | ||
<orderEntry type="library" name="ghc-prim-0.5.3" level="project" /> | ||
<orderEntry type="library" name="integer-gmp-1.0.2.0" level="project" /> | ||
<orderEntry type="library" name="megaparsec-7.0.4" level="project" /> | ||
<orderEntry type="library" name="mtl-2.2.2" level="project" /> | ||
<orderEntry type="library" name="text-1.2.3.1" level="project" /> | ||
<orderEntry type="library" name="bytestring-0.10.8.2" level="project" /> | ||
<orderEntry type="library" name="case-insensitive-1.2.0.11" level="project" /> | ||
<orderEntry type="library" name="containers-0.6.0.1" level="project" /> | ||
<orderEntry type="library" name="deepseq-1.4.4.0" level="project" /> | ||
<orderEntry type="library" name="parser-combinators-1.0.1" level="project" /> | ||
<orderEntry type="library" name="scientific-0.3.6.2" level="project" /> | ||
<orderEntry type="library" name="transformers-0.5.6.2" level="project" /> | ||
<orderEntry type="library" name="array-0.5.3.0" level="project" /> | ||
<orderEntry type="library" name="binary-0.8.6.0" level="project" /> | ||
<orderEntry type="library" name="hashable-1.2.7.0" level="project" /> | ||
<orderEntry type="library" name="integer-logarithms-1.0.2.2" level="project" /> | ||
<orderEntry type="library" name="primitive-0.6.4.0" level="project" /> | ||
<orderEntry type="library" name="hspec-2.6.1" level="project" /> | ||
<orderEntry type="library" name="hspec-megaparsec-2.0.0" level="project" /> | ||
<orderEntry type="library" name="QuickCheck-2.12.6.1" level="project" /> | ||
<orderEntry type="library" name="hspec-core-2.6.1" level="project" /> | ||
<orderEntry type="library" name="hspec-discover-2.6.1" level="project" /> | ||
<orderEntry type="library" name="hspec-expectations-0.8.2" level="project" /> | ||
<orderEntry type="library" name="erf-2.0.0.0" level="project" /> | ||
<orderEntry type="library" name="random-1.1" level="project" /> | ||
<orderEntry type="library" name="template-haskell-2.14.0.0" level="project" /> | ||
<orderEntry type="library" name="tf-random-0.5" level="project" /> | ||
<orderEntry type="library" name="HUnit-1.6.0.0" level="project" /> | ||
<orderEntry type="library" name="ansi-terminal-0.8.2" level="project" /> | ||
<orderEntry type="library" name="call-stack-0.1.0" level="project" /> | ||
<orderEntry type="library" name="clock-0.7.2" level="project" /> | ||
<orderEntry type="library" name="directory-1.3.3.0" level="project" /> | ||
<orderEntry type="library" name="filepath-1.4.2.1" level="project" /> | ||
<orderEntry type="library" name="quickcheck-io-0.2.0" level="project" /> | ||
<orderEntry type="library" name="setenv-0.1.1.3" level="project" /> | ||
<orderEntry type="library" name="stm-2.5.0.0" level="project" /> | ||
<orderEntry type="library" name="time-1.8.0.2" level="project" /> | ||
<orderEntry type="library" name="ghc-boot-th-8.6.4" level="project" /> | ||
<orderEntry type="library" name="pretty-1.1.3.6" level="project" /> | ||
<orderEntry type="library" name="colour-2.3.4" level="project" /> | ||
<orderEntry type="library" name="unix-2.7.2.2" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright Author name here (c) 2019 | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Author name here nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Contua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Main where | ||
|
||
import Parser.Parser | ||
|
||
main :: IO () | ||
main = putStrLn "Not done yet!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type :: a = [2, 1, 3, 7] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
\documentclass{article} | ||
\usepackage[utf8]{inputenc} | ||
\usepackage{amsfonts} | ||
\usepackage{soul} | ||
\usepackage{textcomp} | ||
\usepackage{color} | ||
\usepackage{enumitem} | ||
\usepackage{amsmath} | ||
\usepackage{amssymb} | ||
\usepackage{mathtools} | ||
\usepackage{listings} | ||
\usepackage{amsthm} | ||
\usepackage[dvipsnames]{xcolor} | ||
\usepackage[a4paper, total={6.5in, 10in}]{geometry} | ||
\definecolor{dkgreen}{rgb}{0,0.6,0} | ||
\definecolor{gray}{rgb}{0.5,0.5,0.5} | ||
\definecolor{mauve}{rgb}{0.58,0,0.82} | ||
\lstset{frame=tb, | ||
language=Haskell, | ||
aboveskip=3mm, | ||
belowskip=3mm, | ||
showstringspaces=false, | ||
columns=flexible, | ||
basicstyle={\small\ttfamily}, | ||
numbers=none, | ||
numberstyle=\tiny\color{gray}, | ||
keywordstyle=\color{blue}, | ||
commentstyle=\color{dkgreen}, | ||
stringstyle=\color{mauve}, | ||
breaklines=true, | ||
breakatwhitespace=true, | ||
escapeinside={(*}{*)}, % if you want to add LaTeX within your code | ||
tabsize=4 | ||
} | ||
|
||
\title{Overview of the Contua programming language.} | ||
\author{Jacek Olczyk} | ||
\date{Feb 2019} | ||
|
||
\begin{document} | ||
\maketitle | ||
\section{Introduction} | ||
\paragraph{Contua} is a strongly typed functional programming language. It is conceived on a basis of the idea that the language should force the programmer to write all the functions continuation-style. It is not immediately clear what measures needs to be taken to disallow regular functions. I needed to come up with some conventions to achieve that result. | ||
\section{The syntax} | ||
Since the language will be pretty complicated in the 'backend', I tried to keep the syntax as simple as possible. In this grammar I omitted the whitespace rules. | ||
\begin{align*} | ||
% program | ||
\texttt{program} =\ & \texttt{\{ \color{gray}typeDecl \color{black} \}, \{ \color{red}funDecl \color{black} \}}\\ | ||
% funDecl | ||
\texttt{\color{red}funDecl\color{black}} =\ & \texttt{\color{ForestGreen}type\color{black}, '::', id, \{ id \}, "=", \color{RoyalPurple}expr\color{black}}\\ | ||
% typeDecl | ||
\texttt{\color{gray}typeDecl\color{black}} =\ &\texttt{\color{blue}'type'\color{black}, ID, \{ id \}, "=", \color{RubineRed}typeCtor\color{black}, \{ "|", \color{RubineRed}typeCtor \color{black} \}}\\ | ||
% type | ||
\texttt{\color{ForestGreen}type\color{black}} =\ &\texttt{\color{CadetBlue}basicType \color{black} | (\color{ForestGreen}type\color{black}, \{ '->', \color{ForestGreen}type \color{black} \}) | "(", \color{ForestGreen}type\color{black}, ")"}\\ | ||
% basicType | ||
\texttt{\color{CadetBlue}basicType} =\ & \texttt{\color{RubineRed}typeCtor \color{black}| id | "[", id, "]"}\\ | ||
% typeCtor | ||
\texttt{\color{RubineRed}typeCtor\color{black}} =\ & \texttt{ID, \{ \color{ForestGreen}type \color{black} \}}\\ | ||
% function | ||
% \texttt{\color{brown}function\color{black}} =\ & \texttt{}\\ | ||
% expr | ||
\texttt{\color{RoyalPurple}expr\color{black}} =\ & \texttt{ | ||
% variables | ||
id | ||
% type ctors | ||
| ID | ||
% + | ||
| \color{RoyalPurple}expr\color{black}, "+", \color{RoyalPurple}expr \color{black} | ||
% - | ||
| \color{RoyalPurple}expr\color{black}, "-", \color{RoyalPurple}expr \color{black} | ||
% * | ||
| \color{RoyalPurple}expr\color{black}, "*", \color{RoyalPurple}expr \color{black} | ||
% - unary | ||
| "-", \color{RoyalPurple}expr \color{black} | ||
|}\\ | ||
&\texttt{ | ||
% () | ||
| "(", \color{RoyalPurple}expr\color{black}, ")" | ||
% application | ||
| \color{RoyalPurple}expr\color{black}, \color{RoyalPurple}expr \color{black} | ||
% lambda | ||
| \color{blue}'fn'\color{black}, \{ id \}, ".", \color{RoyalPurple}expr \color{black} | ||
% listExpr | ||
| \color{RawSienna}listExpr \color{black} | ||
|}\\ | ||
&\texttt{ | ||
% where | ||
| \color{RoyalPurple}expr\color{black}, \color{blue}'where'\color{black}, \color{red} funDecl\color{black}, \{ \color{blue}'and'\color{black}, \color{red}funDecl \color{black} \} | ||
% let in | ||
| \color{blue}'let'\color{black}, \color{red}funDecl\color{black}, \color{blue}'in'\color{black}, \color{RoyalPurple}expr \color{black} | ||
|}\\ | ||
&\texttt{ | ||
% match | ||
| \color{blue}'match'\color{black}, \color{RoyalPurple}expr\color{black}, \color{blue}'with'\color{black}, \{ "|", \color{RoyalPurple}expr\color{black}, '=>', \color{RoyalPurple}expr \color{black} \} | ||
|}\\ | ||
&\texttt{ | ||
% if then else | ||
| \color{blue}'if'\color{black}, \color{Goldenrod}bexpr\color{black}, \color{blue}'then'\color{black}, \color{RoyalPurple}expr\color{black}, \color{blue}'else'\color{black}, \color{RoyalPurple}expr\color{black} | ||
}\\ | ||
% bexpr | ||
\texttt{\color{Goldenrod}bexpr\color{black}} =\ &\texttt{ | ||
% boolean variable | ||
id | ||
% conjunction | ||
| \color{Goldenrod}bexpr\color{black}, \color{blue}'and'\color{black}, \color{Goldenrod}bexpr \color{black} | ||
% disjunction | ||
| \color{Goldenrod}bexpr\color{black}, \color{blue} 'or'\color{black}, \color{Goldenrod}bexpr \color{black} | ||
% negation | ||
| \color{blue} 'or'\color{black}, \color{Goldenrod}bexpr \color{black} | ||
% less | ||
| \color{RoyalPurple}expr\color{black}, '<=', \color{RoyalPurple}expr\color{black} | ||
}\\ | ||
% listExpr | ||
\texttt{\color{RawSienna}listExpr\color{black}} =\ &\texttt{ | ||
% list literal | ||
[\color{RoyalPurple}expr\color{black}, \{",", \color{RoyalPurple}expr \color{black}\}] | ||
% head/tail | ||
| \color{RoyalPurple} expr\color{black}, ":", \color{RawSienna}listExpr \color{black} | ||
% concatenation | ||
| \color{RawSienna}listExpr\color{black}, "++", \color{RawSienna}listExpr \color{black} | ||
} | ||
\end{align*} | ||
\section{Forcing continuation style} | ||
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Contua | ||
version: 0.1.0.0 | ||
github: "Joald/Contua" | ||
license: BSD3 | ||
author: "Jacek Olczyk" | ||
maintainer: "[email protected]" | ||
copyright: "2019 Jacek Olczyk" | ||
|
||
extra-source-files: | ||
- README.md | ||
- ChangeLog.md | ||
|
||
# Metadata used when publishing your package | ||
# synopsis: Short description of your package | ||
# category: Web | ||
|
||
# To avoid duplicated efforts in documentation and dealing with the | ||
# complications of embedding Haddock markup inside cabal files, it is | ||
# common to point users to the README.md file. | ||
description: Please see the README on GitHub at <https://github.com/Joald/Contua#readme> | ||
|
||
dependencies: | ||
- base >= 4.7 && < 5 | ||
- megaparsec >= 7 | ||
- mtl | ||
- text | ||
- parser-combinators | ||
- hspec >= 2.6.1 | ||
- hspec-megaparsec | ||
|
||
library: | ||
source-dirs: src | ||
|
||
executables: | ||
Contua-exe: | ||
main: Main.hs | ||
source-dirs: app | ||
ghc-options: | ||
- -threaded | ||
- -rtsopts | ||
- -with-rtsopts=-N | ||
dependencies: | ||
- Contua | ||
|
||
tests: | ||
Contua-test: | ||
main: Spec.hs | ||
source-dirs: test | ||
ghc-options: | ||
- -threaded | ||
- -rtsopts | ||
- -with-rtsopts=-N | ||
dependencies: | ||
- Contua |
Oops, something went wrong.