Skip to content

Commit

Permalink
initial commit: restart project
Browse files Browse the repository at this point in the history
  • Loading branch information
0rphee committed Dec 23, 2024
0 parents commit e0a8b54
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Set update schedule for GitHub Actions
version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI

# Trigger the workflow on push or pull request, but only for the main branch
on:
pull_request:
push:
workflow_dispatch:

jobs:
generate-matrix:
name: "Generate matrix from cabal"
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
runs-on: ubuntu-latest
steps:
- name: Extract the tested GHC versions
id: set-matrix
uses: kleidukos/get-tested@0.1.8.1
with:
cabal-file: xolsh.cabal
ubuntu-version: latest
macos-version: latest
windows-version: latest
version: 0.1.7.0

tests:
name: ${{ matrix.ghc }} on ${{ matrix.os }}
needs: generate-matrix
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Checkout base repo
uses: actions/checkout@v4

- name: Set up Haskell
id: setup-haskell
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: "latest"

- name: Configure
run: |
cabal configure --enable-tests
# Generate dist-newstyle/cache/plan.json for the cache key.
cabal build --dry-run
- name: Freeze
run: cabal freeze

- name: Cache ~/.cabal/store
uses: actions/cache@v4
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dist-newstyle/cache/plan.json') }}

- name: Build
run: cabal build all

- name: Test
run: cabal test all --test-show-details=direct
41 changes: 41 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Linting

on:
pull_request:
push:
branches: ["main"]

jobs:
fourmolu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: haskell-actions/run-fourmolu@v10
with:
pattern: |
src
app
test
bench
hlint:
runs-on: ubuntu-latest
permissions:
security-events: write # Needed to upload results to GitHub code scanning.
steps:
- uses: actions/checkout@v4

- name: 'Set up HLint'
uses: haskell-actions/hlint-setup@v2
with:
version: '3.8'

- name: 'Run HLint Scan'
uses: haskell-actions/hlint-scan@v1

- name: 'Run HLint'
uses: haskell-actions/hlint-run@v2
with:
path: '["app"]'
fail-on: warning
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Created by https://www.toptal.com/developers/gitignore/api/haskell
# Edit at https://www.toptal.com/developers/gitignore?templates=haskell

### Haskell ###
dist
dist-*
cabal-dev
*.o
*.hi
*.hie
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*

# End of https://www.toptal.com/developers/gitignore/api/haskell
*~
10 changes: 10 additions & 0 deletions .helix/languages.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[language-server.haskell-language-server.config.haskell]
"formattingProvider" = "fourmolu"

[[language]]
name = "haskell"
auto-format = true

[[language]]
name = "cabal"
auto-format = true
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog for `xolsh`

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the
[Haskell Package Versioning Policy](https://pvp.haskell.org/).

## Unreleased

## 0.1.0.0 - YYYY-MM-DD
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright 0rphee (c) 2023

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 0rphee 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.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# xolsh

A work-in-progress implementation of jlox from the [Crafting Interpreters Book](https://craftinginterpreters.com/).
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
37 changes: 37 additions & 0 deletions app/CmdlineOptions.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module CmdlineOptions
( options
, Options (..)
, execParser
)
where

import Data.ByteString.Char8 as B
import Options.Applicative

newtype Options = Options
{ sourceCodeFile :: Maybe ByteString
}

options :: ParserInfo Options
options =
info
(opts <**> helper)
( fullDesc
<> header "xolsh - a lox interpreter written in haskell "
<> footer
"still a work in progress, source code here: https://codeberg.org/0rphee/xolsh, \
\following the Crafting Interpreters book: https://craftinginterpreters.com/"
<> failureCode 64
)

opts :: Parser Options
opts =
Options
<$> optional
( strArgument
( metavar "FILENAME"
<> help "Input file"
<> action "directory"
<> action "file"
)
)
4 changes: 4 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main (main) where

main :: IO ()
main = putStrLn "Hello world"
25 changes: 25 additions & 0 deletions bench/Bench.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Main (main) where

import Control.Applicative
import Data.Vector as V
import Expr
import Parser qualified as P
import Test.Tasty.Bench
import Token

toks :: Vector Token
toks =
V.fromList $
badPosTok
<$> [FALSE, TRUE, NIL, STRING "aa", NUMBER 56.0]

bParsePrimaryExpr :: Vector Token -> [PrimaryExpr]
bParsePrimaryExpr t = case P.runParser (many P.parsePrimary) t of
P.OK !xs _ -> xs
_ -> error "ooops"

main :: IO ()
main =
defaultMain
[ bench "parsePrimary :: Parser e PrimaryExpr" $ nf bParsePrimaryExpr toks
]
3 changes: 3 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: ./

tests: True
16 changes: 16 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
indentation: 2 # any non-negative integer (default 4)
column-limit: 80 # (default none), or any non-negative integer
function-arrows: leading # (default trailing), leading, leading-args
comma-style: leading # (default leading), trailing
import-export-style: leading # leading, trailing, (default diff-friendly)
indent-wheres: true # true, (default false)
record-brace-space: true # true, (default false)
newlines-between-decls: 1 # any integer (default 1)
haddock-style: multi-line # single-line, (default multi-line), multi-line-compact
haddock-style-module: # (default same as haddock-style)
let-style: inline # inline, newline, (default auto), mixed
in-style: right-align # left-align, (default right-align), no-space
single-constraint-parens: never # (default always), never, auto
unicode: never # always, detect, (default never)
respectful: false # (default true), false
fixities: [] # list of strings (default [])
4 changes: 4 additions & 0 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main () where

main :: IO ()
main = putStrLn "Test suite not yet implemented"
1 change: 1 addition & 0 deletions test/test.lox
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
() / {} name while for true false identifier 123.01 123. tree 123
Loading

0 comments on commit e0a8b54

Please sign in to comment.