Skip to content

Commit e368ee6

Browse files
committed
Initial sketleton
0 parents  commit e368ee6

15 files changed

+308
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*~
2+
*.swp
3+
tarballs/
4+
.stack-work/

ChangeLog.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog for haskell-lox
2+
3+
## Unreleased changes

LICENSE

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright Author name here (c) 2019
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Author name here nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE 2021 Author name here HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 2021 Author name here
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# haskell-lox
2+
3+
## Execute
4+
5+
* Run `stack exec -- haskell-lox-exe` to see "We're inside the application!"
6+
* With `stack exec -- haskell-lox-exe --verbose` you will see the same message, with more logging.
7+
8+
## Run tests
9+
10+
`stack test`

Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

app/.#Main.hs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
devanla@is-devanla-01.30804:1629298645

app/Main.hs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
module Main (main) where
4+
5+
import Import
6+
import Run
7+
import RIO.Process
8+
import Options.Applicative.Simple
9+
import qualified Paths_haskell_lox
10+
11+
main :: IO ()
12+
main = do
13+
(options, ()) <- simpleOptions
14+
$(simpleVersion Paths_haskell_lox.version)
15+
"Header for command line arguments"
16+
"Program description, also for command line arguments"
17+
(Options
18+
<$> switch ( long "verbose"
19+
<> short 'v'
20+
<> help "Verbose output?"
21+
)
22+
)
23+
empty
24+
lo <- logOptionsHandle stderr (optionsVerbose options)
25+
pc <- mkDefaultProcessContext
26+
withLogFunc lo $ \lf ->
27+
let app = App
28+
{ appLogFunc = lf
29+
, appProcessContext = pc
30+
, appOptions = options
31+
}
32+
in runRIO app run

package.yaml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: haskell-lox
2+
version: 0.1.0.0
3+
github: githubuser/haskell-lox
4+
license: BSD3
5+
author: Author name here
6+
maintainer: [email protected]
7+
copyright: 2021 Author name here
8+
9+
extra-source-files:
10+
- README.md
11+
- ChangeLog.md
12+
13+
# Metadata used when publishing your package
14+
# synopsis: Short description of your package
15+
# category: Web
16+
17+
# To avoid duplicated efforts in documentation and dealing with the
18+
# complications of embedding Haddock markup inside cabal files, it is
19+
# common to point users to the README.md file.
20+
description: Please see the README on Github at <https://github.com/githubuser/haskell-lox#readme>
21+
22+
dependencies:
23+
- base >= 4.11 && < 10
24+
- rio >= 0.1.12.0
25+
- array >= 0.5.4.0
26+
- text >= 1.2.4.1
27+
- directory >= 1.3.6.0
28+
- filepath >= 1.4.2.1
29+
- regex-tdfa >= 1.3.1
30+
- utf8-string >= 1
31+
- bytestring >= 0.10.12.0
32+
- optparse-simple >= 0.1.1.3
33+
34+
35+
ghc-options:
36+
- -Wall
37+
- -Wcompat
38+
- -Widentities
39+
- -Wincomplete-record-updates
40+
- -Wincomplete-uni-patterns
41+
- -Wpartial-fields
42+
- -Wredundant-constraints
43+
44+
library:
45+
source-dirs: src
46+
47+
executables:
48+
haskell-lox-exe:
49+
main: Main.hs
50+
source-dirs: app
51+
dependencies:
52+
- haskell-lox
53+
- optparse-simple
54+
55+
ghc-options:
56+
- -threaded
57+
- -rtsopts
58+
- -with-rtsopts=-N
59+
60+
tests:
61+
haskell-lox-test-1:
62+
main: test_lexer.hs
63+
source-dirs: test
64+
dependencies:
65+
- haskell-lox
66+
- tasty
67+
- HUnit
68+
- tasty-hunit
69+
- hspec
70+
- tasty
71+
72+
ghc-options:
73+
- -threaded
74+
- -rtsopts
75+
- -with-rtsopts=-N

src/Import.hs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
module Import
3+
( module RIO
4+
, module Types
5+
) where
6+
7+
import RIO
8+
import Types

src/Run.hs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
module Run (run) where
4+
5+
import Import
6+
7+
run :: RIO App ()
8+
run = do
9+
logInfo "We're inside the application!"

