Skip to content

Object initialization #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target/
*.iml
__pycache__/
*.pyc
*.out

### PREVIOUS KOTLIN AND IDEA IGNORES ###

Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file removed a.out
Empty file.
3 changes: 2 additions & 1 deletion ci/simple.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ FROM mangocode/mango_daily_base:2021-05-02 AS build
ENV RUST_LOG='debug,ws=warn,mio=warn'

# Copy the actual code.
COPY ./Cargo.toml ./Cargo.lock ./deny.toml ./rustfmt.toml ./
# exclude .lock file for now as it slows down dependencies
COPY ./Cargo.toml ./deny.toml ./rustfmt.toml ./
COPY ./src/ ./src

# Build (for test)
Expand Down
4 changes: 4 additions & 0 deletions src/lexeme/collect/for_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ impl TestLexemeBuilder {
self.add_simple(": ", |src| Lexeme::Colon(ColonLexeme::new(src)))
}

pub fn type_sep(self) -> Self {
self.add_simple("< ", |src| Lexeme::Operator(OperatorLexeme::from_symbol(Symbol::LT, src)))
}

pub fn comma(self) -> Self {
self.add_simple(",", |src| Lexeme::Comma(CommaLexeme::new(src)))
}
Expand Down
4 changes: 2 additions & 2 deletions src/lexeme/lexemes/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::lexeme::Lexeme;
/// Also in-place operations like *=, += etc.
#[derive(Debug, Eq, Clone)]
pub struct OperatorLexeme {
symbol: Symbol,
source: SourceSlice,
pub symbol: Symbol,
pub source: SourceSlice,
}

