{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UnboxedTuples #-}
module Parsers.Nandlang where

import Data.Bool
import Data.Char (isSpace, isAlpha, isAlphaNum)
import Data.Char (Char)
import Data.Eq (Eq(..))
import Data.Ord (Ord(..))
import Data.String (String)
import qualified Data.Set as Set
import qualified Data.Text as Text

import qualified Symantic.Parser as P
import qualified Symantic.Lang as Prod

type Parser a = P.Parser Text.Text a

nandIdentStart :: Char -> Bool
nandIdentStart :: Char -> Bool
nandIdentStart Char
c = Char -> Bool
isAlpha Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_'

nandIdentLetter :: Char -> Bool
nandIdentLetter :: Char -> Bool
nandIdentLetter Char
c = Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_'

nandUnreservedName :: String -> Bool
nandUnreservedName :: String -> Bool
nandUnreservedName = \String
s -> Bool -> Bool
not (String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member String
s Set String
keys)
  where
  keys :: Set String
keys = [String] -> Set String
forall a. Ord a => [a] -> Set a
Set.fromList [String
"if", String
"else", String
"while", String
"function", String
"var"]

nandStringLetter :: Char -> Bool
nandStringLetter :: Char -> Bool
nandStringLetter Char
c = (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'"') Bool -> Bool -> Bool
&& (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\\') Bool -> Bool -> Bool
&& (Char
c Char -> Char -> Bool
forall a. Ord a => a -> a -> Bool
> Char
'\026')

grammar :: forall repr.
  P.Grammarable Char repr =>
  repr ()
grammar :: forall (repr :: * -> *). Grammarable Char repr => repr ()
grammar = repr ()
whitespace repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombFoldable repr) =>
repr a -> repr ()
P.skipMany repr ()
funcdef repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr a
P.<* repr ()
forall (repr :: * -> *). CombLookable repr => repr ()
P.eof
  where
  literal :: repr ()
  literal :: repr ()
literal = repr ()
bit repr () -> repr () -> repr ()
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> repr ()
charLit
  bit :: repr ()
  bit :: repr ()
bit = (Char -> repr Char
forall (repr :: * -> *).
(CombApplicable repr, CombSatisfiable Char repr) =>
Char -> repr Char
P.char Char
'0' repr Char -> repr Char -> repr Char
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> Char -> repr Char
forall (repr :: * -> *).
(CombApplicable repr, CombSatisfiable Char repr) =>
Char -> repr Char
P.char Char
'1') repr Char -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
whitespace
  charLit :: repr ()
  charLit :: repr ()
charLit = repr Char -> repr Char -> repr () -> repr ()
forall (repr :: * -> *) o c a.
CombApplicable repr =>
repr o -> repr c -> repr a -> repr a
P.between (Char -> repr Char
forall (repr :: * -> *).
(CombApplicable repr, CombSatisfiable Char repr) =>
Char -> repr Char
P.char Char
'\'') (Char -> repr Char
symbol Char
'\'') repr ()
charChar
  charChar :: repr ()
  charChar :: repr ()
charChar = repr Char -> repr ()
forall (repr :: * -> *) a. CombApplicable repr => repr a -> repr ()
P.void (Production (Char -> Bool) -> repr Char
forall tok (repr :: * -> *).
CombSatisfiable tok repr =>
Production (tok -> Bool) -> repr tok
P.satisfy
    ((Char -> Bool) -> CodeQ (Char -> Bool) -> Production (Char -> Bool)
forall a. a -> CodeQ a -> Production a
P.production Char -> Bool
nandStringLetter [||nandStringLetter||])) repr () -> repr () -> repr ()
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> repr ()
esc
  esc :: repr ()
  esc :: repr ()
esc = Char -> repr Char
forall (repr :: * -> *).
(CombApplicable repr, CombSatisfiable Char repr) =>
Char -> repr Char
P.char Char
'\\' repr Char -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr Char -> repr ()
forall (repr :: * -> *) a. CombApplicable repr => repr a -> repr ()
P.void (String -> repr Char
forall tok (repr :: * -> *).
(Ord tok, Show tok, Typeable tok, Lift tok, NFData tok,
 CombSatisfiable tok repr) =>
[tok] -> repr tok
P.oneOf String
"0tnvfr")
  expr :: repr ()
  expr :: repr ()
expr = repr ()
nandexpr repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombFoldable repr) =>
repr a -> repr ()
P.skipMany (Char -> repr Char
symbol Char
'!' repr Char -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
nandexpr)
  nandexpr :: repr ()
  nandexpr :: repr ()
nandexpr = repr ()
literal repr () -> repr () -> repr ()
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> repr ()
funccallOrVar
  funccallOrVar :: repr ()
  funccallOrVar :: repr ()