src/Types.hs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
module Types where
3+
4+
import RIO
5+
import RIO.Process
6+
7+
-- | Command line arguments
8+
data Options = Options
9+
{ optionsVerbose :: !Bool
10+
}
11+
12+
data App = App
13+
{ appLogFunc :: !LogFunc
14+
, appProcessContext :: !ProcessContext
15+
, appOptions :: !Options
16+
-- Add other app-specific configuration information here
17+
}
18+
19+
instance HasLogFunc App where
20+
logFuncL = lens appLogFunc (\x y -> x { appLogFunc = y })
21+
instance HasProcessContext App where
22+
processContextL = lens appProcessContext (\x y -> x { appProcessContext = y })

src/Util.hs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
-- | Silly utility module, used to demonstrate how to write a test
3+
-- case.
4+
module Util
5+
( plus2
6+
) where
7+
8+
import RIO
9+
10+
plus2 :: Int -> Int
11+
plus2 = (+ 2)

stack.yaml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This file was automatically generated by 'stack init'
2+
#
3+
# Some commonly used options have been documented as comments in this file.
4+
# For advanced use and comprehensive documentation of the format, please see:
5+
# https://docs.haskellstack.org/en/stable/yaml_configuration/
6+
7+
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8+
# A snapshot resolver dictates the compiler version and the set of packages
9+
# to be used for project dependencies. For example:
10+
#
11+
# resolver: lts-3.5
12+
# resolver: nightly-2015-09-21
13+
# resolver: ghc-7.10.2
14+
#
15+
# The location of a snapshot can be provided as a file or url. Stack assumes
16+
# a snapshot provided as a file might change, whereas a url resource does not.
17+
#
18+
# resolver: ./custom-snapshot.yaml
19+
# resolver: https://example.com/snapshots/2018-01-01.yaml
20+
resolver:
21+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/7.yaml
22+
23+
# User packages to be built.
24+
# Various formats can be used as shown in the example below.
25+
#
26+
# packages:
27+
# - some-directory
28+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
29+
# subdirs:
30+
# - auto-update
31+
# - wai
32+
packages:
33+
- .
34+
# Dependency packages to be pulled from upstream that are not in the resolver.
35+
# These entries can reference officially published versions as well as
36+
# forks / in-progress versions pinned to a git hash. For example:
37+
#
38+
# extra-deps:
39+
# - acme-missiles-0.3
40+
# - git: https://github.com/commercialhaskell/stack.git
41+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
42+
#
43+
# extra-deps: []
44+
45+
# Override default flag values for local packages and extra-deps
46+
# flags: {}
47+
48+
# Extra package databases containing global packages
49+
# extra-package-dbs: []
50+
51+
# Control whether we use the GHC we find on the path
52+
# system-ghc: true
53+
#
54+
# Require a specific version of stack, using version ranges
55+
# require-stack-version: -any # Default
56+
# require-stack-version: ">=2.5"
57+
#
58+
# Override the architecture used by stack, especially useful on Windows
59+
# arch: i386
60+
# arch: x86_64
61+
#
62+
# Extra directories used by stack for building
63+
# extra-include-dirs: [/path/to/dir]
64+
# extra-lib-dirs: [/path/to/dir]
65+
#
66+
# Allow a newer minor version of GHC than the snapshot specifies
67+
# compiler-check: newer-minor

test/UtilSpec.hs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
module UtilSpec (spec) where
3+
4+
import Import
5+
import Util
6+
import Test.Hspec
7+
import Test.Hspec.QuickCheck
8+
9+
spec :: Spec
10+
spec = do
11+
describe "plus2" $ do
12+
it "basic check" $ plus2 0 `shouldBe` 2
13+
it "overflow" $ plus2 maxBound `shouldBe` minBound + 1
14+
prop "minus 2" $ \i -> plus2 i - 2 `shouldBe` i

test/test_lexer.hs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import RIO
2+
import System.IO
3+
import qualified RIO.Text as T
4+
import qualified Data.Text as T
5+
import qualified Data.List as L
6+
import Prelude (print, read)
7+
import Test.Tasty
8+
import Test.Tasty.HUnit
9+
import Text.Regex.TDFA
10+
import Data.Array
11+
12+
import System.FilePath
13+
import System.Directory (listDirectory)
14+
15+
16+
test1 = testCase "test" $ do
17+
1 @?= 1
18+
19+
main = do
20+
defaultMain $ testGroup "tokenizer_tests_example_1" [test1]

0 commit comments

Comments
 (0)