impl OperatorLexeme {
Expand Down
4 changes: 2 additions & 2 deletions src/parsing/files/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ mod tests {
.identifier("gcd")
.parenthesis_open()
.identifier("x")
.colon()
.type_sep()
.identifier("int")
.comma()
.identifier("y")
.colon()
.type_sep()
.identifier("int")
.parenthesis_close()
.operator("➔")
Expand Down
77 changes: 43 additions & 34 deletions src/parsing/partial/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::collections::HashSet;

use ::smallvec::smallvec;

use crate::lexeme::Lexeme;
use crate::ir::codeparts::Symbol;
use crate::lexeme::{Lexeme, OperatorLexeme};
use crate::parselet::signature::parameters::{ParametersParselet, TypedValueParselet};
use crate::parsing::partial::typ::parse_type;
use crate::parsing::util::cursor::ParseCursor;
Expand Down Expand Up @@ -30,7 +31,11 @@ pub fn parse_parameters(mut cursor: ParseCursor) -> ParseRes<ParametersParselet>
Ok(Lexeme::Identifier(name)) => {
if let Some(name) = name.to_simple() {
let name = name.clone();
if let Lexeme::Colon(_) = iter_cursor.take()? {
if let Lexeme::Operator(OperatorLexeme {
symbol: Symbol::LT,
source: _,
}) = iter_cursor.take()?
{
//TODO @mark: parse complex types like [int, double] or Vec[int]
if let Ok((typ_cursor, typ)) = parse_type(iter_cursor) {
if names_seen.contains(name.name.as_ustr()) {
Expand All @@ -44,8 +49,12 @@ pub fn parse_parameters(mut cursor: ParseCursor) -> ParseRes<ParametersParselet>
continue;
}
break;
} else {
//TODO @mark: better error handling
panic!("parameter {} is missing a type", name.name);
}
} else {
//TODO @mark: better error handling
panic!("parameter {} is missing a type", name.name);
}
}
Expand Down Expand Up @@ -78,7 +87,7 @@ mod with_parentheses {
let lexemes = builder()
.parenthesis_open()
.identifier("name")
.colon()
.type_sep()
.identifier("type")
.parenthesis_close()
.file();
Expand All @@ -93,7 +102,7 @@ mod with_parentheses {
let lexemes = builder()
.parenthesis_open()
.identifier("name")
.colon()
.type_sep()
.identifier("type")
.comma()
.parenthesis_close()
Expand All @@ -109,7 +118,7 @@ mod with_parentheses {
let lexemes = builder()
.parenthesis_open()
.identifier("name")
.colon()
.type_sep()
.identifier("type")
.newline()
.parenthesis_close()
Expand All @@ -125,7 +134,7 @@ mod with_parentheses {
let lexemes = builder()
.parenthesis_open()
.identifier("name")
.colon()
.type_sep()
.identifier("type")
.comma()
.newline()
Expand All @@ -142,19 +151,19 @@ mod with_parentheses {
let lexemes = builder()
.parenthesis_open()
.identifier("name1")
.colon()
.type_sep()
.identifier("type1")
.comma()
.identifier("name2")
.colon()
.type_sep()
.identifier("type2")
.comma()
.identifier("name3")
.colon()
.type_sep()
.identifier("type3")
.newline()
.identifier("name4")
.colon()
.type_sep()
.identifier("type4")
.newline()
.parenthesis_close()
Expand All @@ -173,11 +182,11 @@ mod with_parentheses {
let lexemes = builder()
.parenthesis_open()
.identifier("name1")
.colon()
.type_sep()
.identifier("type")
.comma()
.identifier("name2")
.colon()
.type_sep()
.identifier("type")
.comma()
.parenthesis_close()
Expand Down Expand Up @@ -211,11 +220,11 @@ mod error_cases {
let lexemes = builder()
.parenthesis_open()
.identifier("name")
.colon()
.type_sep()
.identifier("type1")
.comma()
.identifier("name")
.colon()
.type_sep()
.identifier("type2")
.comma()
.parenthesis_close()
Expand All @@ -228,7 +237,7 @@ mod error_cases {
fn missing_open() {
let lexemes = builder()
.identifier("name")
.colon()
.type_sep()
.identifier("type1")
.comma()
.parenthesis_close()
Expand All @@ -242,7 +251,7 @@ mod error_cases {
let lexemes = builder()
.parenthesis_open()
.identifier("name")
.colon()
.type_sep()
.identifier("type1")
.comma()
.file();
Expand All @@ -255,10 +264,10 @@ mod error_cases {
let lexemes = builder()
.parenthesis_open()
.identifier("name")
.colon()
.type_sep()
.identifier("type1")
.identifier("name")
.colon()
.type_sep()
.identifier("type1")
.parenthesis_close()
.file();
Expand Down Expand Up @@ -291,7 +300,7 @@ mod without_parentheses {

#[test]
fn single() {
let lexemes = builder().identifier("name").colon().identifier("type").file();
let lexemes = builder().identifier("name").type_sep().identifier("type").file();
let (cursor, params) = parse_parameters(lexemes.cursor()).unwrap();
assert_eq!(params.len(), 1);
assert_eq!(params[0], TypedValueParselet::new_mocked("name", "type"));
Expand All @@ -302,7 +311,7 @@ mod without_parentheses {
fn single_trailing_comma() {
let lexemes = builder()
.identifier("name")
.colon()
.type_sep()
.identifier("type")
.comma()
.parenthesis_close()
Expand All @@ -317,7 +326,7 @@ mod without_parentheses {
fn single_trailing_newline() {
let lexemes = builder()
.identifier("name")
.colon()
.type_sep()
.identifier("type")
.newline()
.parenthesis_close()
Expand All @@ -332,7 +341,7 @@ mod without_parentheses {
fn single_trailing_comma_and_newline() {
let lexemes = builder()
.identifier("name")
.colon()
.type_sep()
.identifier("type")
.comma()
.newline()
Expand All @@ -348,11 +357,11 @@ mod without_parentheses {
fn double() {
let lexemes = builder()
.identifier("name1")
.colon()
.type_sep()
.identifier("type1")
.comma()
.identifier("name2")
.colon()
.type_sep()
.identifier("type2")
.comma()
.parenthesis_close()
Expand All @@ -368,19 +377,19 @@ mod without_parentheses {
fn quadruple() {
let lexemes = builder()
.identifier("name1")
.colon()
.type_sep()
.identifier("type1")
.comma()
.identifier("name2")
.colon()
.type_sep()
.identifier("type2")
.comma()
.identifier("name3")
.colon()
.type_sep()
.identifier("type3")
.newline()
.identifier("name4")
.colon()
.type_sep()
.identifier("type4")
.newline()
.parenthesis_close()
Expand All @@ -398,11 +407,11 @@ mod without_parentheses {
fn next_lexeme_close() {
let lexemes = builder()
.identifier("name1")
.colon()
.type_sep()
.identifier("type")
.comma()
.identifier("name2")
.colon()
.type_sep()
.identifier("type")
.comma()
.parenthesis_close()
Expand All @@ -417,11 +426,11 @@ mod without_parentheses {
fn next_lexeme_random() {
let lexemes = builder()
.identifier("name1")
.colon()
.type_sep()
.identifier("type")
.comma()
.identifier("name2")
.colon()
.type_sep()
.identifier("type")
.comma()
.keyword("use")
Expand All @@ -436,11 +445,11 @@ mod without_parentheses {
fn next_lexeme_eof() {
let lexemes = builder()
.identifier("name1")
.colon()
.type_sep()
.identifier("type")
.comma()
.identifier("name2")
.colon()
.type_sep()
.identifier("type")
.file();
let (cursor, params) = parse_parameters(lexemes.cursor()).unwrap();
Expand Down
Loading