funccallOrVar = repr ()
identifier repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombAlternable repr) =>
repr a -> repr ()
P.optional (repr () -> repr ()
forall a. repr a -> repr a
parens repr ()
exprlist repr () -> repr () -> repr ()
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> repr ()
index)
  identifier :: repr ()
  identifier :: repr ()
identifier = repr () -> repr ()
forall (repr :: * -> *) a. CombAlternable repr => repr a -> repr a
P.try (repr Char
forall {repr :: * -> *}. CombSatisfiable Char repr => repr Char
identStart repr Char -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr Char -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombFoldable repr) =>
repr a -> repr ()
P.skipMany repr Char
forall {repr :: * -> *}. CombSatisfiable Char repr => repr Char
identLetter) repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
whitespace
  identStart :: repr Char
identStart = Production (Char -> Bool) -> repr Char
forall tok (repr :: * -> *).
CombSatisfiable tok repr =>
Production (tok -> Bool) -> repr tok
P.satisfy
    ((Char -> Bool) -> CodeQ (Char -> Bool) -> Production (Char -> Bool)
forall a. a -> CodeQ a -> Production a
P.production Char -> Bool
nandIdentStart [||nandIdentStart||])

  exprlist :: repr ()
exprlist  = repr () -> repr ()
forall a. repr a -> repr ()
commaSep repr ()
expr
  exprlist1 :: repr ()
exprlist1 = repr () -> repr ()
forall a. repr a -> repr ()
commaSep1 repr ()
expr
  varlist :: repr ()
varlist   = repr () -> repr ()
forall a. repr a -> repr ()
commaSep repr ()
variable
  varlist1 :: repr ()
varlist1  = repr () -> repr ()
forall a. repr a -> repr ()
commaSep1 repr ()
variable
  variable :: repr ()
  variable :: repr ()
variable = repr ()
identifier repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombAlternable repr) =>
repr a -> repr ()
P.optional repr ()
index
  index :: repr ()
  index :: repr ()
index = repr () -> repr ()
forall a. repr a -> repr a
brackets repr ()
nat
  nat :: repr ()
  nat :: repr ()
nat = repr ()
decimal
  decimal :: repr ()
  decimal :: repr ()
decimal = repr Char -> repr ()
forall a. repr a -> repr ()
number (String -> repr Char
forall tok (repr :: * -> *).
(Ord tok, Show tok, Typeable tok, Lift tok, NFData tok,
 CombSatisfiable tok repr) =>
[tok] -> repr tok
P.oneOf [Char
'0'..Char
'9'])
  number :: repr a -> repr ()
  number :: forall a. repr a -> repr ()
number repr a
digit = repr a -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombFoldable repr) =>
repr a -> repr ()
P.skipSome repr a
digit

  funcdef :: repr ()
funcdef = String -> repr ()
keyword String
"function" repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
identifier repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr () -> repr ()
forall a. repr a -> repr a
parens repr ()
funcparam repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
block
  funcparam :: repr ()
funcparam = repr ()
varlist repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombAlternable repr) =>
repr a -> repr ()
P.optional (Char -> repr Char
symbol Char
':' repr Char -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
varlist)
  block :: repr ()
block = repr () -> repr ()
forall a. repr a -> repr a
braces (repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombFoldable repr) =>
repr a -> repr ()
P.skipMany repr ()
statement)
  statement :: repr ()
statement =
    repr ()
ifstmt repr () -> repr () -> repr ()
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> repr ()
whilestmt repr () -> repr () -> repr ()
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> repr () -> repr ()
forall (repr :: * -> *) a. CombAlternable repr => repr a -> repr a
P.try repr ()
varstmt repr () -> repr () -> repr ()
forall (repr :: * -> *) a.
CombAlternable repr =>
repr a -> repr a -> repr a
P.<|> repr ()
expr repr () -> repr Char -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr a
P.<* repr Char
semi
    -- P.pure Prod.unit
  ifstmt :: repr ()
ifstmt = String -> repr ()
keyword String
"if" -- P.*> expr P.*> block P.*> P.optional (keyword "else" P.*> block)
  whilestmt :: repr ()
whilestmt = String -> repr ()
keyword String
"while" repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
expr repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
block
  varstmt :: repr ()
varstmt = repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombAlternable repr) =>
repr a -> repr ()
P.optional (String -> repr ()
keyword String
"var") repr () -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
varlist1 repr () -> repr Char -> repr Char
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> Char -> repr Char
symbol Char
'=' repr Char -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr ()
exprlist1 repr () -> repr Char -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr a
P.<* repr Char
semi
  keyword :: String -> repr ()
  keyword :: String -> repr ()
keyword String
k = String -> repr String
forall (repr :: * -> *).
(CombApplicable repr, CombAlternable repr,
 CombSatisfiable Char repr) =>
