guards less strict, return fontifies until end, example2 added

This commit is contained in:
Armin Friedl 2016-08-15 19:59:52 +02:00
parent ce9e1b37c1
commit 76472ca357
5 changed files with 46 additions and 9 deletions

View file

@ -4,7 +4,10 @@ all:
cabal build cabal build
test: all test: all
dist/build/hedit/hedit test dist/build/hedit/hedit examples/example1
test2: all
dist/build/hedit/hedit examples/example2
clean: clean:
rm -fR dist/ rm -fR dist/

View file

@ -1,4 +1,3 @@
{ {
max = { % number a, number b, number c -> number or "error" max = { % number a, number b, number c -> number or "error"
[ c = "" : c = "0"; ] % by default use "0" if c not specified [ c = "" : c = "0"; ] % by default use "0" if c not specified

24
examples/example2 Normal file
View file

@ -0,0 +1,24 @@
{
error = "0";
fact = { % number num -> number; set error if something is wrong
continue = {} + ("test 1 -ge " + num).syscall;
[ continue = "0" :
[ {} + ("test 0 = " + num).syscall # "0" :
*error = "1";
]
^ "1";
]
nextnum = { in = *num + "-1"; } + "bc -lq".iosyscall;
[ nextnum.result = "0" :
result = { in = { num = **nextnum.out; } + **fact + "*" + *nextnum.out; } + "bc -lq".iosyscall;
[ result.result = "0" :
^ result.out;
]
]
*error = "2";
^ "0";
}
value = { num = "5"; } + fact;
[ error = "0" : { in = "result: " + *value; } + "echo".iosyscall; ]
[ error # "0" : { in = "error #" + *error; } + "echo".iosyscall; ]
}

View file

@ -69,7 +69,8 @@ executable hedit
directory, directory,
text-zipper, text-zipper,
array, array,
regex-tdfa regex-tdfa,
containers
-- Directories containing source files. -- Directories containing source files.
hs-source-dirs: src, src/App hs-source-dirs: src, src/App

View file

@ -1,3 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
module Fontifier (fontMap, fontify, Fontification(..)) where module Fontifier (fontMap, fontify, Fontification(..)) where
{---- Imports ----} {---- Imports ----}
@ -11,7 +13,9 @@ import qualified Text.Regex.TDFA as Tdfa
---- Various ---- ---- Various ----
import Data.Array import Data.Array
import Data.String import Data.String
import Lens.Micro ((^.), _1, _2) import Lens.Micro ((%~), (&), (.~), (^.))
import Lens.Micro.TH (makeLenses)
import qualified Data.Map as Map
{---- Type Definitions ----} {---- Type Definitions ----}
@ -28,6 +32,10 @@ type Slices = [Slice]
type MatchResult = [Tdfa.MatchArray] type MatchResult = [Tdfa.MatchArray]
type CheckString = String type CheckString = String
type Regex = Tdfa.Regex type Regex = Tdfa.Regex
data BlockSlice = BS Slice String
data AccessSlice = AS Slice String
type BlockSlices = [BlockSlice]
type AccessSlices = [AccessSlice]
{---- Infix Operators ----} {---- Infix Operators ----}
@ -61,11 +69,13 @@ fontMap = [ (attrName "assignment" , fg Vty.blue)
, (attrName "err_brackets" , bg Vty.red) -- unbalanced brackets , (attrName "err_brackets" , bg Vty.red) -- unbalanced brackets
, (attrName "err_quotes" , Vty.withStyle (fg Vty.red) Vty.underline) -- unbalanced quotes , (attrName "err_quotes" , Vty.withStyle (fg Vty.red) Vty.underline) -- unbalanced quotes
, (attrName "err_unterm" , Vty.withStyle (fg Vty.red) Vty.underline) -- missing ; , (attrName "err_unterm" , Vty.withStyle (fg Vty.red) Vty.underline) -- missing ;
, (attrName "err_read" , Vty.withStyle (fg Vty.red) Vty.underline) -- invalid read
, (attrName "err_write" , Vty.withStyle (fg Vty.red) Vty.underline) -- invalid write
] ]
fontify :: CheckString -> Fontifications fontify :: CheckString -> Fontifications
fontify = concatApply [ assignments, returns fontify = concatApply [ assignments, strings
, strings, guards, comments , returns, guards, comments
, mismatchedBrackets , mismatchedBrackets
, mismatchedQuotes] , mismatchedQuotes]
-- , untermStrings -- , untermStrings
@ -86,9 +96,9 @@ concatApply (f:fs) s = f s ++ concatApply fs s
comments = slicesToFT §: "comment" §. matchAll §~ "%.*" comments = slicesToFT §: "comment" §. matchAll §~ "%.*"
assignments = slicesToFT §: "assignment" §. matchGrpStripCmts 1 §~ "(\\**[[:word:]]+)[[:blank:]]*=" assignments = slicesToFT §: "assignment" §. matchGrpStripCmts 1 §~ "(\\**[[:word:]]+)[[:blank:]]*="
returns = slicesToFT §: "return" §. matchStripCmts §~ "[[:space:]]\\^" returns = slicesToFT §: "return" §. matchGrpStripCmts 1 §~ "([[:space:]]\\^.*);"
strings = slicesToFT §: "string" §. matchStripCmts §~ "\"[^%\"]*\"" strings = slicesToFT §: "string" §. matchStripCmts §~ "\"[^%\"]*\""
guards = slicesToFT §: "guard" §. matchGrpStripCmts 1 §~ "\\[(.+):.+\\]" guards = slicesToFT §: "guard" §. matchGrpStripCmts 1 §~ "\\[([^:]+):"
{- Custom/Function-Based -} {- Custom/Function-Based -}