Browse Source

Add copyright notices

github-actions
Garrit Franke 2 years ago
parent
commit
226fb93792
  1. 17
      examples/leapyear.sb
  2. 19
      examples/playground.sb
  3. 19
      src/generator/js.rs
  4. 15
      src/generator/mod.rs
  5. 15
      src/generator/x86.rs
  6. 15
      src/lexer/cursor.rs
  7. 36
      src/lexer/mod.rs
  8. 16
      src/lexer/tests.rs
  9. 15
      src/main.rs
  10. 15
      src/parser/mod.rs
  11. 21
      src/parser/node_type.rs
  12. 15
      src/parser/tests.rs
  13. 15
      src/util/mod.rs
  14. 15
      src/util/string_util.rs

17
examples/leapyear.sb

@ -0,0 +1,17 @@
// There are no nested expressions yet, so we have to hack a little bit
fn main() {
let year = 2020
let divisibleBy4 = year % 4 == 0
let divisibleBy100 = year % 100 != 0
let divisibleBy400 = year % 400 == 0
let ly = divisibleBy4 && divisibleBy100
if ly || divisibleBy400 {
return "Leap year"
} else {
return "Not a leap year"
}
}

19
examples/playground.sb

@ -1,10 +1,17 @@
// There are no nested expressions yet, so we have to hack a little bit
fn main() {
let num = 5
if num > 5 {
return num
} else if num < 5 {
return 1
let year = 2020
let divisibleBy4 = year % 4 == 0
let divisibleBy100 = year % 100 != 0
let divisibleBy400 = year % 400 == 0
let ly = divisibleBy4 && divisibleBy100
if ly || divisibleBy400 {
return "Leap year"
} else {
return num + 1
return "Not a leap year"
}
}

19
src/generator/js.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::generator::Generator;
use crate::parser::node_type::*;
@ -104,8 +119,8 @@ fn generate_declare(name: String, val: Option<Expression>) -> String {
// var is used here to not collide with scopes.
// TODO: Can let be used instead?
match val {
Some(expr) => format!("var {} = {};", name, generate_expression(expr)),
None => format!("var {};", name),
Some(expr) => format!("var {} = {};\n", name, generate_expression(expr)),
None => format!("var {};\n", name),
}
}

15
src/generator/mod.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::parser::node_type::*;
pub mod js;

15
src/generator/x86.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::generator::Generator;
use crate::parser::node_type::{Function, Program, Statement};

15
src/lexer/cursor.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::lexer::Position;
use std::str::Chars;

36
src/lexer/mod.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pub(crate) mod cursor;
use self::TokenKind::*;
@ -51,6 +66,8 @@ pub enum TokenKind {
Star,
/// "/"
Slash,
/// "%"
Percent,
/// ":"
Colon,
/// ";"
@ -73,6 +90,10 @@ pub enum TokenKind {
GreaterThanOrEqual,
/// "!="
NotEqual,
/// &&
And,
/// "||"
Or,
/// "("
BraceOpen,
/// ")"
@ -170,6 +191,7 @@ impl Cursor<'_> {
'+' => Plus,
'-' => Minus,
'*' => Star,
'%' => Percent,
'/' => match self.first() {
'/' => {
self.bump();
@ -201,6 +223,20 @@ impl Cursor<'_> {
}
_ => GreaterThan,
},
'&' => match self.first() {
'&' => {
self.bump();
And
}
_ => Unknown,
},
'|' => match self.first() {
'|' => {
self.bump();
Or
}
_ => Unknown,
},
'!' => match self.first() {
'=' => {
self.bump();

16
src/lexer/tests.rs

@ -1,3 +1,19 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#[cfg(test)]
mod tests {
use crate::lexer::*;

15
src/main.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern crate structopt;
use crate::generator::Generator;

15
src/parser/mod.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::lexer::Keyword;
use crate::lexer::{Token, TokenKind, Value};
use crate::parser::node_type::Statement;

21
src/parser/node_type.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::parser::{Token, TokenKind, Value};
use core::convert::TryFrom;
@ -84,14 +99,16 @@ impl TryFrom<TokenKind> for BinOp {
TokenKind::Slash => Ok(BinOp::Division),
TokenKind::Plus => Ok(BinOp::Addition),
TokenKind::Minus => Ok(BinOp::Subtraction),
TokenKind::Percent => Ok(BinOp::Modulus),
TokenKind::LessThan => Ok(BinOp::LessThan),
TokenKind::GreaterThan => Ok(BinOp::GreaterThan),
TokenKind::Equals => Ok(BinOp::Equal),
TokenKind::LessThanOrEqual => Ok(BinOp::LessThanOrEqual),
TokenKind::GreaterThanOrEqual => Ok(BinOp::GreaterThanOrEqual),
TokenKind::NotEqual => Ok(BinOp::NotEqual),
// TokenKind::And => BinOp::And,
// TokenKind::Or => BinOp::Or,
TokenKind::Percent => Ok(BinOp::Modulus),
TokenKind::And => Ok(BinOp::And),
TokenKind::Or => Ok(BinOp::Or),
other => Err(format!("Token {:?} cannot be converted into a BinOp", other).into()),
}
}

15
src/parser/tests.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::lexer::*;
use crate::parser::*;

15
src/util/mod.rs

@ -1 +1,16 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pub mod string_util;

15
src/util/string_util.rs

@ -1,3 +1,18 @@
/**
* Copyright 2020 Garrit Franke
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::lexer::Position;
pub fn highlight_position_in_file(input: String, position: Position) -> String {

Loading…
Cancel
Save