summaryrefslogtreecommitdiff
path: root/src/lexer.rs
diff options
context:
space:
mode:
authorNanoTech2016-12-06 04:08:50 -0600
committerNanoTech2017-03-10 23:48:27 -0600
commit10577fc72af7260255493999294eda8e4413b6a5 (patch)
treea8b7130567fa9460c8126fa8e41da21c027ff37d /src/lexer.rs
parent0c3f365c15156c19f194f0c33500649649fc4ab9 (diff)
Add more ExprB rules
Diffstat (limited to 'src/lexer.rs')
-rw-r--r--src/lexer.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/lexer.rs b/src/lexer.rs
index 5f028b0..23457ac 100644
--- a/src/lexer.rs
+++ b/src/lexer.rs
@@ -24,6 +24,11 @@ pub enum Keyword {
Optional,
OptionalFold,
Bool,
+ Let,
+ In,
+ If,
+ Then,
+ Else,
}
#[derive(Debug, PartialEq, Eq)]
@@ -93,11 +98,20 @@ fn is_symbol(c: char) -> bool {
named!(symbol<&str, &str>, take_while1_s!(is_symbol));
*/
+#[allow(dead_code)]
+fn is_identifier_first_char(c: char) -> bool {
+ c.is_alphabetic() || c == '_'
+}
+
+fn is_identifier_rest_char(c: char) -> bool {
+ c.is_alphabetic() || is_decimal(c) || c == '_' || c == '/'
+}
+
fn is_decimal(c: char) -> bool {
c.is_digit(10)
}
-named!(identifier<&str, &str>, take_while1_s!(char::is_alphabetic)); // FIXME [A-Za-z_][A-Za-z0-9_/]*
+named!(identifier<&str, &str>, take_while1_s!(is_identifier_rest_char)); // FIXME use is_identifier_first_char
named!(natural<&str, &str>, preceded!(tag!("+"), take_while1_s!(is_decimal)));
named!(integral<&str, isize>, map_res!(take_while1_s!(is_decimal), |s| isize::from_str(s)));
named!(integer<&str, isize>, alt!(
@@ -110,16 +124,15 @@ named!(boolean<&str, bool>, alt!(
));
named!(keyword<&str, Keyword>, alt!(
- value!(Keyword::Natural, tag!("Natural")) |
value!(Keyword::NaturalFold, tag!("Natural/fold")) |
value!(Keyword::NaturalBuild, tag!("Natural/build")) |
value!(Keyword::NaturalIsZero, tag!("Natural/isZero")) |
value!(Keyword::NaturalEven, tag!("Natural/even")) |
value!(Keyword::NaturalOdd, tag!("Natural/odd")) |
+ value!(Keyword::Natural, tag!("Natural")) |
value!(Keyword::Integer, tag!("Integer")) |
value!(Keyword::Double, tag!("Double")) |
value!(Keyword::Text, tag!("Text")) |
- value!(Keyword::List, tag!("List")) |
value!(Keyword::ListBuild, tag!("List/build")) |
value!(Keyword::ListFold, tag!("List/fold")) |
value!(Keyword::ListLength, tag!("List/length")) |
@@ -127,9 +140,15 @@ named!(keyword<&str, Keyword>, alt!(
value!(Keyword::ListLast, tag!("List/last")) |
value!(Keyword::ListIndexed, tag!("List/indexed")) |
value!(Keyword::ListReverse, tag!("List/reverse")) |
- value!(Keyword::Optional, tag!("Optional")) |
+ value!(Keyword::List, tag!("List")) |
value!(Keyword::OptionalFold, tag!("Optional/fold")) |
- value!(Keyword::Bool, tag!("Bool"))
+ value!(Keyword::Optional, tag!("Optional")) |
+ value!(Keyword::Bool, tag!("Bool")) |
+ value!(Keyword::Let, tag!("let")) |
+ value!(Keyword::In, tag!("in")) |
+ value!(Keyword::If, tag!("if")) |
+ value!(Keyword::Then, tag!("then")) |
+ value!(Keyword::Else, tag!("else"))
));
named!(token<&str, Tok>, alt!(