String -> repr String
P.string String
k repr String -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> Production () -> repr ()
forall (repr :: * -> *) a.
CombApplicable repr =>
Production a -> repr a
P.pure Production ()
forall (repr :: * -> *). Constantable () repr => repr ()
Prod.unit
  {-
  keyword s = P.try (P.string s P.*> notIdentLetter) P.*> whitespace
  notIdentLetter = P.negLook identLetter
  -}
  identLetter :: repr Char
identLetter = Production (Char -> Bool) -> repr Char
forall tok (repr :: * -> *).
CombSatisfiable tok repr =>
Production (tok -> Bool) -> repr tok
P.satisfy
    ((Char -> Bool) -> CodeQ (Char -> Bool) -> Production (Char -> Bool)
forall a. a -> CodeQ a -> Production a
P.production Char -> Bool
nandIdentLetter [||nandIdentLetter||])

  -- hexadecimal = P.oneOf "xX" P.*> number (P.oneOf (['a'..'f'] <> ['A'..'F'] <> ['0'..'9']))
  -- octal = P.oneOf "oO" P.*> number (P.oneOf ['0'..'7'])

  symbol :: Char -> repr Char
  symbol :: Char -> repr Char
symbol Char
c = Char -> repr Char
forall (repr :: * -> *).
(CombApplicable repr, CombSatisfiable Char repr) =>
Char -> repr Char
P.char Char
c repr Char -> repr () -> repr Char
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr a
P.<* repr ()
whitespace
  parens :: repr a -> repr a
  parens :: forall a. repr a -> repr a
parens = repr Char -> repr Char -> repr a -> repr a
forall (repr :: * -> *) o c a.
CombApplicable repr =>
repr o -> repr c -> repr a -> repr a
P.between (Char -> repr Char
symbol Char
'(') (Char -> repr Char
symbol Char
')')
  brackets :: repr a -> repr a
  brackets :: forall a. repr a -> repr a
brackets = repr Char -> repr Char -> repr a -> repr a
forall (repr :: * -> *) o c a.
CombApplicable repr =>
repr o -> repr c -> repr a -> repr a
P.between (Char -> repr Char
symbol Char
'[') (Char -> repr Char
symbol Char
']')
  braces :: repr a -> repr a
  braces :: forall a. repr a -> repr a
braces = repr Char -> repr Char -> repr a -> repr a
forall (repr :: * -> *) o c a.
CombApplicable repr =>
repr o -> repr c -> repr a -> repr a
P.between (Char -> repr Char
symbol Char
'{') (Char -> repr Char
symbol Char
'}')
  semi :: repr Char
  semi :: repr Char
semi = Char -> repr Char
symbol Char
';'
  comma :: repr Char
  comma :: repr Char
comma = Char -> repr Char
symbol Char
','
  commaSep :: repr a -> repr ()
  commaSep :: forall a. repr a -> repr ()
commaSep repr a
p = repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombAlternable repr) =>
repr a -> repr ()
P.optional (repr a -> repr ()
forall a. repr a -> repr ()
commaSep1 repr a
p)
  commaSep1 :: repr a -> repr ()
  commaSep1 :: forall a. repr a -> repr ()
commaSep1 repr a
p = repr a
p repr a -> repr () -> repr ()
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr a -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombFoldable repr) =>
repr a -> repr ()
P.skipMany (repr Char
comma repr Char -> repr a -> repr a
forall (repr :: * -> *) a b.
CombApplicable repr =>
repr a -> repr b -> repr b
P.*> repr a
p)

  space :: repr ()
  space :: repr ()
space = repr Char -> repr ()
forall (repr :: * -> *) a. CombApplicable repr => repr a -> repr ()
P.void (Production (Char -> Bool) -> repr Char
forall tok (repr :: * -> *).
CombSatisfiable tok repr =>
Production (tok -> Bool) -> repr tok
P.satisfy ((Char -> Bool) -> CodeQ (Char -> Bool) -> Production (Char -> Bool)
forall a. a -> CodeQ a -> Production a
P.production Char -> Bool
isSpace [||isSpace||]))
  whitespace :: repr ()
  whitespace :: repr ()
whitespace = repr ()
spaces
  {-
  whitespace = P.skipMany (spaces P.<|> oneLineComment)
  oneLineComment :: repr ()
  oneLineComment = P.void (P.string "//" P.*> P.skipMany (P.satisfy
    (P.production (/= '\n') [||(/= '\n')||])))
  -}
  spaces :: repr ()
  spaces :: repr ()
spaces = repr () -> repr ()
forall (repr :: * -> *) a.
(CombApplicable repr, CombFoldable repr) =>
repr a -> repr ()
P.skipSome repr ()
space