Skip to content

Commit

Permalink
asv/usv
Browse files Browse the repository at this point in the history
  • Loading branch information
vmchale committed Mar 13, 2024
1 parent 4d8609e commit 821c156
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* Better error messages when a field is out of bounds
* Better error message on empty `|>` (`fold1`)
* Fix parsing bug in curried binary operators
* Add `--usv` command-line flag

# 2.0.3.0

Expand Down
4 changes: 3 additions & 1 deletion src/A.hs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ instance Show C where show=show.pretty
data D a = SetFS T.Text | SetRS T.Text
| FunDecl (Nm a) [Nm a] (E a)
| FlushDecl
| SetAsv | SetOFS T.Text | SetORS T.Text
| SetAsv | SetUsv | SetOFS T.Text | SetORS T.Text
deriving (Functor)

instance Pretty (D a) where
Expand All @@ -386,6 +386,7 @@ instance Pretty (D a) where
pretty (FunDecl n ns e) = "fn" <+> pretty n <> tupled (pretty <$> ns) <+> ":=" <#> indent 2 (pretty e <> ";")
pretty FlushDecl = ":flush;"
pretty SetAsv = ":set asv;"
pretty SetUsv = ":set usv;"
pretty (SetOFS sep) = ":set ofs :=" <+> "'" <> pretty sep <> "';"
pretty (SetORS sep) = ":set ors :=" <+> "'" <> pretty sep <> "';"

Expand All @@ -403,6 +404,7 @@ getS :: Program a -> (Maybe T.Text, Maybe T.Text)
getS (Program ds _) = foldl' go (Nothing, Nothing) ds where
go (_, rs) (SetFS bs) = (Just bs, rs)
go _ SetAsv = (Just "\\x1f", Just "\\x1e")
go _ SetUsv = (Just "",Just "")
go (fs, _) (SetRS bs) = (fs, Just bs)
go next _ = next

Expand Down
2 changes: 1 addition & 1 deletion src/A/I.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lβ e = state (`β` e)

iD :: D T -> RM T ()
iD (FunDecl n [] e) = do {eI <- iE e; modify (bind n eI)}
iD SetFS{} = pure (); iD SetRS{} = pure (); iD SetAsv = pure ()
iD SetFS{} = pure (); iD SetRS{} = pure (); iD SetAsv = pure (); iD SetUsv = pure ()
iD SetORS{} = pure (); iD SetOFS{} = pure (); iD FlushDecl{} = pure ()
iD FunDecl{} = desugar

Expand Down
9 changes: 6 additions & 3 deletions src/L.x
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ tokens :-
if { mkKw KwIf }
then { mkKw KwThen }
else { mkKw KwElse }
asv { mkKw KwAsv }
usv { mkKw KwUsv }
fs { mkRes VarFs }
rs { mkRes VarRs }
Expand Down Expand Up @@ -366,9 +368,8 @@ data Keyword = KwLet
| KwFlush
| KwFn
| KwInclude
| KwIf
| KwThen
| KwElse
| KwIf | KwThen | KwElse
| KwAsv | KwUsv
-- | Reserved/special variables
data Var = VarX
Expand Down Expand Up @@ -404,6 +405,8 @@ instance Pretty Keyword where
pretty KwIf = "if"
pretty KwThen = "then"
pretty KwElse = "else"
pretty KwUsv = "usv"
pretty KwAsv = "asv"
data Builtin = BuiltinIParse
| BuiltinFParse
Expand Down
4 changes: 4 additions & 0 deletions src/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ import Prettyprinter (Pretty (pretty), (<+>))
if { TokKeyword $$ KwIf }
then { TokKeyword $$ KwThen }
else { TokKeyword $$ KwElse }
usv { TokKeyword $$ KwUsv }
asv { TokKeyword $$ KwAsv }

x { TokResVar $$ VarX }
y { TokResVar $$ VarY }
Expand Down Expand Up @@ -216,6 +218,8 @@ D :: { D AlexPosn }
| set rs defEq rr semicolon { SetRS (rr $4) }
| set ofs defEq strLit semicolon { SetOFS (strTok $4) }
| set ors defEq strLit semicolon { SetORS (strTok $4) }
| set asv semicolon { SetAsv }
| set usv semicolon { SetUsv }
| flush semicolon { FlushDecl }
| fn name Args defEq E semicolon { FunDecl $2 $3 $5 }
| fn name defEq E semicolon { FunDecl $2 [] $4 }
Expand Down
1 change: 1 addition & 0 deletions src/Ty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ tyDS s (SetRS bs) = pure (SetRS bs, s)
tyDS s (SetOFS bs) = pure (SetOFS bs, s)
tyDS s (SetORS bs) = pure (SetORS bs, s)
tyDS s SetAsv = pure (SetAsv, s)
tyDS s SetUsv = pure (SetUsv, s)
tyDS s FlushDecl = pure (FlushDecl, s)
tyDS s (FunDecl n@(Nm _ (U i) _) [] e) = do
(e', s') <- tyES s e
Expand Down
2 changes: 1 addition & 1 deletion vscode/syntaxes/jacinda.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ in { fileTypes = [ "jac" ]
}
, TextMate.MatchRe
{ match =
"(splitc|sprintf|option|match|captures|fp|nf|rs|fs|ors|ofs|ix|substr|split|min|max|Some|None|mapMaybe|dedup|filter|fold|fold1|scan|dedupOn|catMaybes)"
"(splitc|sprintf|option|match|captures|fp|nf|rs|fs|ors|ofs|asv|usv|ix|substr|split|min|max|Some|None|mapMaybe|dedup|filter|fold|fold1|scan|dedupOn|catMaybes)"
, name = "constant.language"
}
, TextMate.MatchRe
Expand Down
2 changes: 1 addition & 1 deletion vscode/syntaxes/jacinda.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"name": "keyword"
},
{
"match": "(splitc|sprintf|option|match|captures|fp|nf|rs|fs|ors|ofs|ix|substr|split|min|max|Some|None|mapMaybe|dedup|filter|fold|fold1|scan|dedupOn|catMaybes)",
"match": "(splitc|sprintf|option|match|captures|fp|nf|rs|fs|ors|ofs|asv|usv|ix|substr|split|min|max|Some|None|mapMaybe|dedup|filter|fold|fold1|scan|dedupOn|catMaybes)",
"name": "constant.language"
},
{
Expand Down

0 comments on commit 821c156

Please sign in to comment.