tokens in separate file

This commit is contained in:
rhiannon morris 2022-05-04 15:30:08 +02:00
parent 38ecabdda8
commit 2d7110b9c6
3 changed files with 48 additions and 29 deletions

View file

@ -39,6 +39,8 @@
"Quox.Syntax.Term.Subst", "Quox.Syntax.Term.Subst",
"Quox.Syntax.Universe", "Quox.Syntax.Universe",
"Quox.Syntax.Var", "Quox.Syntax.Var",
"Quox.Token",
"Quox.Lexer", "Quox.Lexer",
"Quox.Context", "Quox.Context",

View file

@ -1,6 +1,7 @@
module Quox.Lexer module Quox.Lexer
import Quox.Error import Quox.Error
import public Quox.Token
import Data.String import Data.String
import Data.String.Extra import Data.String.Extra
@ -19,35 +20,6 @@ record Error where
line, col : Int line, col : Int
char : Char char : Char
public export
data Punc
= LParen | RParen
| LSquare | RSquare
| LBrace | RBrace
| Comma
| Colon | DblColon
| Arrow | DblArrow
| Times | Triangle
| Wild
%runElab derive "Punc" [Generic, Meta, Eq, Ord, DecEq, Show]
||| zero and one are separate because they are
||| quantity & dimension constants
public export
data Number = Zero | One | Other Nat
%runElab derive "Number" [Generic, Meta, Eq, Ord, DecEq, Show]
public export
data Token
= P Punc
| Name String | Symbol String
| N Number
%runElab derive "Token" [Generic, Meta, Eq, Ord, DecEq, Show]
nameStart = pred $ \c => isAlpha c || c == '_' nameStart = pred $ \c => isAlpha c || c == '_'

45
src/Quox/Token.idr Normal file
View file

@ -0,0 +1,45 @@
module Quox.Token
import Generics.Derive
%default total
%language ElabReflection
public export
data Punc
= LParen | RParen
| LSquare | RSquare
| LBrace | RBrace
| Comma
| Colon | DblColon
| Arrow | DblArrow
| Times | Triangle
| Wild
%runElab derive "Punc" [Generic, Meta, Eq, Ord, DecEq, Show]
public export
data Keyword
= Fun | Let | In | Case | Of
%runElab derive "Keyword" [Generic, Meta, Eq, Ord, DecEq, Show]
||| zero and one are separate because they are
||| quantity & dimension constants
public export
data Number = Zero | One | Other Nat
%runElab derive "Number" [Generic, Meta, Eq, Ord, DecEq, Show]
public export
data Token
= P Punc
| Name String | Symbol String
| N Number
| K Keyword
%runElab derive "Token" [Generic, Meta, Eq, Ord, DecEq, Show]