From f1599d6860951e1a6f61d3b792410f9b6e53b284 Mon Sep 17 00:00:00 2001 From: VegOwOtenks Date: Mon, 30 Dec 2024 08:44:51 +0100 Subject: [PATCH] UbcLanguage Definition --- app/Main.hs | 9 ++++++ src/Data/String/Ubc/Parse.hs | 5 ++++ src/Data/String/Ubc/Parse/Language.hs | 41 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 app/Main.hs create mode 100644 src/Data/String/Ubc/Parse.hs create mode 100644 src/Data/String/Ubc/Parse/Language.hs diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..9d1c93c --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,9 @@ +module Main (main) where + +import Data.Text.Ubc.Parse + +main :: IO () +main = do + text <- getContents + someFunc + return () diff --git a/src/Data/String/Ubc/Parse.hs b/src/Data/String/Ubc/Parse.hs new file mode 100644 index 0000000..36604f8 --- /dev/null +++ b/src/Data/String/Ubc/Parse.hs @@ -0,0 +1,5 @@ +module Data.String.Ubc.Parse +( someFunc ) +where + +someFunc = putStrLn "help" diff --git a/src/Data/String/Ubc/Parse/Language.hs b/src/Data/String/Ubc/Parse/Language.hs new file mode 100644 index 0000000..739a509 --- /dev/null +++ b/src/Data/String/Ubc/Parse/Language.hs @@ -0,0 +1,41 @@ +module Data.String.Ubc.Parse.Language +( languageDef +) +where + +import Text.Parsec +import Text.Parsec.Token +import Text.Parsec.Language + +languageDef :: GenLanguageDef String u m +languageDef = LanguageDef { + commentStart = "/*" + , commentEnd = "*/" + , commentLine = "//" + , nestedComments = True + , identStart = letter <|> char '_' + , identLetter = alphaNum <|> char '_' + , opStart = oneOf "+-*/" + , opLetter = oneOf "+-*/" + , reservedNames = [ "struct", "u32", "i32", "f32" ] + } + +tokenParser :: GenTokenParser String u m +tokenParser = makeTokenParser languageDef + +TokenParser{ + identifier = identifier + , reserved = reserved + , operator = operator + , reservedOp = reservedOperator + , charLiteral = characterLiteral + , stringLiteral = stringLiteral + , natural = natural -- decimal, hexadecimal or octal + , integer = integer -- decimal, hexadecimal or octal + , float = float + , naturalOrFloat = naturalOrFloat + , decimal = decimal + , hexadecimal = hexadecimal + , octal = octal + , symbol = symbol + } = tokenParser