Browse Source

Rename crate

main
Dylan Baker 3 years ago
parent
commit
93cdc5ed52
7 changed files with 29 additions and 29 deletions
  1. 7
    7
      Cargo.lock
  2. 1
    1
      Cargo.toml
  3. 1
    1
      Makefile
  4. 3
    3
      src/compiler.rs
  5. 6
    6
      src/error.rs
  6. 3
    3
      src/lexer.rs
  7. 8
    8
      src/parser.rs

+ 7
- 7
Cargo.lock View File

@@ -22,7 +22,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
22 22
 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
23 23
 
24 24
 [[package]]
25
-name = "elastic"
25
+name = "itoa"
26
+version = "0.4.7"
27
+source = "registry+https://github.com/rust-lang/crates.io-index"
28
+checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
29
+
30
+[[package]]
31
+name = "kappe"
26 32
 version = "0.1.0"
27 33
 dependencies = [
28 34
  "lazy_static",
@@ -32,12 +38,6 @@ dependencies = [
32 38
  "wasm-bindgen",
33 39
 ]
34 40
 
35
-[[package]]
36
-name = "itoa"
37
-version = "0.4.7"
38
-source = "registry+https://github.com/rust-lang/crates.io-index"
39
-checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
40
-
41 41
 [[package]]
42 42
 name = "lazy_static"
43 43
 version = "1.4.0"

+ 1
- 1
Cargo.toml View File

@@ -1,5 +1,5 @@
1 1
 [package]
2
-name = "elastic"
2
+name = "kappe"
3 3
 version = "0.1.0"
4 4
 authors = ["Dylan Baker <dylan@simulacrum.party>"]
5 5
 edition = "2018"

+ 1
- 1
Makefile View File

@@ -1,2 +1,2 @@
1
-elastic:
1
+kappe:
2 2
 	wasm-pack build --target web

+ 3
- 3
src/compiler.rs View File

@@ -2,7 +2,7 @@ use serde_json::{json, Value};
2 2
 
3 3
 use std::fmt::{Display, Formatter};
4 4
 
5
-use crate::error::ElasticError;
5
+use crate::error::KappeError;
6 6
 use crate::parser::{Field, Identifier, Select};
7 7
 
8 8
 #[derive(Debug, PartialEq)]
@@ -28,7 +28,7 @@ impl Display for Query {
28 28
     }
29 29
 }
30 30
 
