fix: builtin parsing
This commit is contained in:
		
							parent
							
								
									7f4f103adc
								
							
						
					
					
						commit
						e0e98f92e4
					
				|  | @ -1,3 +1,3 @@ | |||
| (program 1.0.0 | ||||
|     [(lam x (con integer 4)) (con bool False)] | ||||
|     [[(builtin addInteger) (con integer 4)] (con integer 8)] | ||||
| ) | ||||
							
								
								
									
										80
									
								
								src/ast.rs
								
								
								
								
							
							
						
						
									
										80
									
								
								src/ast.rs
								
								
								
								
							|  | @ -1,4 +1,4 @@ | |||
| use strum_macros::EnumString; | ||||
| use crate::builtins::DefaultFunction; | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct Program { | ||||
|  | @ -27,7 +27,7 @@ pub enum Term { | |||
|     // tag: 5
 | ||||
|     Force(Box<Term>), | ||||
|     // tag: 6
 | ||||
|     Error(Box<Term>), | ||||
|     Error, | ||||
|     // tag: 7
 | ||||
|     Builtin(DefaultFunction), | ||||
| } | ||||
|  | @ -48,79 +48,3 @@ pub enum Constant { | |||
|     // tag: 5
 | ||||
|     Bool(bool), | ||||
| } | ||||
| 
 | ||||
| #[allow(non_camel_case_types)] | ||||
| #[derive(Debug, Clone, EnumString)] | ||||
| pub enum DefaultFunction { | ||||
|     // Integer functions
 | ||||
|     AddInteger, | ||||
|     SubtractInteger, | ||||
|     MultiplyInteger, | ||||
|     DivideInteger, | ||||
|     QuotientInteger, | ||||
|     RemainderInteger, | ||||
|     ModInteger, | ||||
|     EqualsInteger, | ||||
|     LessThanInteger, | ||||
|     LessThanEqualsInteger, | ||||
|     // ByteString functions
 | ||||
|     AppendByteString, | ||||
|     ConsByteString, | ||||
|     SliceByteString, | ||||
|     LengthOfByteString, | ||||
|     IndexByteString, | ||||
|     EqualsByteString, | ||||
|     LessThanByteString, | ||||
|     LessThanEqualsByteString, | ||||
|     // Cryptography and hash functions
 | ||||
|     Sha2_256, | ||||
|     Sha3_256, | ||||
|     Blake2b_256, | ||||
|     VerifySignature, | ||||
|     VerifyEcdsaSecp256k1Signature, | ||||
|     VerifySchnorrSecp256k1Signature, | ||||
|     // String functions
 | ||||
|     AppendString, | ||||
|     EqualsString, | ||||
|     EncodeUtf8, | ||||
|     DecodeUtf8, | ||||
|     // Bool function
 | ||||
|     IfThenElse, | ||||
|     // Unit function
 | ||||
|     ChooseUnit, | ||||
|     // Tracing function
 | ||||
|     Trace, | ||||
|     // Pairs functions
 | ||||
|     FstPair, | ||||
|     SndPair, | ||||
|     // List functions
 | ||||
|     ChooseList, | ||||
|     MkCons, | ||||
|     HeadList, | ||||
|     TailList, | ||||
|     NullList, | ||||
|     // Data functions
 | ||||
|     // It is convenient to have a "choosing" function for a data type that has more than two
 | ||||
|     // constructors to get pattern matching over it and we may end up having multiple such data
 | ||||
|     // types, hence we include the name of the data type as a suffix.
 | ||||
|     ChooseData, | ||||
|     ConstrData, | ||||
|     MapData, | ||||
|     ListData, | ||||
|     IData, | ||||
|     BData, | ||||
|     UnConstrData, | ||||
|     UnMapData, | ||||
|     UnListData, | ||||
|     UnIData, | ||||
|     UnBData, | ||||
|     EqualsData, | ||||
|     SerialiseData, | ||||
|     // Misc constructors
 | ||||
|     // Constructors that we need for constructing e.g. Data. Polymorphic builtin
 | ||||
|     // constructors are often problematic (See note [Representable built-in
 | ||||
|     // functions over polymorphic built-in types])
 | ||||
|     MkPairData, | ||||
|     MkNilData, | ||||
|     MkNilPairData, | ||||
| } | ||||
|  |  | |||
|  | @ -0,0 +1,78 @@ | |||
| use strum_macros::EnumString; | ||||
| 
 | ||||
| #[allow(non_camel_case_types)] | ||||
| #[derive(Debug, Clone, EnumString)] | ||||
| #[strum(serialize_all = "camelCase")] | ||||
| pub enum DefaultFunction { | ||||
|     // Integer functions
 | ||||
|     AddInteger, | ||||
|     SubtractInteger, | ||||
|     MultiplyInteger, | ||||
|     DivideInteger, | ||||
|     QuotientInteger, | ||||
|     RemainderInteger, | ||||
|     ModInteger, | ||||
|     EqualsInteger, | ||||
|     LessThanInteger, | ||||
|     LessThanEqualsInteger, | ||||
|     // ByteString functions
 | ||||
|     AppendByteString, | ||||
|     ConsByteString, | ||||
|     SliceByteString, | ||||
|     LengthOfByteString, | ||||
|     IndexByteString, | ||||
|     EqualsByteString, | ||||
|     LessThanByteString, | ||||
|     LessThanEqualsByteString, | ||||
|     // Cryptography and hash functions
 | ||||
|     Sha2_256, | ||||
|     Sha3_256, | ||||
|     Blake2b_256, | ||||
|     VerifySignature, | ||||
|     VerifyEcdsaSecp256k1Signature, | ||||
|     VerifySchnorrSecp256k1Signature, | ||||
|     // String functions
 | ||||
|     AppendString, | ||||
|     EqualsString, | ||||
|     EncodeUtf8, | ||||
|     DecodeUtf8, | ||||
|     // Bool function
 | ||||
|     IfThenElse, | ||||
|     // Unit function
 | ||||
|     ChooseUnit, | ||||
|     // Tracing function
 | ||||
|     Trace, | ||||
|     // Pairs functions
 | ||||
|     FstPair, | ||||
|     SndPair, | ||||
|     // List functions
 | ||||
|     ChooseList, | ||||
|     MkCons, | ||||
|     HeadList, | ||||
|     TailList, | ||||
|     NullList, | ||||
|     // Data functions
 | ||||
|     // It is convenient to have a "choosing" function for a data type that has more than two
 | ||||
|     // constructors to get pattern matching over it and we may end up having multiple such data
 | ||||
|     // types, hence we include the name of the data type as a suffix.
 | ||||
|     ChooseData, | ||||
|     ConstrData, | ||||
|     MapData, | ||||
|     ListData, | ||||
|     IData, | ||||
|     BData, | ||||
|     UnConstrData, | ||||
|     UnMapData, | ||||
|     UnListData, | ||||
|     UnIData, | ||||
|     UnBData, | ||||
|     EqualsData, | ||||
|     SerialiseData, | ||||
|     // Misc constructors
 | ||||
|     // Constructors that we need for constructing e.g. Data. Polymorphic builtin
 | ||||
|     // constructors are often problematic (See note [Representable built-in
 | ||||
|     // functions over polymorphic built-in types])
 | ||||
|     MkPairData, | ||||
|     MkNilData, | ||||
|     MkNilPairData, | ||||
| } | ||||
|  | @ -1,4 +1,5 @@ | |||
| pub mod ast; | ||||
| pub mod builtins; | ||||
| pub mod cli; | ||||
| pub mod parser; | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,7 +8,10 @@ use combine::{ | |||
|     token, EasyParser, ParseError, Parser, Stream, | ||||
| }; | ||||
| 
 | ||||
| use crate::ast::{Constant, DefaultFunction, Program, Term}; | ||||
| use crate::{ | ||||
|     ast::{Constant, Program, Term}, | ||||
|     builtins::DefaultFunction, | ||||
| }; | ||||
| 
 | ||||
| pub fn program(src: &str) -> anyhow::Result<Program> { | ||||
|     let mut parser = program_(); | ||||
|  | @ -167,8 +170,7 @@ where | |||
|         token(')'), | ||||
|         string("error") | ||||
|             .with(skip_many1(space())) | ||||
|             .with(term_()) | ||||
|             .map(|term| Term::Error(Box::new(term))), | ||||
|             .map(|_| Term::Error), | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Kasey White
						Kasey White