about summary refs log tree commit diff
path: root/users/glittershark/achilles/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'users/glittershark/achilles/src/parser')
-rw-r--r--users/glittershark/achilles/src/parser/mod.rs21
-rw-r--r--users/glittershark/achilles/src/parser/type_.rs8
2 files changed, 23 insertions, 6 deletions
diff --git a/users/glittershark/achilles/src/parser/mod.rs b/users/glittershark/achilles/src/parser/mod.rs
index dd7874aff853..c7e541ce48a0 100644
--- a/users/glittershark/achilles/src/parser/mod.rs
+++ b/users/glittershark/achilles/src/parser/mod.rs
@@ -9,6 +9,7 @@ mod type_;
 
 use crate::ast::{Arg, Decl, Fun, Ident};
 pub use expr::expr;
+use type_::function_type;
 pub use type_::type_;
 
 pub type Error = nom::Err<nom::error::Error<String>>;
@@ -79,9 +80,24 @@ named!(arg(&str) -> Arg, alt!(
     ascripted_arg
 ));
 
+named!(extern_decl(&str) -> Decl, do_parse!(
+    complete!(tag!("extern"))
+        >> multispace1
+        >> name: ident
+        >> multispace0
+        >> char!(':')
+        >> multispace0
+        >> type_: function_type
+        >> multispace0
+        >> (Decl::Extern {
+            name,
+            type_
+        })
+));
+
 named!(fun_decl(&str) -> Decl, do_parse!(
     complete!(tag!("fn"))
-        >> multispace0
+        >> multispace1
         >> name: ident
         >> multispace1
         >> args: separated_list0!(multispace1, arg)
@@ -112,7 +128,8 @@ named!(ascription_decl(&str) -> Decl, do_parse!(
 
 named!(pub decl(&str) -> Decl, alt!(
     ascription_decl |
-    fun_decl
+    fun_decl |
+    extern_decl
 ));
 
 named!(pub toplevel(&str) -> Vec<Decl>, terminated!(many0!(decl), multispace0));
diff --git a/users/glittershark/achilles/src/parser/type_.rs b/users/glittershark/achilles/src/parser/type_.rs
index c90ceda4d72e..1e6e380bb823 100644
--- a/users/glittershark/achilles/src/parser/type_.rs
+++ b/users/glittershark/achilles/src/parser/type_.rs
@@ -4,7 +4,7 @@ use nom::{alt, delimited, do_parse, map, named, opt, separated_list0, tag, termi
 use super::ident;
 use crate::ast::{FunctionType, Type};
 
-named!(function_type(&str) -> Type, do_parse!(
+named!(pub function_type(&str) -> FunctionType, do_parse!(
     tag!("fn")
         >> multispace1
         >> args: map!(opt!(terminated!(separated_list0!(
@@ -18,10 +18,10 @@ named!(function_type(&str) -> Type, do_parse!(
         >> tag!("->")
         >> multispace1
         >> ret: type_
-        >> (Type::Function(FunctionType {
+        >> (FunctionType {
             args,
             ret: Box::new(ret)
-        }))
+        })
 ));
 
 named!(pub type_(&str) -> Type, alt!(
@@ -29,7 +29,7 @@ named!(pub type_(&str) -> Type, alt!(
     tag!("float") => { |_| Type::Float } |
     tag!("bool") => { |_| Type::Bool } |
     tag!("cstring") => { |_| Type::CString } |
-    function_type |
+    function_type => { |ft| Type::Function(ft) }|
     ident => { |id| Type::Var(id) } |
     delimited!(
         tuple!(tag!("("), multispace0),