31
-pub fn compile(expr: Select) -> Result<Query, ElasticError> {
31
+pub fn compile(expr: Select) -> Result<Query, KappeError> {
32 32
     let field_names: Vec<Value> = expr
33 33
         .fields
34 34
         .iter()
@@ -52,7 +52,7 @@ mod tests {
52 52
     use crate::lexer::scan;
53 53
     use crate::parser::parse;
54 54
 
55
-    fn _compile(input: &str) -> Result<Query, ElasticError> {
55
+    fn _compile(input: &str) -> Result<Query, KappeError> {
56 56
         let tokens = scan(input).unwrap();
57 57
         let select = parse(tokens).unwrap();
58 58
         compile(select)

+ 6
- 6
src/error.rs View File

@@ -1,11 +1,11 @@
1 1
 use std::{error::Error, fmt, fmt::Display};
2 2
 
3 3
 #[derive(Debug, PartialEq)]
4
-pub struct ElasticError {
4
+pub struct KappeError {
5 5
     pub message: String,
6 6
 }
7 7
 
8
-impl ElasticError {
8
+impl KappeError {
9 9
     pub fn new(message: &str) -> Self {
10 10
         Self {
11 11
             message: message.to_string(),
@@ -13,16 +13,16 @@ impl ElasticError {
13 13
     }
14 14
 }
15 15
 
16
-impl Display for ElasticError {
16
+impl Display for KappeError {
17 17
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
18 18
         write!(f, "{}", &self.message)
19 19
     }
20 20
 }
21 21
 
22
-impl Error for ElasticError {}
22
+impl Error for KappeError {}
23 23
 
24
-impl From<ElasticError> for std::io::Error {
25
-    fn from(e: ElasticError) -> Self {
24
+impl From<KappeError> for std::io::Error {
25
+    fn from(e: KappeError) -> Self {
26 26
         Self::new(std::io::ErrorKind::InvalidInput, e.message)
27 27
     }
28 28
 }

+ 3
- 3
src/lexer.rs View File

@@ -1,7 +1,7 @@
1 1
 use lazy_static::lazy_static;
2 2
 use regex::Regex;
3 3
 
4
-use crate::error::ElasticError;
4
+use crate::error::KappeError;
5 5
 use crate::token::{Token, TokenType};
6 6
 
7 7
 #[derive(Debug)]
@@ -32,7 +32,7 @@ lazy_static! {
32 32
     ];
33 33
 }
34 34
 
35
-pub fn scan(input: &str) -> Result<Vec<Token>, ElasticError> {
35
+pub fn scan(input: &str) -> Result<Vec<Token>, KappeError> {
36 36
     let mut tokens: Vec<Token> = vec![];
37 37
     let mut position = 0;
38 38
 
@@ -62,7 +62,7 @@ pub fn scan(input: &str) -> Result<Vec<Token>, ElasticError> {
62 62
         }
63 63
 
64 64
         if !matched {
65
-            return Err(ElasticError::new("Unrecognized sequence"));
65
+            return Err(KappeError::new("Unrecognized sequence"));
66 66
         }
67 67
     }
68 68
 

+ 8
- 8
src/parser.rs View File

@@ -1,6 +1,6 @@
1 1
 use std::{iter::Peekable, slice::Iter};
2 2
 
3
-use crate::error::ElasticError;
3
+use crate::error::KappeError;
4 4
 use crate::token::{Token, TokenType};
5 5
 
6 6
 #[derive(Debug, PartialEq)]
@@ -28,11 +28,11 @@ impl Identifier {
28 28
     }
29 29
 }
30 30
 
31
-pub fn parse(tokens: Vec<Token>) -> Result<Select, ElasticError> {
31
+pub fn parse(tokens: Vec<Token>) -> Result<Select, KappeError> {
32 32
     parse_select_expression(&mut tokens.iter().peekable())
33 33
 }
34 34
 
35
-fn parse_select_expression(tokens: &mut Peekable<Iter<Token>>) -> Result<Select, ElasticError> {
35
+fn parse_select_expression(tokens: &mut Peekable<Iter<Token>>) -> Result<Select, KappeError> {
36 36
     eat(tokens, TokenType::Select)?;
37 37
     let fields = parse_fields(tokens)?;
38 38
     eat(tokens, TokenType::From)?;
@@ -41,7 +41,7 @@ fn parse_select_expression(tokens: &mut Peekable<Iter<Token>>) -> Result<Select,
41 41
     Ok(Select { fields, source })
42 42
 }
43 43
 
44
-fn parse_fields(tokens: &mut Peekable<Iter<Token>>) -> Result<Vec<Field>, ElasticError> {
44
+fn parse_fields(tokens: &mut Peekable<Iter<Token>>) -> Result<Vec<Field>, KappeError> {
45 45
     if current_token_is(tokens, TokenType::Star) {
46 46
         eat(tokens, TokenType::Star).and_then(|_| Ok(vec![Field::Star]))
47 47
     } else {
@@ -72,19 +72,19 @@ fn current_token_is(tokens: &mut Peekable<Iter<Token>>, token_type: TokenType) -
72 72
 fn eat<'a>(
73 73
     tokens: &'a mut Peekable<Iter<Token>>,
74 74
     token_type: TokenType,
75
-) -> Result<&'a Token, ElasticError> {
75
+) -> Result<&'a Token, KappeError> {
76 76
     match tokens.next() {
77 77
         Some(token) => {
78 78
             if token.token_type == token_type {
79 79
                 Ok(token)
80 80
             } else {
81
-                Err(ElasticError::new(&format!(
81
+                Err(KappeError::new(&format!(
82 82
                     "Expected {} but got {}",
83 83
                     token_type, token.token_type
84 84
                 )))
85 85
             }
86 86
         }
87
-        None => Err(ElasticError::new("Unexpected end of tokens")),
87
+        None => Err(KappeError::new("Unexpected end of tokens")),
88 88
     }
89 89
 }
90 90
 
@@ -93,7 +93,7 @@ mod tests {
93 93
     use super::*;
94 94
     use crate::lexer::scan;
95 95
 
96
-    fn _parse(input: &str) -> Result<Select, ElasticError> {
96
+    fn _parse(input: &str) -> Result<Select, KappeError> {
97 97
         let tokens = scan(input).unwrap();
98 98
         parse(tokens)
99 99
     }

Loading…
Cancel
Save