Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lthms committed Feb 27, 2016
0 parents commit 4bece94
Show file tree
Hide file tree
Showing 10 changed files with 620 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.stack-work/
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: haskell

sudo: false

cache:
directories:
- $HOME/.stack

before_install:
- mkdir -p ~/.local/bin
- export PATH=~/.local/bin:$PATH
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
- chmod a+x ~/.local/bin/stack

install:
- stack install cabal-install --install-ghc

script:
- stack setup
- stack build
- stack test

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Iky

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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
34 changes: 34 additions & 0 deletions ogmarkup.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: ogmarkup
version: 0.1.0.0
synopsis: Language Markup Parser for Ogma
description: Please see README.md
homepage: http://gitlab.com/ogma/ogmarkup
license: MIT
license-file: LICENSE
author: Iky
maintainer: [email protected]
copyright: 2016 Iky
category: Web
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10

library
hs-source-dirs: src
exposed-modules: Ogmarkup.Parser,
Ogmarkup.Ast
build-depends: base >= 4.7 && < 5, parsec == 3.1.9
default-language: Haskell2010

test-suite ogmadown-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base, hspec,
ogmarkup, parsec
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

source-repository head
type: git
location: https://gitlab.com/ogma/ogmarkup
66 changes: 66 additions & 0 deletions src/Ogmarkup/Ast.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module Ogmarkup.Ast (
OgmaText (
Word,
Semicolon,
Colon,
OpenQuote,
CloseQuote,
QuestionMark,
ExclamationMark,
LongDash,
Comma,
Point,
SuspensionPoints
),
OgmaFormat (
Raw,
WeakEmph,
StrongEmph
),
OgmaDialog (Simple,
WithSay
),
OgmaComponent (Teller,
Audible,
Thought
),
OgmaParagraph (Story,
Quote
)
) where

data OgmaText =
Word String
| Semicolon
| Colon
| OpenQuote
| CloseQuote
| QuestionMark
| ExclamationMark
| LongDash
| Comma
| Point
| SuspensionPoints
deriving (Show,Eq)

data OgmaFormat =
Raw [OgmaText]
| WeakEmph [OgmaText]
| StrongEmph [OgmaText]
deriving (Show,Eq)

data OgmaDialog =
Simple [OgmaFormat] String
| WithSay [OgmaFormat] [OgmaFormat] [OgmaFormat] String
deriving (Show,Eq)

data OgmaComponent =
Teller [OgmaFormat]
| Audible OgmaDialog -- String
| Thought OgmaDialog -- String
deriving (Show,Eq)

data OgmaParagraph =
Story [OgmaComponent]
| Quote [[OgmaComponent]] OgmaFormat
deriving (Show,Eq)
137 changes: 137 additions & 0 deletions src/Ogmarkup/Parser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
module Ogmarkup.Parser (
specialchar,
word,
text,
raw,
strongemph,
weakemph,
paragraph,
format,
dialog,
teller,
component,
) where

import Text.ParserCombinators.Parsec
import Ogmarkup.Ast

textmarker :: GenParser Char st ()
textmarker = oneOf "«»—?!;:.," >> return ()

formatmarker :: GenParser Char st ()
formatmarker = oneOf "*|" >> return ()

opendialogmarker :: GenParser Char st ()
opendialogmarker = oneOf "[<" >> return ()

closedialogmarker :: GenParser Char st ()
closedialogmarker = oneOf ">]" >> return ()

dialogmarker :: GenParser Char st ()
dialogmarker = opendialogmarker <|> closedialogmarker

marker :: GenParser Char st ()
marker = (space >> return ()) <|> textmarker <|> formatmarker <|> dialogmarker <|> eof

ogmaLookAhead parser = (lookAhead $ try parser) >> return ()

manyTillEof parser till = manyTill parser (ogmaLookAhead till <|> eof)

many1TillEof parser till = do
notFollowedBy till
ps <- manyTill parser (ogmaLookAhead till <|> eof)

return ps

paragraph :: GenParser Char st OgmaParagraph
paragraph = manyTill component eof >>= return . Story

component :: GenParser Char st OgmaComponent
component = spaces *> (try audible <|> try thought <|> teller) <* spaces

audible :: GenParser Char st OgmaComponent
audible = dialog '[' ']' >>= return . Audible

thought :: GenParser Char st OgmaComponent
thought = dialog '<' '>' >>= return . Thought

teller :: GenParser Char st OgmaComponent
teller = many1TillEof format opendialogmarker >>= return . Teller

dialog :: Char -> Char -> GenParser Char st OgmaDialog
dialog c e = do
char c
d <- many1TillEof format (char e <|> char '|')
try (do
char '|'
i <- many1TillEof format (char '|')
char '|'
spaces
d' <- manyTillEof format (char e)
char e
char '('
a <- many letter
char ')'

return $ WithSay d i d' a) <|> (do
char e
char '('
a <- many letter
char ')'
return $ Simple d a)

format :: GenParser Char st OgmaFormat
format = spaces *> (try strongemph <|> try weakemph <|> raw) <* spaces

weakemph :: GenParser Char st OgmaFormat
weakemph = do
char '*'
t <- many1TillEof text (char '*')
char '*'

return $ WeakEmph t

strongemph :: GenParser Char st OgmaFormat
strongemph = do
string "**"
t <- many1TillEof text (string "**")
string "**"

return $ StrongEmph t

raw :: GenParser Char st OgmaFormat
raw = (many1TillEof text (formatmarker <|> dialogmarker)) >>= return . Raw

text :: GenParser Char st OgmaText
text = spaces *> (specialchar <|> (notFollowedBy marker >> word)) <* spaces

word :: GenParser Char st OgmaText
word = do
w <- many1TillEof anyChar marker
return $ Word w

specialchar :: GenParser Char st OgmaText
specialchar = colon
<|> semicolon
<|> longDash
<|> openQuote
<|> closeQuote
<|> exclamationMark
<|> questionMark
<|> comma
<|> try suspension
<|> point

parseSpecial :: String -> OgmaText -> GenParser Char st OgmaText
parseSpecial s r = string s >> return r

questionMark = parseSpecial "?" QuestionMark
exclamationMark = parseSpecial "!" ExclamationMark
openQuote = parseSpecial "«" OpenQuote
closeQuote = parseSpecial "»" CloseQuote
longDash = parseSpecial "" LongDash
semicolon = parseSpecial ";" Semicolon
colon = parseSpecial ":" Colon
comma = parseSpecial "," Comma
point = parseSpecial "." Point
suspension = string ".." >> many (char '.') >> return SuspensionPoints
35 changes: 35 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration.html

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-5.4

# Local packages, usually specified by relative directory name
packages:
- '.'

# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps: []

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true

# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: >= 1.0.0

# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64

# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]

# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
Loading

0 comments on commit 4bece94

Please sign in to comment.