Move the wasm lib, and cleanup rust directory and all references (#5585)
* git mv src/wasm-lib rust Signed-off-by: Jess Frazelle <github@jessfraz.com> * mv wasm-lib to workspace Signed-off-by: Jess Frazelle <github@jessfraz.com> * mv kcl-lib Signed-off-by: Jess Frazelle <github@jessfraz.com> * mv derive docs Signed-off-by: Jess Frazelle <github@jessfraz.com> * resolve file paths Signed-off-by: Jess Frazelle <github@jessfraz.com> * clippy Signed-off-by: Jess Frazelle <github@jessfraz.com> * move more shit Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix more paths Signed-off-by: Jess Frazelle <github@jessfraz.com> * make yarn build:wasm work Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix scripts Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixups Signed-off-by: Jess Frazelle <github@jessfraz.com> * better references Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix cargo ci Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix reference Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix more ci Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix tests Signed-off-by: Jess Frazelle <github@jessfraz.com> * cargo sort Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix script Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix Signed-off-by: Jess Frazelle <github@jessfraz.com> * fmt Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix a dep Signed-off-by: Jess Frazelle <github@jessfraz.com> * sort Signed-off-by: Jess Frazelle <github@jessfraz.com> * remove unused deps Signed-off-by: Jess Frazelle <github@jessfraz.com> * Revert "remove unused deps" This reverts commit fbabdb062e275fd5cbc1476f8480a1afee15d972. * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * deps; Signed-off-by: Jess Frazelle <github@jessfraz.com> * fixes Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
514
rust/kcl-lib/src/parsing/ast/digest.rs
Normal file
514
rust/kcl-lib/src/parsing/ast/digest.rs
Normal file
@ -0,0 +1,514 @@
|
||||
use sha2::{Digest as DigestTrait, Sha256};
|
||||
|
||||
use crate::parsing::ast::types::{
|
||||
Annotation, ArrayExpression, ArrayRangeExpression, Ascription, BinaryExpression, BinaryPart, BodyItem,
|
||||
CallExpression, CallExpressionKw, DefaultParamVal, ElseIf, Expr, ExpressionStatement, FunctionExpression,
|
||||
Identifier, IfExpression, ImportItem, ImportSelector, ImportStatement, ItemVisibility, KclNone, LabelledExpression,
|
||||
Literal, LiteralIdentifier, LiteralValue, MemberExpression, MemberObject, ObjectExpression, ObjectProperty,
|
||||
Parameter, PipeExpression, PipeSubstitution, Program, ReturnStatement, TagDeclarator, Type, UnaryExpression,
|
||||
VariableDeclaration, VariableDeclarator, VariableKind,
|
||||
};
|
||||
|
||||
/// Position-independent digest of the AST node.
|
||||
pub type Digest = [u8; 32];
|
||||
|
||||
macro_rules! compute_digest {
|
||||
(|$slf:ident, $hasher:ident| $body:block) => {
|
||||
/// Compute a digest over the AST node.
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
if let Some(node_digest) = self.digest {
|
||||
return node_digest;
|
||||
}
|
||||
|
||||
let mut $hasher = Sha256::new();
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut $slf = self;
|
||||
|
||||
$hasher.update(std::any::type_name::<Self>());
|
||||
|
||||
$body
|
||||
|
||||
let node_digest: Digest = $hasher.finalize().into();
|
||||
$slf.digest = Some(node_digest);
|
||||
node_digest
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl ImportItem {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
if let Some(alias) = &mut slf.alias {
|
||||
hasher.update([1]);
|
||||
hasher.update(alias.compute_digest());
|
||||
} else {
|
||||
hasher.update([0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ImportStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
match &mut slf.selector {
|
||||
ImportSelector::List { items } => {
|
||||
for item in items {
|
||||
hasher.update(item.compute_digest());
|
||||
}
|
||||
}
|
||||
ImportSelector::Glob(_) => hasher.update(b"ImportSelector::Glob"),
|
||||
ImportSelector::None { alias: None } => hasher.update(b"ImportSelector::None"),
|
||||
ImportSelector::None { alias: Some(alias) } => {
|
||||
hasher.update(b"ImportSelector::None");
|
||||
hasher.update(alias.compute_digest());
|
||||
}
|
||||
}
|
||||
hasher.update(slf.visibility.digestable_id());
|
||||
let path = slf.path.to_string();
|
||||
let path = path.as_bytes();
|
||||
hasher.update(path.len().to_ne_bytes());
|
||||
hasher.update(path);
|
||||
});
|
||||
}
|
||||
|
||||
impl Program {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.body.len().to_ne_bytes());
|
||||
for body_item in slf.body.iter_mut() {
|
||||
hasher.update(body_item.compute_digest());
|
||||
}
|
||||
for attr in &mut slf.inner_attrs {
|
||||
hasher.update(attr.compute_digest());
|
||||
}
|
||||
if let Some(shebang) = &slf.shebang {
|
||||
hasher.update(&shebang.inner.content);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl Annotation {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
let mut hasher = Sha256::new();
|
||||
if let Some(name) = &mut self.name {
|
||||
hasher.update(name.compute_digest());
|
||||
}
|
||||
if let Some(properties) = &mut self.properties {
|
||||
hasher.update(properties.len().to_ne_bytes());
|
||||
for property in properties.iter_mut() {
|
||||
hasher.update(property.compute_digest());
|
||||
}
|
||||
} else {
|
||||
hasher.update("no_properties");
|
||||
}
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl BodyItem {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(match self {
|
||||
BodyItem::ImportStatement(s) => s.compute_digest(),
|
||||
BodyItem::ExpressionStatement(es) => es.compute_digest(),
|
||||
BodyItem::VariableDeclaration(vs) => vs.compute_digest(),
|
||||
BodyItem::ReturnStatement(rs) => rs.compute_digest(),
|
||||
});
|
||||
|
||||
for a in self.get_attrs_mut() {
|
||||
hasher.update(a.compute_digest());
|
||||
}
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Expr {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
Expr::Literal(lit) => lit.compute_digest(),
|
||||
Expr::Identifier(id) => id.compute_digest(),
|
||||
Expr::TagDeclarator(tag) => tag.compute_digest(),
|
||||
Expr::BinaryExpression(be) => be.compute_digest(),
|
||||
Expr::FunctionExpression(fe) => fe.compute_digest(),
|
||||
Expr::CallExpression(ce) => ce.compute_digest(),
|
||||
Expr::CallExpressionKw(ce) => ce.compute_digest(),
|
||||
Expr::PipeExpression(pe) => pe.compute_digest(),
|
||||
Expr::PipeSubstitution(ps) => ps.compute_digest(),
|
||||
Expr::ArrayExpression(ae) => ae.compute_digest(),
|
||||
Expr::ArrayRangeExpression(are) => are.compute_digest(),
|
||||
Expr::ObjectExpression(oe) => oe.compute_digest(),
|
||||
Expr::MemberExpression(me) => me.compute_digest(),
|
||||
Expr::UnaryExpression(ue) => ue.compute_digest(),
|
||||
Expr::IfExpression(e) => e.compute_digest(),
|
||||
Expr::LabelledExpression(e) => e.compute_digest(),
|
||||
Expr::AscribedExpression(e) => e.compute_digest(),
|
||||
Expr::None(_) => {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(b"Value::None");
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BinaryPart {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
BinaryPart::Literal(lit) => lit.compute_digest(),
|
||||
BinaryPart::Identifier(id) => id.compute_digest(),
|
||||
BinaryPart::BinaryExpression(be) => be.compute_digest(),
|
||||
BinaryPart::CallExpression(ce) => ce.compute_digest(),
|
||||
BinaryPart::CallExpressionKw(ce) => ce.compute_digest(),
|
||||
BinaryPart::UnaryExpression(ue) => ue.compute_digest(),
|
||||
BinaryPart::MemberExpression(me) => me.compute_digest(),
|
||||
BinaryPart::IfExpression(e) => e.compute_digest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MemberObject {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
MemberObject::MemberExpression(me) => me.compute_digest(),
|
||||
MemberObject::Identifier(id) => id.compute_digest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LiteralIdentifier {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
match self {
|
||||
LiteralIdentifier::Identifier(id) => id.compute_digest(),
|
||||
LiteralIdentifier::Literal(lit) => lit.compute_digest(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Type {
|
||||
pub fn compute_digest(&mut self) -> Digest {
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
match self {
|
||||
Type::Primitive(prim) => {
|
||||
hasher.update(b"FnArgType::Primitive");
|
||||
hasher.update(prim.digestable_id())
|
||||
}
|
||||
Type::Array(prim) => {
|
||||
hasher.update(b"FnArgType::Array");
|
||||
hasher.update(prim.digestable_id())
|
||||
}
|
||||
Type::Object { properties } => {
|
||||
hasher.update(b"FnArgType::Object");
|
||||
hasher.update(properties.len().to_ne_bytes());
|
||||
for prop in properties.iter_mut() {
|
||||
hasher.update(prop.compute_digest());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hasher.finalize().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Parameter {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.identifier.compute_digest());
|
||||
match &mut slf.type_ {
|
||||
Some(arg) => {
|
||||
hasher.update(b"Parameter::type_::Some");
|
||||
hasher.update(arg.compute_digest())
|
||||
}
|
||||
None => {
|
||||
hasher.update(b"Parameter::type_::None");
|
||||
}
|
||||
}
|
||||
match slf.default_value {
|
||||
None => hasher.update(vec![0]),
|
||||
Some(DefaultParamVal::KclNone(ref _kcl_none)) => hasher.update(vec![1]),
|
||||
Some(DefaultParamVal::Literal(ref mut literal)) => hasher.update(literal.compute_digest()),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl KclNone {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(b"KclNone");
|
||||
});
|
||||
}
|
||||
|
||||
impl FunctionExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.params.len().to_ne_bytes());
|
||||
for param in slf.params.iter_mut() {
|
||||
hasher.update(param.compute_digest());
|
||||
}
|
||||
hasher.update(slf.body.compute_digest());
|
||||
match &mut slf.return_type {
|
||||
Some(rt) => {
|
||||
hasher.update(b"FunctionExpression::return_type::Some");
|
||||
hasher.update(rt.compute_digest());
|
||||
}
|
||||
None => {
|
||||
hasher.update(b"FunctionExpression::return_type::None");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ReturnStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.argument.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl ExpressionStatement {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.expression.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl VariableDeclaration {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.declaration.compute_digest());
|
||||
hasher.update(slf.visibility.digestable_id());
|
||||
hasher.update(slf.kind.digestable_id());
|
||||
});
|
||||
}
|
||||
|
||||
impl VariableKind {
|
||||
fn digestable_id(&self) -> [u8; 1] {
|
||||
match self {
|
||||
VariableKind::Const => [2],
|
||||
VariableKind::Fn => [3],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ItemVisibility {
|
||||
fn digestable_id(&self) -> [u8; 1] {
|
||||
match self {
|
||||
ItemVisibility::Default => [0],
|
||||
ItemVisibility::Export => [1],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VariableDeclarator {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.id.compute_digest());
|
||||
hasher.update(slf.init.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl Literal {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.value.digestable_id());
|
||||
});
|
||||
}
|
||||
|
||||
impl LiteralValue {
|
||||
fn digestable_id(&self) -> Vec<u8> {
|
||||
match self {
|
||||
LiteralValue::Number { value, suffix } => {
|
||||
let mut result: Vec<u8> = value.to_ne_bytes().into();
|
||||
result.extend((*suffix as u32).to_ne_bytes());
|
||||
result
|
||||
}
|
||||
LiteralValue::String(st) => st.as_bytes().into(),
|
||||
LiteralValue::Bool(b) => {
|
||||
if *b {
|
||||
vec![1]
|
||||
} else {
|
||||
vec![0]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Identifier {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
});
|
||||
}
|
||||
|
||||
impl TagDeclarator {
|
||||
compute_digest!(|slf, hasher| {
|
||||
let name = slf.name.as_bytes();
|
||||
hasher.update(name.len().to_ne_bytes());
|
||||
hasher.update(name);
|
||||
});
|
||||
}
|
||||
|
||||
impl PipeSubstitution {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(b"PipeSubstitution");
|
||||
});
|
||||
}
|
||||
|
||||
impl ArrayExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.elements.len().to_ne_bytes());
|
||||
for value in slf.elements.iter_mut() {
|
||||
hasher.update(value.compute_digest());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ArrayRangeExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.start_element.compute_digest());
|
||||
hasher.update(slf.end_element.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl ObjectExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.properties.len().to_ne_bytes());
|
||||
for prop in slf.properties.iter_mut() {
|
||||
hasher.update(prop.compute_digest());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl ObjectProperty {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.key.compute_digest());
|
||||
hasher.update(slf.value.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl MemberExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.object.compute_digest());
|
||||
hasher.update(slf.property.compute_digest());
|
||||
hasher.update(if slf.computed { [1] } else { [0] });
|
||||
});
|
||||
}
|
||||
|
||||
impl BinaryExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.operator.digestable_id());
|
||||
hasher.update(slf.left.compute_digest());
|
||||
hasher.update(slf.right.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl UnaryExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.operator.digestable_id());
|
||||
hasher.update(slf.argument.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl LabelledExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.expr.compute_digest());
|
||||
hasher.update(slf.label.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl Ascription {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.expr.compute_digest());
|
||||
hasher.update(slf.ty.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
impl PipeExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.body.len().to_ne_bytes());
|
||||
for value in slf.body.iter_mut() {
|
||||
hasher.update(value.compute_digest());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl CallExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.callee.compute_digest());
|
||||
hasher.update(slf.arguments.len().to_ne_bytes());
|
||||
for argument in slf.arguments.iter_mut() {
|
||||
hasher.update(argument.compute_digest());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl CallExpressionKw {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.callee.compute_digest());
|
||||
if let Some(ref mut unlabeled) = slf.unlabeled {
|
||||
hasher.update(unlabeled.compute_digest());
|
||||
} else {
|
||||
hasher.update("no_unlabeled");
|
||||
}
|
||||
hasher.update(slf.arguments.len().to_ne_bytes());
|
||||
for argument in slf.arguments.iter_mut() {
|
||||
hasher.update(argument.label.compute_digest());
|
||||
hasher.update(argument.arg.compute_digest());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
impl IfExpression {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.cond.compute_digest());
|
||||
hasher.update(slf.then_val.compute_digest());
|
||||
for else_if in &mut slf.else_ifs {
|
||||
hasher.update(else_if.compute_digest());
|
||||
}
|
||||
hasher.update(slf.final_else.compute_digest());
|
||||
});
|
||||
}
|
||||
impl ElseIf {
|
||||
compute_digest!(|slf, hasher| {
|
||||
hasher.update(slf.cond.compute_digest());
|
||||
hasher.update(slf.then_val.compute_digest());
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_parse_digest() {
|
||||
let prog1_string = r#"startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([5, 5], %)
|
||||
"#;
|
||||
let prog1_digest = crate::parsing::top_level_parse(prog1_string).unwrap().compute_digest();
|
||||
|
||||
let prog2_string = r#"startSketchOn('XY')
|
||||
|> startProfileAt([0, 2], %)
|
||||
|> line([5, 5], %)
|
||||
"#;
|
||||
let prog2_digest = crate::parsing::top_level_parse(prog2_string).unwrap().compute_digest();
|
||||
|
||||
assert!(prog1_digest != prog2_digest);
|
||||
|
||||
let prog3_string = r#"startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([5, 5], %)
|
||||
"#;
|
||||
let prog3_digest = crate::parsing::top_level_parse(prog3_string).unwrap().compute_digest();
|
||||
|
||||
assert_eq!(prog1_digest, prog3_digest);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_annotations_digest() {
|
||||
// Settings annotations should be included in the digest.
|
||||
let prog1_string = r#"@settings(defaultLengthUnit = in)
|
||||
startSketchOn('XY')
|
||||
"#;
|
||||
let prog1_digest = crate::parsing::top_level_parse(prog1_string).unwrap().compute_digest();
|
||||
|
||||
let prog2_string = r#"@settings(defaultLengthUnit = mm)
|
||||
startSketchOn('XY')
|
||||
"#;
|
||||
let prog2_digest = crate::parsing::top_level_parse(prog2_string).unwrap().compute_digest();
|
||||
|
||||
assert!(prog1_digest != prog2_digest);
|
||||
}
|
||||
}
|
77
rust/kcl-lib/src/parsing/ast/mod.rs
Normal file
77
rust/kcl-lib/src/parsing/ast/mod.rs
Normal file
@ -0,0 +1,77 @@
|
||||
pub(crate) mod digest;
|
||||
pub mod modify;
|
||||
pub mod types;
|
||||
|
||||
use crate::{
|
||||
parsing::ast::types::{BinaryPart, BodyItem, Expr, LiteralIdentifier, MemberObject},
|
||||
ModuleId,
|
||||
};
|
||||
|
||||
impl BodyItem {
|
||||
pub fn module_id(&self) -> ModuleId {
|
||||
match self {
|
||||
BodyItem::ImportStatement(stmt) => stmt.module_id,
|
||||
BodyItem::ExpressionStatement(expression_statement) => expression_statement.module_id,
|
||||
BodyItem::VariableDeclaration(variable_declaration) => variable_declaration.module_id,
|
||||
BodyItem::ReturnStatement(return_statement) => return_statement.module_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Expr {
|
||||
pub fn module_id(&self) -> ModuleId {
|
||||
match self {
|
||||
Expr::Literal(literal) => literal.module_id,
|
||||
Expr::Identifier(identifier) => identifier.module_id,
|
||||
Expr::TagDeclarator(tag) => tag.module_id,
|
||||
Expr::BinaryExpression(binary_expression) => binary_expression.module_id,
|
||||
Expr::FunctionExpression(function_expression) => function_expression.module_id,
|
||||
Expr::CallExpression(call_expression) => call_expression.module_id,
|
||||
Expr::CallExpressionKw(call_expression) => call_expression.module_id,
|
||||
Expr::PipeExpression(pipe_expression) => pipe_expression.module_id,
|
||||
Expr::PipeSubstitution(pipe_substitution) => pipe_substitution.module_id,
|
||||
Expr::ArrayExpression(array_expression) => array_expression.module_id,
|
||||
Expr::ArrayRangeExpression(array_range) => array_range.module_id,
|
||||
Expr::ObjectExpression(object_expression) => object_expression.module_id,
|
||||
Expr::MemberExpression(member_expression) => member_expression.module_id,
|
||||
Expr::UnaryExpression(unary_expression) => unary_expression.module_id,
|
||||
Expr::IfExpression(expr) => expr.module_id,
|
||||
Expr::LabelledExpression(expr) => expr.expr.module_id(),
|
||||
Expr::AscribedExpression(expr) => expr.expr.module_id(),
|
||||
Expr::None(none) => none.module_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BinaryPart {
|
||||
pub fn module_id(&self) -> ModuleId {
|
||||
match self {
|
||||
BinaryPart::Literal(literal) => literal.module_id,
|
||||
BinaryPart::Identifier(identifier) => identifier.module_id,
|
||||
BinaryPart::BinaryExpression(binary_expression) => binary_expression.module_id,
|
||||
BinaryPart::CallExpression(call_expression) => call_expression.module_id,
|
||||
BinaryPart::CallExpressionKw(call_expression) => call_expression.module_id,
|
||||
BinaryPart::UnaryExpression(unary_expression) => unary_expression.module_id,
|
||||
BinaryPart::MemberExpression(member_expression) => member_expression.module_id,
|
||||
BinaryPart::IfExpression(e) => e.module_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MemberObject {
|
||||
pub fn module_id(&self) -> ModuleId {
|
||||
match self {
|
||||
MemberObject::MemberExpression(member_expression) => member_expression.module_id,
|
||||
MemberObject::Identifier(identifier) => identifier.module_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LiteralIdentifier {
|
||||
pub fn module_id(&self) -> ModuleId {
|
||||
match self {
|
||||
LiteralIdentifier::Identifier(identifier) => identifier.module_id,
|
||||
LiteralIdentifier::Literal(literal) => literal.module_id,
|
||||
}
|
||||
}
|
||||
}
|
282
rust/kcl-lib/src/parsing/ast/modify.rs
Normal file
282
rust/kcl-lib/src/parsing/ast/modify.rs
Normal file
@ -0,0 +1,282 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use kcmc::{
|
||||
each_cmd as mcmd, ok_response::OkModelingCmdResponse, shared::PathCommand, websocket::OkWebSocketResponseData,
|
||||
ModelingCmd,
|
||||
};
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
|
||||
use super::types::{CallExpressionKw, Identifier, LabeledArg, LiteralValue};
|
||||
use crate::{
|
||||
engine::EngineManager,
|
||||
errors::{KclError, KclErrorDetails},
|
||||
execution::Point2d,
|
||||
parsing::ast::types::{
|
||||
ArrayExpression, CallExpression, ConstraintLevel, FormatOptions, Literal, Node, PipeExpression,
|
||||
PipeSubstitution, VariableDeclarator,
|
||||
},
|
||||
source_range::SourceRange,
|
||||
ModuleId, Program,
|
||||
};
|
||||
|
||||
type Point3d = kcmc::shared::Point3d<f64>;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The control point data for a curve or line.
|
||||
struct ControlPointData {
|
||||
/// The control points for the curve or line.
|
||||
points: Vec<Point3d>,
|
||||
/// The command that created this curve or line.
|
||||
_command: PathCommand,
|
||||
/// The id of the curve or line.
|
||||
_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
const EPSILON: f64 = 0.015625; // or 2^-6
|
||||
|
||||
/// Update the AST to reflect the new state of the program after something like
|
||||
/// a move or a new line.
|
||||
pub async fn modify_ast_for_sketch(
|
||||
engine: &Arc<Box<dyn EngineManager>>,
|
||||
program: &mut Program,
|
||||
module_id: ModuleId,
|
||||
// The name of the sketch.
|
||||
sketch_name: &str,
|
||||
// The type of plane the sketch is on. `XY` or `XZ`, etc
|
||||
plane: crate::execution::PlaneType,
|
||||
// The ID of the parent sketch.
|
||||
sketch_id: uuid::Uuid,
|
||||
) -> Result<String, KclError> {
|
||||
// First we need to check if this sketch is constrained (even partially).
|
||||
// If it is, we cannot modify it.
|
||||
|
||||
// Get the information about the sketch.
|
||||
if let Some(ast_sketch) = program.ast.get_variable(sketch_name) {
|
||||
let constraint_level = match ast_sketch {
|
||||
super::types::Definition::Variable(var) => var.get_constraint_level(),
|
||||
super::types::Definition::Import(import) => import.get_constraint_level(),
|
||||
};
|
||||
match &constraint_level {
|
||||
ConstraintLevel::None { source_ranges: _ } => {}
|
||||
ConstraintLevel::Ignore { source_ranges: _ } => {}
|
||||
ConstraintLevel::Partial {
|
||||
source_ranges: _,
|
||||
levels,
|
||||
} => {
|
||||
return Err(KclError::Engine(KclErrorDetails {
|
||||
message: format!(
|
||||
"Sketch {} is constrained `{}` and cannot be modified",
|
||||
sketch_name, constraint_level
|
||||
),
|
||||
source_ranges: levels.get_all_partial_or_full_source_ranges(),
|
||||
}));
|
||||
}
|
||||
ConstraintLevel::Full { source_ranges } => {
|
||||
return Err(KclError::Engine(KclErrorDetails {
|
||||
message: format!(
|
||||
"Sketch {} is constrained `{}` and cannot be modified",
|
||||
sketch_name, constraint_level
|
||||
),
|
||||
source_ranges: source_ranges.clone(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Let's start by getting the path info.
|
||||
|
||||
// Let's get the path info.
|
||||
let resp = engine
|
||||
.send_modeling_cmd(
|
||||
uuid::Uuid::new_v4(),
|
||||
SourceRange::default(),
|
||||
&ModelingCmd::PathGetInfo(mcmd::PathGetInfo { path_id: sketch_id }),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let OkWebSocketResponseData::Modeling {
|
||||
modeling_response: OkModelingCmdResponse::PathGetInfo(path_info),
|
||||
} = &resp
|
||||
else {
|
||||
return Err(KclError::Engine(KclErrorDetails {
|
||||
message: format!("Get path info response was not as expected: {:?}", resp),
|
||||
source_ranges: vec![SourceRange::default()],
|
||||
}));
|
||||
};
|
||||
|
||||
// Now let's get the control points for all the segments.
|
||||
// TODO: We should probably await all these at once so we aren't going one by one.
|
||||
// But I guess this is fine for now.
|
||||
// We absolutely have to preserve the order of the control points.
|
||||
let mut control_points = Vec::new();
|
||||
for segment in &path_info.segments {
|
||||
if let Some(command_id) = &segment.command_id {
|
||||
let cmd = ModelingCmd::from(mcmd::CurveGetControlPoints {
|
||||
curve_id: (*command_id).into(),
|
||||
});
|
||||
let h = engine.send_modeling_cmd(uuid::Uuid::new_v4(), SourceRange::default(), &cmd);
|
||||
|
||||
let OkWebSocketResponseData::Modeling {
|
||||
modeling_response: OkModelingCmdResponse::CurveGetControlPoints(data),
|
||||
} = h.await?
|
||||
else {
|
||||
return Err(KclError::Engine(KclErrorDetails {
|
||||
message: format!("Curve get control points response was not as expected: {:?}", resp),
|
||||
source_ranges: vec![SourceRange::default()],
|
||||
}));
|
||||
};
|
||||
|
||||
control_points.push(ControlPointData {
|
||||
points: data.control_points.clone(),
|
||||
_command: segment.command,
|
||||
_id: (*command_id).into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if control_points.is_empty() {
|
||||
return Err(KclError::Engine(KclErrorDetails {
|
||||
message: format!("No control points found for sketch {}", sketch_name),
|
||||
source_ranges: vec![SourceRange::default()],
|
||||
}));
|
||||
}
|
||||
|
||||
let first_control_points = control_points.first().ok_or_else(|| {
|
||||
KclError::Engine(KclErrorDetails {
|
||||
message: format!("No control points found for sketch {}", sketch_name),
|
||||
source_ranges: vec![SourceRange::default()],
|
||||
})
|
||||
})?;
|
||||
|
||||
let mut additional_lines = Vec::new();
|
||||
let mut last_point = first_control_points.points[1];
|
||||
for control_point in control_points[1..].iter() {
|
||||
additional_lines.push([
|
||||
(control_point.points[1].x - last_point.x),
|
||||
(control_point.points[1].y - last_point.y),
|
||||
]);
|
||||
last_point = Point3d {
|
||||
x: control_point.points[1].x,
|
||||
y: control_point.points[1].y,
|
||||
z: control_point.points[1].z,
|
||||
};
|
||||
}
|
||||
|
||||
// Okay now let's recalculate the sketch from the control points.
|
||||
let start_sketch_at_end = Point3d {
|
||||
x: (first_control_points.points[1].x - first_control_points.points[0].x),
|
||||
y: (first_control_points.points[1].y - first_control_points.points[0].y),
|
||||
z: (first_control_points.points[1].z - first_control_points.points[0].z),
|
||||
};
|
||||
let sketch = create_start_sketch_on(
|
||||
sketch_name,
|
||||
[first_control_points.points[0].x, first_control_points.points[0].y],
|
||||
[start_sketch_at_end.x, start_sketch_at_end.y],
|
||||
plane,
|
||||
additional_lines,
|
||||
)?;
|
||||
|
||||
// Add the sketch back to the program.
|
||||
program.ast.replace_variable(sketch_name, sketch);
|
||||
|
||||
let recasted = program.ast.recast(&FormatOptions::default(), 0);
|
||||
|
||||
// Re-parse the ast so we get the correct source ranges.
|
||||
program.ast = crate::parsing::parse_str(&recasted, module_id).parse_errs_as_err()?;
|
||||
|
||||
Ok(recasted)
|
||||
}
|
||||
|
||||
/// Create a pipe expression that starts a sketch at the given point and draws a line to the given point.
|
||||
fn create_start_sketch_on(
|
||||
name: &str,
|
||||
start: [f64; 2],
|
||||
end: [f64; 2],
|
||||
plane: crate::execution::PlaneType,
|
||||
additional_lines: Vec<[f64; 2]>,
|
||||
) -> Result<Node<VariableDeclarator>, KclError> {
|
||||
let start_sketch_on = CallExpression::new("startSketchOn", vec![Literal::new(plane.to_string().into()).into()])?;
|
||||
let start_profile_at = CallExpression::new(
|
||||
"startProfileAt",
|
||||
vec![
|
||||
ArrayExpression::new(vec![
|
||||
Literal::new(LiteralValue::from_f64_no_uom(round_before_recast(start[0]))).into(),
|
||||
Literal::new(LiteralValue::from_f64_no_uom(round_before_recast(start[1]))).into(),
|
||||
])
|
||||
.into(),
|
||||
PipeSubstitution::new().into(),
|
||||
],
|
||||
)?;
|
||||
|
||||
// Keep track of where we are so we can close the sketch if we need to.
|
||||
let mut current_position = Point2d {
|
||||
x: start[0],
|
||||
y: start[1],
|
||||
};
|
||||
current_position.x += end[0];
|
||||
current_position.y += end[1];
|
||||
|
||||
let expr = ArrayExpression::new(vec![
|
||||
Literal::new(LiteralValue::from_f64_no_uom(round_before_recast(end[0]))).into(),
|
||||
Literal::new(LiteralValue::from_f64_no_uom(round_before_recast(end[1]))).into(),
|
||||
])
|
||||
.into();
|
||||
let initial_line = CallExpressionKw::new(
|
||||
"line",
|
||||
None,
|
||||
vec![LabeledArg {
|
||||
label: super::types::Identifier {
|
||||
name: "end".to_owned(),
|
||||
digest: None,
|
||||
},
|
||||
arg: expr,
|
||||
}],
|
||||
)?;
|
||||
|
||||
let mut pipe_body = vec![start_sketch_on.into(), start_profile_at.into(), initial_line.into()];
|
||||
|
||||
for (index, line) in additional_lines.iter().enumerate() {
|
||||
current_position.x += line[0];
|
||||
current_position.y += line[1];
|
||||
|
||||
// If we are on the last line, check if we have to close the sketch.
|
||||
if index == additional_lines.len() - 1 {
|
||||
let diff_x = (current_position.x - start[0]).abs();
|
||||
let diff_y = (current_position.y - start[1]).abs();
|
||||
// Compare the end of the last line to the start of the first line.
|
||||
// This is a bit more lenient if you look at the value of epsilon.
|
||||
if diff_x <= EPSILON && diff_y <= EPSILON {
|
||||
// We have to close the sketch.
|
||||
let close = CallExpressionKw::new("close", None, vec![])?;
|
||||
pipe_body.push(close.into());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: we should check if we should close the sketch.
|
||||
let expr = ArrayExpression::new(vec![
|
||||
Literal::new(LiteralValue::from_f64_no_uom(round_before_recast(line[0]))).into(),
|
||||
Literal::new(LiteralValue::from_f64_no_uom(round_before_recast(line[1]))).into(),
|
||||
])
|
||||
.into();
|
||||
let line = CallExpressionKw::new(
|
||||
"line",
|
||||
None,
|
||||
vec![LabeledArg {
|
||||
arg: expr,
|
||||
label: Identifier {
|
||||
name: "end".to_owned(),
|
||||
digest: None,
|
||||
},
|
||||
}],
|
||||
)?;
|
||||
pipe_body.push(line.into());
|
||||
}
|
||||
|
||||
Ok(VariableDeclarator::new(name, PipeExpression::new(pipe_body).into()))
|
||||
}
|
||||
|
||||
fn round_before_recast(num: f64) -> f64 {
|
||||
// We use 2 decimal places.
|
||||
(num * 100.0).round() / 100.0
|
||||
}
|
102
rust/kcl-lib/src/parsing/ast/types/condition.rs
Normal file
102
rust/kcl-lib/src/parsing/ast/types/condition.rs
Normal file
@ -0,0 +1,102 @@
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{BoxNode, ConstraintLevel, Digest, Expr, Hover, Node, NodeList};
|
||||
use crate::SourceRange;
|
||||
|
||||
// TODO: This should be its own type, similar to Program,
|
||||
// but guaranteed to have an Expression as its final item.
|
||||
// https://github.com/KittyCAD/modeling-app/issues/4015
|
||||
type IfBlock = crate::parsing::ast::types::Program;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(tag = "type")]
|
||||
pub struct IfExpression {
|
||||
pub cond: Box<Expr>,
|
||||
pub then_val: BoxNode<IfBlock>,
|
||||
pub else_ifs: NodeList<ElseIf>,
|
||||
pub final_else: BoxNode<IfBlock>,
|
||||
|
||||
pub digest: Option<Digest>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(tag = "type")]
|
||||
pub struct ElseIf {
|
||||
pub cond: Expr,
|
||||
pub then_val: BoxNode<IfBlock>,
|
||||
|
||||
pub digest: Option<Digest>,
|
||||
}
|
||||
|
||||
// Source code metadata
|
||||
|
||||
impl Node<IfExpression> {
|
||||
fn source_ranges(&self) -> Vec<SourceRange> {
|
||||
vec![SourceRange::from(self)]
|
||||
}
|
||||
}
|
||||
|
||||
impl Node<ElseIf> {
|
||||
#[allow(dead_code)]
|
||||
fn source_ranges(&self) -> Vec<SourceRange> {
|
||||
vec![SourceRange::new(self.start, self.end, self.module_id)]
|
||||
}
|
||||
}
|
||||
|
||||
// IDE support and refactors
|
||||
|
||||
impl Node<IfExpression> {
|
||||
/// Get the constraint level.
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
ConstraintLevel::Full {
|
||||
source_ranges: self.source_ranges(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IfExpression {
|
||||
pub fn get_hover_value_for_position(&self, pos: usize, code: &str) -> Option<Hover> {
|
||||
self.cond
|
||||
.get_hover_value_for_position(pos, code)
|
||||
.or_else(|| self.then_val.get_hover_value_for_position(pos, code))
|
||||
.or_else(|| {
|
||||
self.else_ifs
|
||||
.iter()
|
||||
.find_map(|else_if| else_if.get_hover_value_for_position(pos, code))
|
||||
})
|
||||
.or_else(|| self.final_else.get_hover_value_for_position(pos, code))
|
||||
}
|
||||
|
||||
/// Rename all identifiers that have the old name to the new given name.
|
||||
pub fn rename_identifiers(&mut self, old_name: &str, new_name: &str) {
|
||||
self.cond.rename_identifiers(old_name, new_name);
|
||||
self.then_val.rename_identifiers(old_name, new_name);
|
||||
for else_if in &mut self.else_ifs {
|
||||
else_if.rename_identifiers(old_name, new_name);
|
||||
}
|
||||
self.final_else.rename_identifiers(old_name, new_name);
|
||||
}
|
||||
|
||||
pub fn replace_value(&mut self, source_range: SourceRange, new_value: Expr) {
|
||||
self.cond.replace_value(source_range, new_value.clone());
|
||||
for else_if in &mut self.else_ifs {
|
||||
else_if.cond.replace_value(source_range, new_value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ElseIf {
|
||||
fn get_hover_value_for_position(&self, pos: usize, code: &str) -> Option<Hover> {
|
||||
self.cond
|
||||
.get_hover_value_for_position(pos, code)
|
||||
.or_else(|| self.then_val.get_hover_value_for_position(pos, code))
|
||||
}
|
||||
/// Rename all identifiers that have the old name to the new given name.
|
||||
fn rename_identifiers(&mut self, old_name: &str, new_name: &str) {
|
||||
self.cond.rename_identifiers(old_name, new_name);
|
||||
self.then_val.rename_identifiers(old_name, new_name);
|
||||
}
|
||||
}
|
74
rust/kcl-lib/src/parsing/ast/types/literal_value.rs
Normal file
74
rust/kcl-lib/src/parsing/ast/types/literal_value.rs
Normal file
@ -0,0 +1,74 @@
|
||||
use std::fmt;
|
||||
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::Node;
|
||||
use crate::parsing::{
|
||||
ast::types::{Expr, Literal},
|
||||
token::NumericSuffix,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(untagged, rename_all = "snake_case")]
|
||||
pub enum LiteralValue {
|
||||
Number { value: f64, suffix: NumericSuffix },
|
||||
String(String),
|
||||
Bool(bool),
|
||||
}
|
||||
|
||||
impl LiteralValue {
|
||||
pub fn from_f64_no_uom(value: f64) -> Self {
|
||||
LiteralValue::Number {
|
||||
value,
|
||||
suffix: NumericSuffix::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for LiteralValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
LiteralValue::Number { value, suffix } => {
|
||||
let int_value = *value as u64;
|
||||
if int_value as f64 == *value {
|
||||
write!(f, "{int_value}")?;
|
||||
} else {
|
||||
write!(f, "{value}")?;
|
||||
}
|
||||
if *suffix != NumericSuffix::None {
|
||||
write!(f, "{suffix}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
LiteralValue::String(s) => write!(f, "\"{s}\""),
|
||||
LiteralValue::Bool(b) => write!(f, "{b}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Node<Literal>> for Expr {
|
||||
fn from(literal: Node<Literal>) -> Self {
|
||||
Expr::Literal(Box::new(literal))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for LiteralValue {
|
||||
fn from(value: String) -> Self {
|
||||
Self::String(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for LiteralValue {
|
||||
fn from(value: &'static str) -> Self {
|
||||
// TODO: Make this Cow<str>
|
||||
Self::String(value.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bool> for LiteralValue {
|
||||
fn from(value: bool) -> Self {
|
||||
Self::Bool(value)
|
||||
}
|
||||
}
|
4110
rust/kcl-lib/src/parsing/ast/types/mod.rs
Normal file
4110
rust/kcl-lib/src/parsing/ast/types/mod.rs
Normal file
File diff suppressed because it is too large
Load Diff
105
rust/kcl-lib/src/parsing/ast/types/none.rs
Normal file
105
rust/kcl-lib/src/parsing/ast/types/none.rs
Normal file
@ -0,0 +1,105 @@
|
||||
//! KCL has optional parameters. Their type is [`KclOption`].
|
||||
//! If an optional parameter is not given, it will have a value of type [`KclNone`].
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{super::digest::Digest, Node};
|
||||
use crate::{execution::KclValue, parsing::ast::types::ConstraintLevel};
|
||||
|
||||
const KCL_NONE_ID: &str = "KCL_NONE_ID";
|
||||
|
||||
/// KCL value for an optional parameter which was not given an argument.
|
||||
/// (remember, parameters are in the function declaration,
|
||||
/// arguments are in the function call/application).
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Default, Copy)]
|
||||
#[ts(export)]
|
||||
#[serde(tag = "type")]
|
||||
pub struct KclNone {
|
||||
#[serde(deserialize_with = "deser_private")]
|
||||
#[ts(skip)]
|
||||
#[schemars(skip)]
|
||||
__private: Private,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub digest: Option<Digest>,
|
||||
}
|
||||
|
||||
impl KclNone {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
__private: Private {},
|
||||
digest: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
struct Private;
|
||||
|
||||
impl Serialize for Private {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(KCL_NONE_ID)
|
||||
}
|
||||
}
|
||||
|
||||
fn deser_private<'de, D>(deserializer: D) -> Result<Private, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
if s == KCL_NONE_ID {
|
||||
Ok(Private {})
|
||||
} else {
|
||||
Err(serde::de::Error::custom("not a KCL none"))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&KclNone> for KclValue {
|
||||
fn from(none: &KclNone) -> Self {
|
||||
KclValue::KclNone {
|
||||
value: *none,
|
||||
meta: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Node<KclNone>> for KclValue {
|
||||
fn from(none: &Node<KclNone>) -> Self {
|
||||
Self::from(&none.inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl Node<KclNone> {
|
||||
/// Get the constraint level.
|
||||
/// KCL None is never constrained.
|
||||
pub fn get_constraint_level(&self) -> ConstraintLevel {
|
||||
ConstraintLevel::None {
|
||||
source_ranges: self.as_source_ranges(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn other_types_will_not_deserialize() {
|
||||
// This shouldn't deserialize into a KCL None,
|
||||
// because it's missing the special Private tag.
|
||||
let j = r#"{"start": 0, "end": 0}"#;
|
||||
let _e = serde_json::from_str::<KclNone>(j).unwrap_err();
|
||||
}
|
||||
#[test]
|
||||
fn serialize_then_deserialize() {
|
||||
// Serializing, then deserializing a None should produce the same value.
|
||||
let before = KclNone::default();
|
||||
let j = serde_json::to_string_pretty(&before).unwrap();
|
||||
let after: KclNone = serde_json::from_str(&j).unwrap();
|
||||
assert_eq!(before, after);
|
||||
}
|
||||
}
|
187
rust/kcl-lib/src/parsing/math.rs
Normal file
187
rust/kcl-lib/src/parsing/math.rs
Normal file
@ -0,0 +1,187 @@
|
||||
// TODO optimise size of CompilationError
|
||||
#![allow(clippy::result_large_err)]
|
||||
|
||||
use super::CompilationError;
|
||||
use crate::{
|
||||
parsing::ast::types::{BinaryExpression, BinaryOperator, BinaryPart, Node},
|
||||
SourceRange,
|
||||
};
|
||||
|
||||
/// Parses a list of tokens (in infix order, i.e. as the user typed them)
|
||||
/// into a binary expression tree.
|
||||
pub fn parse(infix_tokens: Vec<BinaryExpressionToken>) -> Result<Node<BinaryExpression>, CompilationError> {
|
||||
let rpn = postfix(infix_tokens);
|
||||
evaluate(rpn)
|
||||
}
|
||||
|
||||
/// Parses a list of tokens (in postfix order) into a binary expression tree.
|
||||
fn evaluate(rpn: Vec<BinaryExpressionToken>) -> Result<Node<BinaryExpression>, CompilationError> {
|
||||
let source_range = source_range(&rpn);
|
||||
let mut operand_stack: Vec<BinaryPart> = Vec::new();
|
||||
let e = CompilationError::fatal(source_range, "error parsing binary math expressions");
|
||||
for item in rpn {
|
||||
let expr = match item {
|
||||
BinaryExpressionToken::Operator(operator) => {
|
||||
let Some(right) = operand_stack.pop() else {
|
||||
return Err(e);
|
||||
};
|
||||
let Some(left) = operand_stack.pop() else {
|
||||
return Err(e);
|
||||
};
|
||||
let start = left.start();
|
||||
let end = right.end();
|
||||
let module_id = left.module_id();
|
||||
|
||||
BinaryPart::BinaryExpression(Node::boxed(
|
||||
BinaryExpression {
|
||||
operator,
|
||||
left,
|
||||
right,
|
||||
digest: None,
|
||||
},
|
||||
start,
|
||||
end,
|
||||
module_id,
|
||||
))
|
||||
}
|
||||
BinaryExpressionToken::Operand(o) => o,
|
||||
};
|
||||
operand_stack.push(expr)
|
||||
}
|
||||
if let Some(BinaryPart::BinaryExpression(expr)) = operand_stack.pop() {
|
||||
Ok(*expr)
|
||||
} else {
|
||||
// If this branch is used, the evaluation algorithm has a bug and must be fixed.
|
||||
// This is a programmer error, not a user error.
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
fn source_range(tokens: &[BinaryExpressionToken]) -> SourceRange {
|
||||
let sources: Vec<_> = tokens
|
||||
.iter()
|
||||
.filter_map(|op| match op {
|
||||
BinaryExpressionToken::Operator(_) => None,
|
||||
BinaryExpressionToken::Operand(o) => Some((o.start(), o.end(), o.module_id())),
|
||||
})
|
||||
.collect();
|
||||
match (sources.first(), sources.last()) {
|
||||
(Some((start, _, module_id)), Some((_, end, _))) => SourceRange::new(*start, *end, *module_id),
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Reorders tokens from infix order to postfix order.
|
||||
fn postfix(infix: Vec<BinaryExpressionToken>) -> Vec<BinaryExpressionToken> {
|
||||
let mut operator_stack: Vec<BinaryOperator> = Vec::with_capacity(infix.len());
|
||||
let mut output = Vec::with_capacity(infix.len());
|
||||
for token in infix {
|
||||
match token {
|
||||
BinaryExpressionToken::Operator(o1) => {
|
||||
// From https://en.wikipedia.org/wiki/Shunting_yard_algorithm:
|
||||
// while (
|
||||
// there is an operator o2 at the top of the operator stack which is not a left parenthesis,
|
||||
// and (o2 has greater precedence than o1 or (o1 and o2 have the same precedence and o1 is left-associative))
|
||||
// )
|
||||
// pop o2 from the operator stack into the output queue
|
||||
while let Some(o2) = operator_stack.pop() {
|
||||
if (o2.precedence() > o1.precedence())
|
||||
|| o1.precedence() == o2.precedence() && o1.associativity().is_left()
|
||||
{
|
||||
output.push(BinaryExpressionToken::Operator(o2));
|
||||
} else {
|
||||
operator_stack.push(o2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
operator_stack.push(o1);
|
||||
}
|
||||
o @ BinaryExpressionToken::Operand(_) => output.push(o),
|
||||
}
|
||||
}
|
||||
// After the while loop, pop the remaining items from the operator stack into the output queue.
|
||||
output.extend(operator_stack.into_iter().rev().map(BinaryExpressionToken::Operator));
|
||||
output
|
||||
}
|
||||
|
||||
/// Expressions are made up of operators and operands.
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum BinaryExpressionToken {
|
||||
Operator(BinaryOperator),
|
||||
Operand(BinaryPart),
|
||||
}
|
||||
|
||||
impl From<BinaryPart> for BinaryExpressionToken {
|
||||
fn from(value: BinaryPart) -> Self {
|
||||
Self::Operand(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BinaryOperator> for BinaryExpressionToken {
|
||||
fn from(value: BinaryOperator) -> Self {
|
||||
Self::Operator(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
parsing::{
|
||||
ast::types::{Literal, LiteralValue},
|
||||
token::NumericSuffix,
|
||||
},
|
||||
ModuleId,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn parse_and_evaluate() {
|
||||
/// Make a literal
|
||||
fn lit(n: u8) -> BinaryPart {
|
||||
BinaryPart::Literal(Box::new(Node::new(
|
||||
Literal {
|
||||
value: LiteralValue::Number {
|
||||
value: n as f64,
|
||||
suffix: NumericSuffix::None,
|
||||
},
|
||||
raw: n.to_string(),
|
||||
digest: None,
|
||||
},
|
||||
0,
|
||||
0,
|
||||
ModuleId::default(),
|
||||
)))
|
||||
}
|
||||
let tests: Vec<Vec<BinaryExpressionToken>> = vec![
|
||||
// 3 + 4 × 2 ÷ ( 1 − 5 ) ^ 2 ^ 3
|
||||
vec![
|
||||
lit(3).into(),
|
||||
BinaryOperator::Add.into(),
|
||||
lit(4).into(),
|
||||
BinaryOperator::Mul.into(),
|
||||
lit(2).into(),
|
||||
BinaryOperator::Div.into(),
|
||||
BinaryPart::BinaryExpression(Node::boxed(
|
||||
BinaryExpression {
|
||||
operator: BinaryOperator::Sub,
|
||||
left: lit(1),
|
||||
right: lit(5),
|
||||
digest: None,
|
||||
},
|
||||
0,
|
||||
0,
|
||||
ModuleId::default(),
|
||||
))
|
||||
.into(),
|
||||
BinaryOperator::Pow.into(),
|
||||
lit(2).into(),
|
||||
BinaryOperator::Pow.into(),
|
||||
lit(3).into(),
|
||||
],
|
||||
];
|
||||
for infix_input in tests {
|
||||
let rpn = postfix(infix_input);
|
||||
let _tree = evaluate(rpn).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
162
rust/kcl-lib/src/parsing/mod.rs
Normal file
162
rust/kcl-lib/src/parsing/mod.rs
Normal file
@ -0,0 +1,162 @@
|
||||
use crate::{
|
||||
errors::{CompilationError, KclError, KclErrorDetails},
|
||||
parsing::{
|
||||
ast::types::{Node, Program},
|
||||
token::TokenStream,
|
||||
},
|
||||
source_range::SourceRange,
|
||||
ModuleId,
|
||||
};
|
||||
|
||||
pub(crate) mod ast;
|
||||
mod math;
|
||||
pub(crate) mod parser;
|
||||
pub(crate) mod token;
|
||||
|
||||
pub const PIPE_SUBSTITUTION_OPERATOR: &str = "%";
|
||||
pub const PIPE_OPERATOR: &str = "|>";
|
||||
|
||||
// `?` like behavior for `Result`s to return a ParseResult if there is an error.
|
||||
macro_rules! pr_try {
|
||||
($e: expr) => {
|
||||
match $e {
|
||||
Ok(a) => a,
|
||||
Err(e) => return e.into(),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// Parse the given KCL code into an AST. This is the top-level.
|
||||
pub fn top_level_parse(code: &str) -> ParseResult {
|
||||
let module_id = ModuleId::default();
|
||||
parse_str(code, module_id)
|
||||
}
|
||||
|
||||
/// Parse the given KCL code into an AST.
|
||||
pub fn parse_str(code: &str, module_id: ModuleId) -> ParseResult {
|
||||
let tokens = pr_try!(crate::parsing::token::lex(code, module_id));
|
||||
parse_tokens(tokens)
|
||||
}
|
||||
|
||||
/// Parse the supplied tokens into an AST.
|
||||
pub fn parse_tokens(mut tokens: TokenStream) -> ParseResult {
|
||||
let unknown_tokens = tokens.remove_unknown();
|
||||
|
||||
if !unknown_tokens.is_empty() {
|
||||
let source_ranges = unknown_tokens.iter().map(SourceRange::from).collect();
|
||||
let token_list = unknown_tokens.iter().map(|t| t.value.as_str()).collect::<Vec<_>>();
|
||||
let message = if token_list.len() == 1 {
|
||||
format!("found unknown token '{}'", token_list[0])
|
||||
} else {
|
||||
format!("found unknown tokens [{}]", token_list.join(", "))
|
||||
};
|
||||
return KclError::Lexical(KclErrorDetails { source_ranges, message }).into();
|
||||
}
|
||||
|
||||
// Important, to not call this before the unknown tokens check.
|
||||
if tokens.is_empty() {
|
||||
// Empty file should just do nothing.
|
||||
return Node::<Program>::default().into();
|
||||
}
|
||||
|
||||
// Check all the tokens are whitespace or comments.
|
||||
if tokens
|
||||
.iter()
|
||||
.all(|t| t.token_type.is_whitespace() || t.token_type.is_comment())
|
||||
{
|
||||
return Node::<Program>::default().into();
|
||||
}
|
||||
|
||||
parser::run_parser(tokens.as_slice())
|
||||
}
|
||||
|
||||
/// Result of parsing.
|
||||
///
|
||||
/// Will be a KclError if there was a lexing error or some unexpected error during parsing.
|
||||
/// TODO - lexing errors should be included with the parse errors.
|
||||
/// Will be Ok otherwise, including if there were parsing errors. Any errors or warnings will
|
||||
/// be in the ParseContext. If an AST was produced, then that will be in the Option.
|
||||
///
|
||||
/// Invariants:
|
||||
/// - if there are no errors, then the Option will be Some
|
||||
/// - if the Option is None, then there will be at least one error in the ParseContext.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct ParseResult(pub Result<(Option<Node<Program>>, Vec<CompilationError>), KclError>);
|
||||
|
||||
impl ParseResult {
|
||||
#[cfg(test)]
|
||||
#[track_caller]
|
||||
pub fn unwrap(self) -> Node<Program> {
|
||||
if self.0.is_err() || self.0.as_ref().unwrap().0.is_none() {
|
||||
eprint!("{self:#?}");
|
||||
}
|
||||
self.0.unwrap().0.unwrap()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn is_ok(&self) -> bool {
|
||||
match &self.0 {
|
||||
Ok((p, errs)) => p.is_some() && !errs.iter().any(|e| e.severity.is_err()),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[track_caller]
|
||||
pub fn unwrap_errs(&self) -> impl Iterator<Item = &CompilationError> {
|
||||
self.0.as_ref().unwrap().1.iter().filter(|e| e.severity.is_err())
|
||||
}
|
||||
|
||||
/// Treat parsing errors as an Error.
|
||||
pub fn parse_errs_as_err(self) -> Result<Node<Program>, KclError> {
|
||||
let (p, errs) = self.0?;
|
||||
|
||||
if let Some(err) = errs.iter().find(|e| e.severity.is_err()) {
|
||||
return Err(KclError::Syntax(err.clone().into()));
|
||||
}
|
||||
match p {
|
||||
Some(p) => Ok(p),
|
||||
None => Err(KclError::internal("Unknown parsing error".to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Result<(Option<Node<Program>>, Vec<CompilationError>), KclError>> for ParseResult {
|
||||
fn from(r: Result<(Option<Node<Program>>, Vec<CompilationError>), KclError>) -> ParseResult {
|
||||
ParseResult(r)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<(Option<Node<Program>>, Vec<CompilationError>)> for ParseResult {
|
||||
fn from(p: (Option<Node<Program>>, Vec<CompilationError>)) -> ParseResult {
|
||||
ParseResult(Ok(p))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Node<Program>> for ParseResult {
|
||||
fn from(p: Node<Program>) -> ParseResult {
|
||||
ParseResult(Ok((Some(p), vec![])))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KclError> for ParseResult {
|
||||
fn from(e: KclError) -> ParseResult {
|
||||
ParseResult(Err(e))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
macro_rules! parse_and_lex {
|
||||
($func_name:ident, $test_kcl_program:expr) => {
|
||||
#[test]
|
||||
fn $func_name() {
|
||||
let _ = crate::parsing::top_level_parse($test_kcl_program);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
parse_and_lex!(crash_eof_1, "{\"ގގ\0\0\0\"\".");
|
||||
parse_and_lex!(crash_eof_2, "(/=e\"\u{616}ݝ\"\"");
|
||||
}
|
4932
rust/kcl-lib/src/parsing/parser.rs
Normal file
4932
rust/kcl-lib/src/parsing/parser.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,32 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 4,
|
||||
"end": 5
|
||||
},
|
||||
"start": 0,
|
||||
"end": 5
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 2,
|
||||
"end": 3
|
||||
},
|
||||
"start": 0,
|
||||
"end": 3
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "-",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 3,
|
||||
"end": 4
|
||||
},
|
||||
"start": 0,
|
||||
"end": 4
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 4,
|
||||
"end": 5
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "3",
|
||||
"start": 8,
|
||||
"end": 9
|
||||
},
|
||||
"start": 4,
|
||||
"end": 9
|
||||
},
|
||||
"start": 0,
|
||||
"end": 9
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 6,
|
||||
"end": 7
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "3",
|
||||
"start": 10,
|
||||
"end": 11
|
||||
},
|
||||
"start": 6,
|
||||
"end": 11
|
||||
},
|
||||
"start": 0,
|
||||
"end": 11
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "/",
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 6,
|
||||
"end": 7
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "3",
|
||||
"start": 10,
|
||||
"end": 11
|
||||
},
|
||||
"start": 6,
|
||||
"end": 11
|
||||
},
|
||||
"start": 0,
|
||||
"end": 11
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "4",
|
||||
"start": 16,
|
||||
"end": 17
|
||||
},
|
||||
"start": 0,
|
||||
"end": 17
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "/",
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 6,
|
||||
"end": 7
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "3",
|
||||
"start": 10,
|
||||
"end": 11
|
||||
},
|
||||
"start": 6,
|
||||
"end": 11
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "4",
|
||||
"start": 16,
|
||||
"end": 17
|
||||
},
|
||||
"start": 6,
|
||||
"end": 17
|
||||
},
|
||||
"start": 0,
|
||||
"end": 17
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "/",
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 7,
|
||||
"end": 8
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "3",
|
||||
"start": 11,
|
||||
"end": 12
|
||||
},
|
||||
"start": 7,
|
||||
"end": 12
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "4",
|
||||
"start": 17,
|
||||
"end": 18
|
||||
},
|
||||
"start": 7,
|
||||
"end": 18
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "5",
|
||||
"start": 21,
|
||||
"end": 22
|
||||
},
|
||||
"start": 7,
|
||||
"end": 22
|
||||
},
|
||||
"start": 0,
|
||||
"end": 22
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "1",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 8,
|
||||
"end": 9
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "3",
|
||||
"start": 12,
|
||||
"end": 13
|
||||
},
|
||||
"start": 8,
|
||||
"end": 13
|
||||
},
|
||||
"start": 0,
|
||||
"end": 13
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "/",
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"type": "Identifier",
|
||||
"name": "distance",
|
||||
"start": 0,
|
||||
"end": 8
|
||||
},
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"type": "Identifier",
|
||||
"name": "p",
|
||||
"start": 11,
|
||||
"end": 12
|
||||
},
|
||||
"start": 0,
|
||||
"end": 12
|
||||
},
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"type": "Identifier",
|
||||
"name": "FOS",
|
||||
"start": 15,
|
||||
"end": 18
|
||||
},
|
||||
"start": 0,
|
||||
"end": 18
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 6.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "6",
|
||||
"start": 21,
|
||||
"end": 22
|
||||
},
|
||||
"start": 0,
|
||||
"end": 22
|
||||
},
|
||||
"right": {
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression",
|
||||
"operator": "*",
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"type": "Identifier",
|
||||
"name": "sigmaAllow",
|
||||
"start": 26,
|
||||
"end": 36
|
||||
},
|
||||
"right": {
|
||||
"type": "Identifier",
|
||||
"type": "Identifier",
|
||||
"name": "width",
|
||||
"start": 39,
|
||||
"end": 44
|
||||
},
|
||||
"start": 26,
|
||||
"end": 44
|
||||
},
|
||||
"start": 0,
|
||||
"end": 44
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"type": "BinaryExpression",
|
||||
"operator": "+",
|
||||
"left": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "2",
|
||||
"start": 0,
|
||||
"end": 1
|
||||
},
|
||||
"right": {
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
},
|
||||
"raw": "3",
|
||||
"start": 7,
|
||||
"end": 8
|
||||
},
|
||||
"start": 0,
|
||||
"end": 8
|
||||
}
|
@ -0,0 +1,277 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 141,
|
||||
"id": {
|
||||
"end": 9,
|
||||
"name": "boxSketch",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 28,
|
||||
"raw": "0",
|
||||
"start": 27,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 31,
|
||||
"raw": "0",
|
||||
"start": 30,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 32,
|
||||
"start": 26,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 25,
|
||||
"name": "startSketchAt",
|
||||
"start": 12,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 33,
|
||||
"start": 12,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 48,
|
||||
"raw": "0",
|
||||
"start": 47,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 52,
|
||||
"raw": "10",
|
||||
"start": 50,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 10.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 53,
|
||||
"start": 46,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
{
|
||||
"end": 56,
|
||||
"start": 55,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 45,
|
||||
"name": "line",
|
||||
"start": 41,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 57,
|
||||
"start": 41,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 82,
|
||||
"raw": "5",
|
||||
"start": 81,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 82,
|
||||
"operator": "-",
|
||||
"start": 80,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 85,
|
||||
"raw": "5",
|
||||
"start": 84,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 86,
|
||||
"start": 79,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
{
|
||||
"end": 89,
|
||||
"start": 88,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 78,
|
||||
"name": "tangentialArc",
|
||||
"start": 65,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 90,
|
||||
"start": 65,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 105,
|
||||
"raw": "5",
|
||||
"start": 104,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"argument": {
|
||||
"end": 110,
|
||||
"raw": "15",
|
||||
"start": 108,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 15.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 110,
|
||||
"operator": "-",
|
||||
"start": 107,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
}
|
||||
],
|
||||
"end": 111,
|
||||
"start": 103,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
{
|
||||
"end": 114,
|
||||
"start": 113,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 102,
|
||||
"name": "line",
|
||||
"start": 98,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 115,
|
||||
"start": 98,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "length"
|
||||
},
|
||||
"arg": {
|
||||
"end": 140,
|
||||
"raw": "10",
|
||||
"start": 138,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 10.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 130,
|
||||
"name": "extrude",
|
||||
"start": 123,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 141,
|
||||
"start": 123,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
}
|
||||
],
|
||||
"end": 141,
|
||||
"start": 12,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 141,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 142,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 11,
|
||||
"id": {
|
||||
"end": 2,
|
||||
"name": "sg",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"argument": {
|
||||
"end": 11,
|
||||
"name": "scale",
|
||||
"start": 6,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 11,
|
||||
"operator": "-",
|
||||
"start": 5,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 11,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 11,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 27,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "endAbsolute"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 21,
|
||||
"raw": "0",
|
||||
"start": 20,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"argument": {
|
||||
"end": 25,
|
||||
"raw": "1",
|
||||
"start": 24,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 25,
|
||||
"operator": "-",
|
||||
"start": 23,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
}
|
||||
],
|
||||
"end": 26,
|
||||
"start": 19,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 4,
|
||||
"name": "line",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 27,
|
||||
"start": 0,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 27,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 17,
|
||||
"id": {
|
||||
"end": 7,
|
||||
"name": "myArray",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 17,
|
||||
"endElement": {
|
||||
"end": 16,
|
||||
"raw": "10",
|
||||
"start": 14,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 10.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"endInclusive": true,
|
||||
"start": 10,
|
||||
"startElement": {
|
||||
"end": 12,
|
||||
"raw": "0",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"type": "ArrayRangeExpression",
|
||||
"type": "ArrayRangeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 17,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 17,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 57,
|
||||
"id": {
|
||||
"end": 24,
|
||||
"name": "firstPrimeNumber",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 51,
|
||||
"raw": "2",
|
||||
"start": 50,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 51,
|
||||
"start": 43,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 57,
|
||||
"start": 33
|
||||
},
|
||||
"end": 57,
|
||||
"params": [],
|
||||
"start": 27,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 57,
|
||||
"kind": "fn",
|
||||
"start": 5,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 80,
|
||||
"expression": {
|
||||
"arguments": [],
|
||||
"callee": {
|
||||
"end": 78,
|
||||
"name": "firstPrimeNumber",
|
||||
"start": 62,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 80,
|
||||
"start": 62,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 62,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 80,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 49,
|
||||
"id": {
|
||||
"end": 8,
|
||||
"name": "thing",
|
||||
"start": 3,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 43,
|
||||
"raw": "true",
|
||||
"start": 39,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"end": 43,
|
||||
"start": 32,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 49,
|
||||
"start": 22
|
||||
},
|
||||
"end": 49,
|
||||
"params": [
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 17,
|
||||
"name": "param",
|
||||
"start": 12,
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 11,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 3,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 49,
|
||||
"kind": "fn",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"end": 66,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 65,
|
||||
"raw": "false",
|
||||
"start": 60,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 59,
|
||||
"name": "thing",
|
||||
"start": 54,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 66,
|
||||
"start": 54,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 54,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 66,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,277 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 197,
|
||||
"id": {
|
||||
"end": 8,
|
||||
"name": "mySketch",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 27,
|
||||
"raw": "0",
|
||||
"start": 26,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 29,
|
||||
"raw": "0",
|
||||
"start": 28,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 30,
|
||||
"start": 25,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 24,
|
||||
"name": "startSketchAt",
|
||||
"start": 11,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 31,
|
||||
"start": 11,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "endAbsolute"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 64,
|
||||
"raw": "0",
|
||||
"start": 63,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 67,
|
||||
"raw": "1",
|
||||
"start": 66,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 68,
|
||||
"start": 62,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "tag"
|
||||
},
|
||||
"arg": {
|
||||
"end": 83,
|
||||
"start": 76,
|
||||
"type": "TagDeclarator",
|
||||
"type": "TagDeclarator",
|
||||
"value": "myPath"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 47,
|
||||
"name": "line",
|
||||
"start": 43,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 84,
|
||||
"start": 43,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "endAbsolute"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 117,
|
||||
"raw": "1",
|
||||
"start": 116,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 120,
|
||||
"raw": "1",
|
||||
"start": 119,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 121,
|
||||
"start": 115,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 100,
|
||||
"name": "line",
|
||||
"start": 96,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 122,
|
||||
"start": 96,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "endAbsolute"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 155,
|
||||
"raw": "1",
|
||||
"start": 154,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 158,
|
||||
"raw": "0",
|
||||
"start": 157,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 159,
|
||||
"start": 153,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "tag"
|
||||
},
|
||||
"arg": {
|
||||
"end": 177,
|
||||
"start": 167,
|
||||
"type": "TagDeclarator",
|
||||
"type": "TagDeclarator",
|
||||
"value": "rightPath"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 138,
|
||||
"name": "line",
|
||||
"start": 134,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 178,
|
||||
"start": 134,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
{
|
||||
"arguments": [],
|
||||
"callee": {
|
||||
"end": 195,
|
||||
"name": "close",
|
||||
"start": 190,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 197,
|
||||
"start": 190,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
}
|
||||
],
|
||||
"end": 197,
|
||||
"start": 11,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 197,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 197,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 72,
|
||||
"id": {
|
||||
"end": 8,
|
||||
"name": "mySketch",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 27,
|
||||
"raw": "0",
|
||||
"start": 26,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 29,
|
||||
"raw": "0",
|
||||
"start": 28,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 30,
|
||||
"start": 25,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 24,
|
||||
"name": "startSketchAt",
|
||||
"start": 11,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 31,
|
||||
"start": 11,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "endAbsolute"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 56,
|
||||
"raw": "1",
|
||||
"start": 55,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 59,
|
||||
"raw": "1",
|
||||
"start": 58,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 60,
|
||||
"start": 54,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 39,
|
||||
"name": "line",
|
||||
"start": 35,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 61,
|
||||
"start": 35,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
{
|
||||
"arguments": [],
|
||||
"callee": {
|
||||
"end": 70,
|
||||
"name": "close",
|
||||
"start": 65,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 72,
|
||||
"start": 65,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
}
|
||||
],
|
||||
"end": 72,
|
||||
"start": 11,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 72,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 72,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 24,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "myBox",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 23,
|
||||
"name": "p",
|
||||
"start": 22,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 21,
|
||||
"name": "startSketchAt",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 24,
|
||||
"start": 8,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 24,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 24,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 23,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "myBox",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 11,
|
||||
"raw": "1",
|
||||
"start": 10,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 9,
|
||||
"name": "f",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 12,
|
||||
"start": 8,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 19,
|
||||
"raw": "2",
|
||||
"start": 18,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 22,
|
||||
"start": 21,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 17,
|
||||
"name": "g",
|
||||
"start": 16,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 23,
|
||||
"start": 16,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
}
|
||||
],
|
||||
"end": 23,
|
||||
"start": 8,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 23,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 23,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 46,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "myBox",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 23,
|
||||
"name": "p",
|
||||
"start": 22,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 21,
|
||||
"name": "startSketchAt",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 24,
|
||||
"start": 8,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "end"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 41,
|
||||
"raw": "0",
|
||||
"start": 40,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 44,
|
||||
"name": "l",
|
||||
"start": 43,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"end": 45,
|
||||
"start": 39,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 32,
|
||||
"name": "line",
|
||||
"start": 28,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 46,
|
||||
"start": 28,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
}
|
||||
],
|
||||
"end": 46,
|
||||
"start": 8,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 46,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 46,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 26,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "endAbsolute"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 21,
|
||||
"raw": "0",
|
||||
"start": 20,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 24,
|
||||
"raw": "1",
|
||||
"start": 23,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 25,
|
||||
"start": 19,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 4,
|
||||
"name": "line",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 26,
|
||||
"start": 0,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 26,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 31,
|
||||
"id": {
|
||||
"end": 8,
|
||||
"name": "mySketch",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 27,
|
||||
"raw": "0",
|
||||
"start": 26,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 29,
|
||||
"raw": "0",
|
||||
"start": 28,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 30,
|
||||
"start": 25,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 24,
|
||||
"name": "startSketchAt",
|
||||
"start": 11,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 31,
|
||||
"start": 11,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 31,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 31,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 28,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 5,
|
||||
"raw": "5",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 14,
|
||||
"raw": "\"hello\"",
|
||||
"start": 7,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "hello"
|
||||
},
|
||||
{
|
||||
"end": 27,
|
||||
"name": "aIdentifier",
|
||||
"start": 16,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 3,
|
||||
"name": "log",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 28,
|
||||
"start": 0,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 28,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 7,
|
||||
"expression": {
|
||||
"end": 7,
|
||||
"left": {
|
||||
"end": 1,
|
||||
"raw": "5",
|
||||
"start": 0,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "+",
|
||||
"right": {
|
||||
"end": 7,
|
||||
"raw": "\"a\"",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 7,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 15,
|
||||
"expression": {
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 7,
|
||||
"raw": "0",
|
||||
"start": 6,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 10,
|
||||
"name": "l",
|
||||
"start": 9,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"end": 11,
|
||||
"start": 5,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
{
|
||||
"end": 14,
|
||||
"start": 13,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 4,
|
||||
"name": "line",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 15,
|
||||
"start": 0,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 15,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 106,
|
||||
"id": {
|
||||
"end": 14,
|
||||
"name": "cylinder",
|
||||
"start": 6,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 35,
|
||||
"raw": "'XY'",
|
||||
"start": 31,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "XY"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 30,
|
||||
"name": "startSketchOn",
|
||||
"start": 17,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 36,
|
||||
"start": 17,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "center"
|
||||
},
|
||||
"arg": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 61,
|
||||
"raw": "0",
|
||||
"start": 60,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 64,
|
||||
"raw": "0",
|
||||
"start": 63,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 65,
|
||||
"start": 59,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "radius"
|
||||
},
|
||||
"arg": {
|
||||
"end": 77,
|
||||
"raw": "22",
|
||||
"start": 75,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 22.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 50,
|
||||
"name": "circle",
|
||||
"start": 44,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 78,
|
||||
"start": 44,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "length"
|
||||
},
|
||||
"arg": {
|
||||
"end": 105,
|
||||
"raw": "14",
|
||||
"start": 103,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 14.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 93,
|
||||
"name": "extrude",
|
||||
"start": 86,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 106,
|
||||
"start": 86,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
}
|
||||
],
|
||||
"end": 106,
|
||||
"start": 17,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 6,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 106,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 107,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 49,
|
||||
"id": {
|
||||
"end": 4,
|
||||
"name": "f",
|
||||
"start": 3,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 41,
|
||||
"name": "angle",
|
||||
"start": 36,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
{
|
||||
"end": 46,
|
||||
"raw": "360",
|
||||
"start": 43,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 360.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 35,
|
||||
"name": "default",
|
||||
"start": 28,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 47,
|
||||
"start": 28,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"end": 47,
|
||||
"start": 21,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 49,
|
||||
"start": 19
|
||||
},
|
||||
"end": 49,
|
||||
"params": [
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 13,
|
||||
"name": "angle",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"default_value": {
|
||||
"type": "KclNone",
|
||||
"type": "KclNone",
|
||||
"__private": "KCL_NONE_ID"
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 7,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 3,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 49,
|
||||
"kind": "fn",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 49,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 91,
|
||||
"id": {
|
||||
"end": 11,
|
||||
"name": "numbers",
|
||||
"start": 4,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 29,
|
||||
"raw": "1",
|
||||
"start": 28,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 80,
|
||||
"raw": "3",
|
||||
"start": 79,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 91,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"1": [
|
||||
{
|
||||
"end": 48,
|
||||
"start": 43,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "A,",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
],
|
||||
"2": [
|
||||
{
|
||||
"end": 66,
|
||||
"start": 61,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "B,",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 91,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 91,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 91,
|
||||
"id": {
|
||||
"end": 11,
|
||||
"name": "numbers",
|
||||
"start": 4,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 29,
|
||||
"raw": "1",
|
||||
"start": 28,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 44,
|
||||
"raw": "2",
|
||||
"start": 43,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 91,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"2": [
|
||||
{
|
||||
"end": 63,
|
||||
"start": 58,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "A,",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
],
|
||||
"3": [
|
||||
{
|
||||
"end": 81,
|
||||
"start": 76,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "B,",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 91,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 91,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 80,
|
||||
"id": {
|
||||
"end": 9,
|
||||
"name": "props",
|
||||
"start": 4,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 80,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"1": [
|
||||
{
|
||||
"end": 52,
|
||||
"start": 44,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "b: 2,",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"end": 30,
|
||||
"key": {
|
||||
"end": 27,
|
||||
"name": "a",
|
||||
"start": 26,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 26,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 30,
|
||||
"raw": "1",
|
||||
"start": 29,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 69,
|
||||
"key": {
|
||||
"end": 66,
|
||||
"name": "c",
|
||||
"start": 65,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 65,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 69,
|
||||
"raw": "3",
|
||||
"start": 68,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 12,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 80,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 80,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 79,
|
||||
"id": {
|
||||
"end": 9,
|
||||
"name": "props",
|
||||
"start": 4,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 79,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"1": [
|
||||
{
|
||||
"end": 52,
|
||||
"start": 44,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "b: 2,",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"end": 30,
|
||||
"key": {
|
||||
"end": 27,
|
||||
"name": "a",
|
||||
"start": 26,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 26,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 30,
|
||||
"raw": "1",
|
||||
"start": 29,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 69,
|
||||
"key": {
|
||||
"end": 66,
|
||||
"name": "c",
|
||||
"start": 65,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 65,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 69,
|
||||
"raw": "3",
|
||||
"start": 68,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 12,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 79,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 79,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 30,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "myVar",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 13,
|
||||
"raw": "5",
|
||||
"start": 12,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"argument": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 25,
|
||||
"raw": "5",
|
||||
"start": 24,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 28,
|
||||
"raw": "4",
|
||||
"start": 27,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 23,
|
||||
"name": "legLen",
|
||||
"start": 17,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 29,
|
||||
"start": 17,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"end": 29,
|
||||
"operator": "-",
|
||||
"start": 16,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 11,
|
||||
"name": "min",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 30,
|
||||
"start": 8,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 30,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 30,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 126,
|
||||
"id": {
|
||||
"end": 10,
|
||||
"name": "sketch001",
|
||||
"start": 1,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 31,
|
||||
"raw": "'XY'",
|
||||
"start": 27,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "XY"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 26,
|
||||
"name": "startSketchOn",
|
||||
"start": 13,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 32,
|
||||
"start": 13,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 125,
|
||||
"start": 124,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 123,
|
||||
"name": "startProfileAt",
|
||||
"start": 109,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 126,
|
||||
"start": 109,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
}
|
||||
],
|
||||
"end": 126,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"0": [
|
||||
{
|
||||
"end": 46,
|
||||
"start": 35,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "|> arc({",
|
||||
"style": "line"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 68,
|
||||
"start": 49,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "angleEnd: 270,",
|
||||
"style": "line"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 92,
|
||||
"start": 71,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "angleStart: 450,",
|
||||
"style": "line"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 103,
|
||||
"start": 95,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "}, %)",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 13,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 1,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 126,
|
||||
"kind": "const",
|
||||
"start": 1,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 127,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 25,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "my14",
|
||||
"start": 1,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 25,
|
||||
"left": {
|
||||
"end": 13,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "4",
|
||||
"start": 8,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "^",
|
||||
"right": {
|
||||
"end": 13,
|
||||
"raw": "2",
|
||||
"start": 12,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 8,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"end": 25,
|
||||
"left": {
|
||||
"end": 21,
|
||||
"left": {
|
||||
"end": 17,
|
||||
"raw": "3",
|
||||
"start": 16,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "^",
|
||||
"right": {
|
||||
"end": 21,
|
||||
"raw": "2",
|
||||
"start": 20,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 16,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"operator": "*",
|
||||
"right": {
|
||||
"end": 25,
|
||||
"raw": "2",
|
||||
"start": 24,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 16,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 1,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 25,
|
||||
"kind": "const",
|
||||
"start": 1,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 26,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 68,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 11,
|
||||
"raw": "true",
|
||||
"start": 7,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [],
|
||||
"end": 68,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 58,
|
||||
"expression": {
|
||||
"end": 58,
|
||||
"raw": "4",
|
||||
"start": 57,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 57,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 67,
|
||||
"start": 57
|
||||
},
|
||||
"start": 4,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 27,
|
||||
"expression": {
|
||||
"end": 27,
|
||||
"raw": "3",
|
||||
"start": 26,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 26,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 36,
|
||||
"start": 26
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 68,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 68,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 115,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"cond": {
|
||||
"end": 11,
|
||||
"raw": "true",
|
||||
"start": 7,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"digest": null,
|
||||
"else_ifs": [
|
||||
{
|
||||
"cond": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 57,
|
||||
"name": "radius",
|
||||
"start": 51,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 50,
|
||||
"name": "func",
|
||||
"start": 46,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 58,
|
||||
"start": 46,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"digest": null,
|
||||
"end": 84,
|
||||
"start": 38,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 74,
|
||||
"expression": {
|
||||
"end": 74,
|
||||
"raw": "4",
|
||||
"start": 73,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 73,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 83,
|
||||
"start": 59
|
||||
},
|
||||
"type": "ElseIf"
|
||||
}
|
||||
],
|
||||
"end": 115,
|
||||
"final_else": {
|
||||
"body": [
|
||||
{
|
||||
"end": 105,
|
||||
"expression": {
|
||||
"end": 105,
|
||||
"raw": "5",
|
||||
"start": 104,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 104,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 114,
|
||||
"start": 104
|
||||
},
|
||||
"start": 4,
|
||||
"then_val": {
|
||||
"body": [
|
||||
{
|
||||
"end": 27,
|
||||
"expression": {
|
||||
"end": 27,
|
||||
"raw": "3",
|
||||
"start": 26,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 26,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 36,
|
||||
"start": 26
|
||||
},
|
||||
"type": "IfExpression",
|
||||
"type": "IfExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 115,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 115,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 14,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "x",
|
||||
"start": 4,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 14,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "3",
|
||||
"start": 8,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "==",
|
||||
"right": {
|
||||
"end": 14,
|
||||
"raw": "3",
|
||||
"start": 13,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 8,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 14,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 14,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 14,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "x",
|
||||
"start": 4,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 14,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "3",
|
||||
"start": 8,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "!=",
|
||||
"right": {
|
||||
"end": 14,
|
||||
"raw": "3",
|
||||
"start": 13,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 8,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 14,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 14,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 5,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 5,
|
||||
"raw": "4",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 5,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 5,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 36,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 36,
|
||||
"properties": [
|
||||
{
|
||||
"end": 24,
|
||||
"key": {
|
||||
"end": 13,
|
||||
"name": "center",
|
||||
"start": 7,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 7,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 19,
|
||||
"raw": "10",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 10.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 23,
|
||||
"raw": "10",
|
||||
"start": 21,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 10.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 24,
|
||||
"start": 16,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 35,
|
||||
"key": {
|
||||
"end": 32,
|
||||
"name": "radius",
|
||||
"start": 26,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 26,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 35,
|
||||
"raw": "5",
|
||||
"start": 34,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 36,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 36,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 5,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 5,
|
||||
"raw": "3",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 5,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 30,
|
||||
"id": {
|
||||
"end": 17,
|
||||
"name": "obj",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 30,
|
||||
"properties": [
|
||||
{
|
||||
"end": 23,
|
||||
"key": {
|
||||
"end": 23,
|
||||
"name": "x",
|
||||
"start": 22,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 22,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 23,
|
||||
"name": "x",
|
||||
"start": 22,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 29,
|
||||
"key": {
|
||||
"end": 26,
|
||||
"name": "y",
|
||||
"start": 25,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 25,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 29,
|
||||
"raw": "4",
|
||||
"start": 28,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 20,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 30,
|
||||
"kind": "const",
|
||||
"start": 14,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 30,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 4,
|
||||
"expression": {
|
||||
"end": 4,
|
||||
"raw": "true",
|
||||
"start": 0,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 4,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"end": 5,
|
||||
"expression": {
|
||||
"end": 5,
|
||||
"name": "truee",
|
||||
"start": 0,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "ExpressionStatement",
|
||||
"type": "ExpressionStatement"
|
||||
}
|
||||
],
|
||||
"end": 5,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 9,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"argument": {
|
||||
"end": 9,
|
||||
"raw": "true",
|
||||
"start": 5,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"end": 9,
|
||||
"operator": "!",
|
||||
"start": 4,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 9,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 9,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 16,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 16,
|
||||
"left": {
|
||||
"end": 8,
|
||||
"raw": "true",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "&",
|
||||
"right": {
|
||||
"end": 16,
|
||||
"raw": "false",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 4,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 16,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 16,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 16,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 16,
|
||||
"left": {
|
||||
"end": 8,
|
||||
"raw": "true",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": true
|
||||
},
|
||||
"operator": "|",
|
||||
"right": {
|
||||
"end": 16,
|
||||
"raw": "false",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": false
|
||||
},
|
||||
"start": 4,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 16,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 16,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 29,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "myVar",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"argument": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 21,
|
||||
"raw": "5",
|
||||
"start": 20,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 24,
|
||||
"raw": "4",
|
||||
"start": 23,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 19,
|
||||
"name": "legLen",
|
||||
"start": 13,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 25,
|
||||
"start": 13,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"end": 25,
|
||||
"operator": "-",
|
||||
"start": 12,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 28,
|
||||
"raw": "5",
|
||||
"start": 27,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 11,
|
||||
"name": "min",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 29,
|
||||
"start": 8,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 29,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 29,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 30,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "myVar",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"end": 13,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "5",
|
||||
"start": 8,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 5.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "+",
|
||||
"right": {
|
||||
"end": 13,
|
||||
"raw": "6",
|
||||
"start": 12,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 6.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 8,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 26,
|
||||
"raw": "45",
|
||||
"start": 24,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 45.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 29,
|
||||
"start": 28,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 23,
|
||||
"name": "myFunc",
|
||||
"start": 17,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 30,
|
||||
"start": 17,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
}
|
||||
],
|
||||
"end": 30,
|
||||
"start": 8,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 30,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 30,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 21,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 21,
|
||||
"left": {
|
||||
"argument": {
|
||||
"end": 9,
|
||||
"name": "leg2",
|
||||
"start": 5,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 9,
|
||||
"operator": "-",
|
||||
"start": 4,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
},
|
||||
"operator": "+",
|
||||
"right": {
|
||||
"end": 21,
|
||||
"name": "thickness",
|
||||
"start": 12,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 21,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 21,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 18,
|
||||
"id": {
|
||||
"end": 5,
|
||||
"name": "x",
|
||||
"start": 4,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 18,
|
||||
"left": {
|
||||
"end": 9,
|
||||
"raw": "1",
|
||||
"start": 8,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "*",
|
||||
"right": {
|
||||
"end": 18,
|
||||
"left": {
|
||||
"end": 14,
|
||||
"raw": "3",
|
||||
"start": 13,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"end": 18,
|
||||
"raw": "4",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 4.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 13,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 4,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 18,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 18,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 5,
|
||||
"id": {
|
||||
"end": 1,
|
||||
"name": "x",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 5,
|
||||
"raw": "1",
|
||||
"start": 4,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 5,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 34,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"0": [
|
||||
{
|
||||
"end": 34,
|
||||
"start": 5,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "inlineComment",
|
||||
"value": "this is an inline comment",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 58,
|
||||
"id": {
|
||||
"end": 4,
|
||||
"name": "x",
|
||||
"start": 3,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 32,
|
||||
"name": "sg",
|
||||
"start": 30,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 32,
|
||||
"start": 23,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
},
|
||||
{
|
||||
"argument": {
|
||||
"end": 50,
|
||||
"name": "sg",
|
||||
"start": 48,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 50,
|
||||
"start": 41,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 58,
|
||||
"start": 13
|
||||
},
|
||||
"end": 58,
|
||||
"params": [],
|
||||
"start": 7,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 3,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 58,
|
||||
"kind": "fn",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 58,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 20,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 20,
|
||||
"properties": [
|
||||
{
|
||||
"end": 12,
|
||||
"key": {
|
||||
"end": 9,
|
||||
"name": "a",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 18,
|
||||
"key": {
|
||||
"end": 15,
|
||||
"name": "b",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 18,
|
||||
"raw": "2",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 20,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 43,
|
||||
"id": {
|
||||
"end": 31,
|
||||
"name": "height",
|
||||
"start": 25,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 43,
|
||||
"left": {
|
||||
"end": 35,
|
||||
"raw": "1",
|
||||
"start": 34,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"computed": false,
|
||||
"end": 43,
|
||||
"object": {
|
||||
"end": 41,
|
||||
"name": "obj",
|
||||
"start": 38,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 43,
|
||||
"name": "a",
|
||||
"start": 42,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 38,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 34,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 25,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 43,
|
||||
"kind": "const",
|
||||
"start": 25,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 43,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 20,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 20,
|
||||
"properties": [
|
||||
{
|
||||
"end": 12,
|
||||
"key": {
|
||||
"end": 9,
|
||||
"name": "a",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 18,
|
||||
"key": {
|
||||
"end": 15,
|
||||
"name": "b",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 18,
|
||||
"raw": "2",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 20,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 47,
|
||||
"id": {
|
||||
"end": 32,
|
||||
"name": "height",
|
||||
"start": 26,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 47,
|
||||
"left": {
|
||||
"end": 36,
|
||||
"raw": "1",
|
||||
"start": 35,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"computed": false,
|
||||
"end": 47,
|
||||
"object": {
|
||||
"end": 42,
|
||||
"name": "obj",
|
||||
"start": 39,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 46,
|
||||
"raw": "\"a\"",
|
||||
"start": 43,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 39,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 35,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 26,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 47,
|
||||
"kind": "const",
|
||||
"start": 26,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 47,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 20,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 20,
|
||||
"properties": [
|
||||
{
|
||||
"end": 12,
|
||||
"key": {
|
||||
"end": 9,
|
||||
"name": "a",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 18,
|
||||
"key": {
|
||||
"end": 15,
|
||||
"name": "b",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 18,
|
||||
"raw": "2",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 20,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 46,
|
||||
"id": {
|
||||
"end": 31,
|
||||
"name": "height",
|
||||
"start": 25,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 46,
|
||||
"left": {
|
||||
"computed": false,
|
||||
"end": 42,
|
||||
"object": {
|
||||
"end": 37,
|
||||
"name": "obj",
|
||||
"start": 34,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 41,
|
||||
"raw": "\"a\"",
|
||||
"start": 38,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 34,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"end": 46,
|
||||
"raw": "1",
|
||||
"start": 45,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 34,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 25,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 46,
|
||||
"kind": "const",
|
||||
"start": 25,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 46,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 20,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 20,
|
||||
"properties": [
|
||||
{
|
||||
"end": 12,
|
||||
"key": {
|
||||
"end": 9,
|
||||
"name": "a",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 18,
|
||||
"key": {
|
||||
"end": 15,
|
||||
"name": "b",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 18,
|
||||
"raw": "2",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 20,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 51,
|
||||
"id": {
|
||||
"end": 31,
|
||||
"name": "height",
|
||||
"start": 25,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 47,
|
||||
"left": {
|
||||
"end": 36,
|
||||
"raw": "1",
|
||||
"start": 35,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"computed": false,
|
||||
"end": 47,
|
||||
"object": {
|
||||
"end": 42,
|
||||
"name": "obj",
|
||||
"start": 39,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 46,
|
||||
"raw": "\"a\"",
|
||||
"start": 43,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 39,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 35,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 50,
|
||||
"raw": "0",
|
||||
"start": 49,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 51,
|
||||
"start": 34,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
"start": 25,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 51,
|
||||
"kind": "const",
|
||||
"start": 25,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 51,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 23,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "val",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "x"
|
||||
},
|
||||
"arg": {
|
||||
"end": 15,
|
||||
"name": "a",
|
||||
"start": 14,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "y"
|
||||
},
|
||||
"arg": {
|
||||
"end": 22,
|
||||
"name": "b",
|
||||
"start": 21,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 9,
|
||||
"name": "foo",
|
||||
"start": 6,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 23,
|
||||
"start": 6,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 23,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 23,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 21,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "val",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"end": 7,
|
||||
"raw": "1",
|
||||
"start": 6,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "arg"
|
||||
},
|
||||
"arg": {
|
||||
"end": 20,
|
||||
"name": "x",
|
||||
"start": 19,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 12,
|
||||
"name": "f",
|
||||
"start": 11,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 21,
|
||||
"start": 11,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
}
|
||||
],
|
||||
"end": 21,
|
||||
"start": 6,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 21,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 21,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
snapshot_kind: text
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 87,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "val",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "arg"
|
||||
},
|
||||
"arg": {
|
||||
"end": 29,
|
||||
"name": "x",
|
||||
"start": 28,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "foo"
|
||||
},
|
||||
"arg": {
|
||||
"end": 51,
|
||||
"name": "x",
|
||||
"start": 50,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "bar"
|
||||
},
|
||||
"arg": {
|
||||
"end": 73,
|
||||
"name": "x",
|
||||
"start": 72,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 7,
|
||||
"name": "f",
|
||||
"start": 6,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 87,
|
||||
"start": 6,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 87,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 87,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
snapshot_kind: text
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 90,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "val",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "arg"
|
||||
},
|
||||
"arg": {
|
||||
"end": 29,
|
||||
"name": "x",
|
||||
"start": 28,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "bar"
|
||||
},
|
||||
"arg": {
|
||||
"end": 76,
|
||||
"name": "x",
|
||||
"start": 75,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 7,
|
||||
"name": "f",
|
||||
"start": 6,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 90,
|
||||
"nonCodeMeta": {
|
||||
"nonCodeNodes": {
|
||||
"1": [
|
||||
{
|
||||
"end": 55,
|
||||
"start": 44,
|
||||
"type": "NonCodeNode",
|
||||
"value": {
|
||||
"type": "blockComment",
|
||||
"value": "foo = x,",
|
||||
"style": "line"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"startNodes": []
|
||||
},
|
||||
"start": 6,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": null
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 90,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 90,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 25,
|
||||
"id": {
|
||||
"end": 6,
|
||||
"name": "foo",
|
||||
"start": 3,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 23,
|
||||
"raw": "1",
|
||||
"start": 22,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 23,
|
||||
"start": 15,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 25,
|
||||
"start": 13
|
||||
},
|
||||
"end": 25,
|
||||
"params": [
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 8,
|
||||
"name": "x",
|
||||
"start": 7,
|
||||
"type": "Identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 11,
|
||||
"name": "y",
|
||||
"start": 10,
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 3,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 25,
|
||||
"kind": "fn",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 25,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 26,
|
||||
"id": {
|
||||
"end": 6,
|
||||
"name": "foo",
|
||||
"start": 3,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 24,
|
||||
"raw": "1",
|
||||
"start": 23,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 24,
|
||||
"start": 16,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 26,
|
||||
"start": 14
|
||||
},
|
||||
"end": 26,
|
||||
"params": [
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 9,
|
||||
"name": "x",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"labeled": false
|
||||
},
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 12,
|
||||
"name": "y",
|
||||
"start": 11,
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 3,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 26,
|
||||
"kind": "fn",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 26,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 35,
|
||||
"id": {
|
||||
"end": 6,
|
||||
"name": "foo",
|
||||
"start": 3,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 33,
|
||||
"raw": "1",
|
||||
"start": 32,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 33,
|
||||
"start": 25,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 35,
|
||||
"start": 23
|
||||
},
|
||||
"end": 35,
|
||||
"params": [
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 8,
|
||||
"name": "x",
|
||||
"start": 7,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"default_value": {
|
||||
"end": 21,
|
||||
"raw": "2",
|
||||
"start": 20,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 3,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 35,
|
||||
"kind": "fn",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 35,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 27,
|
||||
"id": {
|
||||
"end": 6,
|
||||
"name": "foo",
|
||||
"start": 3,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": {
|
||||
"body": [
|
||||
{
|
||||
"argument": {
|
||||
"end": 25,
|
||||
"raw": "1",
|
||||
"start": 24,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"end": 25,
|
||||
"start": 17,
|
||||
"type": "ReturnStatement",
|
||||
"type": "ReturnStatement"
|
||||
}
|
||||
],
|
||||
"end": 27,
|
||||
"start": 15
|
||||
},
|
||||
"end": 27,
|
||||
"params": [
|
||||
{
|
||||
"type": "Parameter",
|
||||
"identifier": {
|
||||
"end": 8,
|
||||
"name": "x",
|
||||
"start": 7,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"default_value": {
|
||||
"end": 13,
|
||||
"raw": "2",
|
||||
"start": 12,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "FunctionExpression",
|
||||
"type": "FunctionExpression"
|
||||
},
|
||||
"start": 3,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 27,
|
||||
"kind": "fn",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 27,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 19,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "val",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"type": "LabeledArg",
|
||||
"label": {
|
||||
"type": "Identifier",
|
||||
"name": "y"
|
||||
},
|
||||
"arg": {
|
||||
"end": 18,
|
||||
"name": "z",
|
||||
"start": 17,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 9,
|
||||
"name": "foo",
|
||||
"start": 6,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 19,
|
||||
"start": 6,
|
||||
"type": "CallExpressionKw",
|
||||
"type": "CallExpressionKw",
|
||||
"unlabeled": {
|
||||
"end": 11,
|
||||
"name": "x",
|
||||
"start": 10,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 19,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 19,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 20,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 20,
|
||||
"properties": [
|
||||
{
|
||||
"end": 12,
|
||||
"key": {
|
||||
"end": 9,
|
||||
"name": "a",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 18,
|
||||
"key": {
|
||||
"end": 15,
|
||||
"name": "b",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 18,
|
||||
"raw": "2",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 20,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 51,
|
||||
"id": {
|
||||
"end": 31,
|
||||
"name": "height",
|
||||
"start": 25,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 47,
|
||||
"left": {
|
||||
"computed": false,
|
||||
"end": 43,
|
||||
"object": {
|
||||
"end": 38,
|
||||
"name": "obj",
|
||||
"start": 35,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 42,
|
||||
"raw": "\"a\"",
|
||||
"start": 39,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 35,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"end": 47,
|
||||
"raw": "1",
|
||||
"start": 46,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 35,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 50,
|
||||
"raw": "0",
|
||||
"start": 49,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 51,
|
||||
"start": 34,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
"start": 25,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 51,
|
||||
"kind": "const",
|
||||
"start": 25,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 51,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 20,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 20,
|
||||
"properties": [
|
||||
{
|
||||
"end": 12,
|
||||
"key": {
|
||||
"end": 9,
|
||||
"name": "a",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 18,
|
||||
"key": {
|
||||
"end": 15,
|
||||
"name": "b",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 18,
|
||||
"raw": "2",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 20,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 50,
|
||||
"id": {
|
||||
"end": 31,
|
||||
"name": "height",
|
||||
"start": 25,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"elements": [
|
||||
{
|
||||
"end": 46,
|
||||
"left": {
|
||||
"computed": false,
|
||||
"end": 43,
|
||||
"object": {
|
||||
"end": 38,
|
||||
"name": "obj",
|
||||
"start": 35,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 42,
|
||||
"raw": "\"a\"",
|
||||
"start": 39,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 35,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"end": 46,
|
||||
"raw": "1",
|
||||
"start": 45,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 35,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
{
|
||||
"end": 49,
|
||||
"raw": "0",
|
||||
"start": 48,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 50,
|
||||
"start": 34,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
"start": 25,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 50,
|
||||
"kind": "const",
|
||||
"start": 25,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 50,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 18,
|
||||
"id": {
|
||||
"end": 6,
|
||||
"name": "height",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 18,
|
||||
"left": {
|
||||
"end": 10,
|
||||
"raw": "1",
|
||||
"start": 9,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "-",
|
||||
"right": {
|
||||
"computed": false,
|
||||
"end": 18,
|
||||
"object": {
|
||||
"end": 16,
|
||||
"name": "obj",
|
||||
"start": 13,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 18,
|
||||
"name": "a",
|
||||
"start": 17,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 13,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 9,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 18,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 18,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 15,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "six",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 15,
|
||||
"left": {
|
||||
"end": 11,
|
||||
"left": {
|
||||
"end": 7,
|
||||
"raw": "1",
|
||||
"start": 6,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "+",
|
||||
"right": {
|
||||
"end": 11,
|
||||
"raw": "2",
|
||||
"start": 10,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 6,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"operator": "+",
|
||||
"right": {
|
||||
"end": 15,
|
||||
"raw": "3",
|
||||
"start": 14,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 6,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 15,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 15,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 16,
|
||||
"id": {
|
||||
"end": 4,
|
||||
"name": "five",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 16,
|
||||
"left": {
|
||||
"end": 12,
|
||||
"left": {
|
||||
"end": 8,
|
||||
"raw": "3",
|
||||
"start": 7,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 3.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"operator": "*",
|
||||
"right": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 7,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"operator": "+",
|
||||
"right": {
|
||||
"end": 16,
|
||||
"raw": "2",
|
||||
"start": 15,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 7,
|
||||
"type": "BinaryExpression",
|
||||
"type": "BinaryExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 16,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 16,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 24,
|
||||
"id": {
|
||||
"end": 6,
|
||||
"name": "height",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"elements": [
|
||||
{
|
||||
"computed": false,
|
||||
"end": 19,
|
||||
"object": {
|
||||
"end": 14,
|
||||
"name": "obj",
|
||||
"start": 11,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 18,
|
||||
"raw": "\"a\"",
|
||||
"start": 15,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 11,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
{
|
||||
"end": 22,
|
||||
"raw": "0",
|
||||
"start": 21,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
],
|
||||
"end": 24,
|
||||
"start": 9,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 24,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 24,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 20,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "obj",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"end": 20,
|
||||
"properties": [
|
||||
{
|
||||
"end": 12,
|
||||
"key": {
|
||||
"end": 9,
|
||||
"name": "a",
|
||||
"start": 8,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 8,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 12,
|
||||
"raw": "1",
|
||||
"start": 11,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 1.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"end": 18,
|
||||
"key": {
|
||||
"end": 15,
|
||||
"name": "b",
|
||||
"start": 14,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 14,
|
||||
"type": "ObjectProperty",
|
||||
"value": {
|
||||
"end": 18,
|
||||
"raw": "2",
|
||||
"start": 17,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 2.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"start": 6,
|
||||
"type": "ObjectExpression",
|
||||
"type": "ObjectExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 20,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
},
|
||||
{
|
||||
"declaration": {
|
||||
"end": 42,
|
||||
"id": {
|
||||
"end": 31,
|
||||
"name": "height",
|
||||
"start": 25,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"computed": false,
|
||||
"end": 42,
|
||||
"object": {
|
||||
"end": 37,
|
||||
"name": "obj",
|
||||
"start": 34,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 41,
|
||||
"raw": "\"a\"",
|
||||
"start": 38,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "a"
|
||||
},
|
||||
"start": 34,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 25,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 42,
|
||||
"kind": "const",
|
||||
"start": 25,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 42,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 21,
|
||||
"id": {
|
||||
"end": 4,
|
||||
"name": "prop",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"computed": true,
|
||||
"end": 21,
|
||||
"object": {
|
||||
"computed": false,
|
||||
"end": 16,
|
||||
"object": {
|
||||
"end": 9,
|
||||
"name": "yo",
|
||||
"start": 7,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 15,
|
||||
"raw": "\"one\"",
|
||||
"start": 10,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "one"
|
||||
},
|
||||
"start": 7,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"property": {
|
||||
"end": 20,
|
||||
"name": "two",
|
||||
"start": 17,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 7,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 21,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 21,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 11,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "pt1",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"computed": true,
|
||||
"end": 11,
|
||||
"object": {
|
||||
"end": 8,
|
||||
"name": "b1",
|
||||
"start": 6,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 10,
|
||||
"name": "x",
|
||||
"start": 9,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 6,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 11,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 11,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 28,
|
||||
"id": {
|
||||
"end": 4,
|
||||
"name": "prop",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"computed": false,
|
||||
"end": 28,
|
||||
"object": {
|
||||
"computed": false,
|
||||
"end": 23,
|
||||
"object": {
|
||||
"computed": false,
|
||||
"end": 17,
|
||||
"object": {
|
||||
"computed": false,
|
||||
"end": 13,
|
||||
"object": {
|
||||
"end": 9,
|
||||
"name": "yo",
|
||||
"start": 7,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 13,
|
||||
"name": "one",
|
||||
"start": 10,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 7,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"property": {
|
||||
"end": 17,
|
||||
"name": "two",
|
||||
"start": 14,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 7,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"property": {
|
||||
"end": 23,
|
||||
"name": "three",
|
||||
"start": 18,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 7,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"property": {
|
||||
"end": 28,
|
||||
"name": "four",
|
||||
"start": 24,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 7,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 28,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 28,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 11,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "pt1",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"computed": false,
|
||||
"end": 11,
|
||||
"object": {
|
||||
"end": 8,
|
||||
"name": "b1",
|
||||
"start": 6,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 10,
|
||||
"raw": "0",
|
||||
"start": 9,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
"start": 6,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 11,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 11,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 16,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "pt1",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"computed": false,
|
||||
"end": 16,
|
||||
"object": {
|
||||
"end": 8,
|
||||
"name": "b1",
|
||||
"start": 6,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 15,
|
||||
"raw": "'zero'",
|
||||
"start": 9,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": "zero"
|
||||
},
|
||||
"start": 6,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 16,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 16,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 13,
|
||||
"id": {
|
||||
"end": 3,
|
||||
"name": "pt1",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"computed": false,
|
||||
"end": 13,
|
||||
"object": {
|
||||
"end": 8,
|
||||
"name": "b1",
|
||||
"start": 6,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"property": {
|
||||
"end": 13,
|
||||
"name": "zero",
|
||||
"start": 9,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"start": 6,
|
||||
"type": "MemberExpression",
|
||||
"type": "MemberExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 13,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 13,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 23,
|
||||
"id": {
|
||||
"end": 2,
|
||||
"name": "sg",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"arguments": [
|
||||
{
|
||||
"end": 22,
|
||||
"name": "pos",
|
||||
"start": 19,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 18,
|
||||
"name": "startSketchAt",
|
||||
"start": 5,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 23,
|
||||
"start": 5,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 23,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 23,
|
||||
"start": 0
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
---
|
||||
source: kcl/src/parsing/parser.rs
|
||||
expression: actual
|
||||
---
|
||||
{
|
||||
"body": [
|
||||
{
|
||||
"declaration": {
|
||||
"end": 47,
|
||||
"id": {
|
||||
"end": 2,
|
||||
"name": "sg",
|
||||
"start": 0,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"init": {
|
||||
"body": [
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"end": 22,
|
||||
"name": "pos",
|
||||
"start": 19,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 18,
|
||||
"name": "startSketchAt",
|
||||
"start": 5,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 23,
|
||||
"start": 5,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"end": 34,
|
||||
"raw": "0",
|
||||
"start": 33,
|
||||
"type": "Literal",
|
||||
"type": "Literal",
|
||||
"value": {
|
||||
"value": 0.0,
|
||||
"suffix": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"argument": {
|
||||
"end": 42,
|
||||
"name": "scale",
|
||||
"start": 37,
|
||||
"type": "Identifier",
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 42,
|
||||
"operator": "-",
|
||||
"start": 36,
|
||||
"type": "UnaryExpression",
|
||||
"type": "UnaryExpression"
|
||||
}
|
||||
],
|
||||
"end": 43,
|
||||
"start": 32,
|
||||
"type": "ArrayExpression",
|
||||
"type": "ArrayExpression"
|
||||
},
|
||||
{
|
||||
"end": 46,
|
||||
"start": 45,
|
||||
"type": "PipeSubstitution",
|
||||
"type": "PipeSubstitution"
|
||||
}
|
||||
],
|
||||
"callee": {
|
||||
"end": 31,
|
||||
"name": "line",
|
||||
"start": 27,
|
||||
"type": "Identifier"
|
||||
},
|
||||
"end": 47,
|
||||
"start": 27,
|
||||
"type": "CallExpression",
|
||||
"type": "CallExpression"
|
||||
}
|
||||
],
|
||||
"end": 47,
|
||||
"start": 5,
|
||||
"type": "PipeExpression",
|
||||
"type": "PipeExpression"
|
||||
},
|
||||
"start": 0,
|
||||
"type": "VariableDeclarator"
|
||||
},
|
||||
"end": 47,
|
||||
"kind": "const",
|
||||
"start": 0,
|
||||
"type": "VariableDeclaration",
|
||||
"type": "VariableDeclaration"
|
||||
}
|
||||
],
|
||||
"end": 47,
|
||||
"start": 0
|
||||
}
|
543
rust/kcl-lib/src/parsing/token/mod.rs
Normal file
543
rust/kcl-lib/src/parsing/token/mod.rs
Normal file
@ -0,0 +1,543 @@
|
||||
// Clippy does not agree with rustc here for some reason.
|
||||
#![allow(clippy::needless_lifetimes)]
|
||||
|
||||
use std::{fmt, iter::Enumerate, num::NonZeroUsize, str::FromStr};
|
||||
|
||||
use anyhow::Result;
|
||||
use parse_display::Display;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokeniser::Input;
|
||||
use tower_lsp::lsp_types::SemanticTokenType;
|
||||
use winnow::{
|
||||
self,
|
||||
error::ParseError,
|
||||
stream::{ContainsToken, Stream},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
errors::KclError,
|
||||
parsing::ast::types::{ItemVisibility, VariableKind},
|
||||
source_range::SourceRange,
|
||||
CompilationError, ModuleId,
|
||||
};
|
||||
|
||||
mod tokeniser;
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) use tokeniser::RESERVED_WORDS;
|
||||
|
||||
// Note the ordering, it's important that `m` comes after `mm` and `cm`.
|
||||
pub const NUM_SUFFIXES: [&str; 9] = ["mm", "cm", "m", "inch", "in", "ft", "yd", "deg", "rad"];
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, ts_rs::TS, JsonSchema)]
|
||||
#[repr(u32)]
|
||||
pub enum NumericSuffix {
|
||||
None,
|
||||
Count,
|
||||
Mm,
|
||||
Cm,
|
||||
M,
|
||||
Inch,
|
||||
Ft,
|
||||
Yd,
|
||||
Deg,
|
||||
Rad,
|
||||
}
|
||||
|
||||
impl NumericSuffix {
|
||||
#[allow(dead_code)]
|
||||
pub fn is_none(self) -> bool {
|
||||
self == Self::None
|
||||
}
|
||||
|
||||
pub fn is_some(self) -> bool {
|
||||
self != Self::None
|
||||
}
|
||||
|
||||
pub fn digestable_id(&self) -> &[u8] {
|
||||
match self {
|
||||
NumericSuffix::None => &[],
|
||||
NumericSuffix::Count => b"_",
|
||||
NumericSuffix::Mm => b"mm",
|
||||
NumericSuffix::Cm => b"cm",
|
||||
NumericSuffix::M => b"m",
|
||||
NumericSuffix::Inch => b"in",
|
||||
NumericSuffix::Ft => b"ft",
|
||||
NumericSuffix::Yd => b"yd",
|
||||
NumericSuffix::Deg => b"deg",
|
||||
NumericSuffix::Rad => b"rad",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for NumericSuffix {
|
||||
type Err = CompilationError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"_" => Ok(NumericSuffix::Count),
|
||||
"mm" | "millimeters" => Ok(NumericSuffix::Mm),
|
||||
"cm" | "centimeters" => Ok(NumericSuffix::Cm),
|
||||
"m" | "meters" => Ok(NumericSuffix::M),
|
||||
"inch" | "in" => Ok(NumericSuffix::Inch),
|
||||
"ft" | "feet" => Ok(NumericSuffix::Ft),
|
||||
"yd" | "yards" => Ok(NumericSuffix::Yd),
|
||||
"deg" | "degrees" => Ok(NumericSuffix::Deg),
|
||||
"rad" | "radians" => Ok(NumericSuffix::Rad),
|
||||
_ => Err(CompilationError::err(SourceRange::default(), "invalid unit of measure")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for NumericSuffix {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
NumericSuffix::None => Ok(()),
|
||||
NumericSuffix::Count => write!(f, "_"),
|
||||
NumericSuffix::Mm => write!(f, "mm"),
|
||||
NumericSuffix::Cm => write!(f, "cm"),
|
||||
NumericSuffix::M => write!(f, "m"),
|
||||
NumericSuffix::Inch => write!(f, "in"),
|
||||
NumericSuffix::Ft => write!(f, "ft"),
|
||||
NumericSuffix::Yd => write!(f, "yd"),
|
||||
NumericSuffix::Deg => write!(f, "deg"),
|
||||
NumericSuffix::Rad => write!(f, "rad"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct TokenStream {
|
||||
tokens: Vec<Token>,
|
||||
}
|
||||
|
||||
impl TokenStream {
|
||||
fn new(tokens: Vec<Token>) -> Self {
|
||||
Self { tokens }
|
||||
}
|
||||
|
||||
pub(super) fn remove_unknown(&mut self) -> Vec<Token> {
|
||||
let tokens = std::mem::take(&mut self.tokens);
|
||||
let (tokens, unknown_tokens): (Vec<Token>, Vec<Token>) = tokens
|
||||
.into_iter()
|
||||
.partition(|token| token.token_type != TokenType::Unknown);
|
||||
self.tokens = tokens;
|
||||
unknown_tokens
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &Token> {
|
||||
self.tokens.iter()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.tokens.is_empty()
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> TokenSlice {
|
||||
TokenSlice::from(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a TokenStream> for TokenSlice<'a> {
|
||||
fn from(stream: &'a TokenStream) -> Self {
|
||||
TokenSlice {
|
||||
start: 0,
|
||||
end: stream.tokens.len(),
|
||||
stream,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for TokenStream {
|
||||
type Item = Token;
|
||||
|
||||
type IntoIter = std::vec::IntoIter<Token>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.tokens.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct TokenSlice<'a> {
|
||||
stream: &'a TokenStream,
|
||||
start: usize,
|
||||
end: usize,
|
||||
}
|
||||
|
||||
impl<'a> std::ops::Deref for TokenSlice<'a> {
|
||||
type Target = [Token];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.stream.tokens[self.start..self.end]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TokenSlice<'a> {
|
||||
pub fn token(&self, i: usize) -> &Token {
|
||||
&self.stream.tokens[i + self.start]
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &Token> {
|
||||
(**self).iter()
|
||||
}
|
||||
|
||||
pub fn without_ends(&self) -> Self {
|
||||
Self {
|
||||
start: self.start + 1,
|
||||
end: self.end - 1,
|
||||
stream: self.stream,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for TokenSlice<'a> {
|
||||
type Item = &'a Token;
|
||||
|
||||
type IntoIter = std::slice::Iter<'a, Token>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.stream.tokens[self.start..self.end].iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Stream for TokenSlice<'a> {
|
||||
type Token = Token;
|
||||
type Slice = Self;
|
||||
type IterOffsets = Enumerate<std::vec::IntoIter<Token>>;
|
||||
type Checkpoint = Checkpoint;
|
||||
|
||||
fn iter_offsets(&self) -> Self::IterOffsets {
|
||||
#[allow(clippy::unnecessary_to_owned)]
|
||||
self.to_vec().into_iter().enumerate()
|
||||
}
|
||||
|
||||
fn eof_offset(&self) -> usize {
|
||||
self.len()
|
||||
}
|
||||
|
||||
fn next_token(&mut self) -> Option<Self::Token> {
|
||||
let token = self.first()?.clone();
|
||||
self.start += 1;
|
||||
Some(token)
|
||||
}
|
||||
|
||||
fn offset_for<P>(&self, predicate: P) -> Option<usize>
|
||||
where
|
||||
P: Fn(Self::Token) -> bool,
|
||||
{
|
||||
self.iter().position(|b| predicate(b.clone()))
|
||||
}
|
||||
|
||||
fn offset_at(&self, tokens: usize) -> Result<usize, winnow::error::Needed> {
|
||||
if let Some(needed) = tokens.checked_sub(self.len()).and_then(NonZeroUsize::new) {
|
||||
Err(winnow::error::Needed::Size(needed))
|
||||
} else {
|
||||
Ok(tokens)
|
||||
}
|
||||
}
|
||||
|
||||
fn next_slice(&mut self, offset: usize) -> Self::Slice {
|
||||
assert!(self.start + offset <= self.end);
|
||||
|
||||
let next = TokenSlice {
|
||||
stream: self.stream,
|
||||
start: self.start,
|
||||
end: self.start + offset,
|
||||
};
|
||||
self.start += offset;
|
||||
next
|
||||
}
|
||||
|
||||
fn checkpoint(&self) -> Self::Checkpoint {
|
||||
Checkpoint(self.start, self.end)
|
||||
}
|
||||
|
||||
fn reset(&mut self, checkpoint: &Self::Checkpoint) {
|
||||
self.start = checkpoint.0;
|
||||
self.end = checkpoint.1;
|
||||
}
|
||||
|
||||
fn raw(&self) -> &dyn fmt::Debug {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> winnow::stream::Offset for TokenSlice<'a> {
|
||||
fn offset_from(&self, start: &Self) -> usize {
|
||||
self.start - start.start
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> winnow::stream::Offset<Checkpoint> for TokenSlice<'a> {
|
||||
fn offset_from(&self, start: &Checkpoint) -> usize {
|
||||
self.start - start.0
|
||||
}
|
||||
}
|
||||
|
||||
impl winnow::stream::Offset for Checkpoint {
|
||||
fn offset_from(&self, start: &Self) -> usize {
|
||||
self.0 - start.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> winnow::stream::StreamIsPartial for TokenSlice<'a> {
|
||||
type PartialState = ();
|
||||
|
||||
fn complete(&mut self) -> Self::PartialState {}
|
||||
|
||||
fn restore_partial(&mut self, _: Self::PartialState) {}
|
||||
|
||||
fn is_partial_supported() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Checkpoint(usize, usize);
|
||||
|
||||
/// The types of tokens.
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Display)]
|
||||
#[display(style = "camelCase")]
|
||||
pub enum TokenType {
|
||||
/// A number.
|
||||
Number,
|
||||
/// A word.
|
||||
Word,
|
||||
/// An operator.
|
||||
Operator,
|
||||
/// A string.
|
||||
String,
|
||||
/// A keyword.
|
||||
Keyword,
|
||||
/// A type.
|
||||
Type,
|
||||
/// A brace.
|
||||
Brace,
|
||||
/// A hash.
|
||||
Hash,
|
||||
/// A bang.
|
||||
Bang,
|
||||
/// A dollar sign.
|
||||
Dollar,
|
||||
/// Whitespace.
|
||||
Whitespace,
|
||||
/// A comma.
|
||||
Comma,
|
||||
/// A colon.
|
||||
Colon,
|
||||
/// A period.
|
||||
Period,
|
||||
/// A double period: `..`.
|
||||
DoublePeriod,
|
||||
/// A line comment.
|
||||
LineComment,
|
||||
/// A block comment.
|
||||
BlockComment,
|
||||
/// A function name.
|
||||
Function,
|
||||
/// Unknown lexemes.
|
||||
Unknown,
|
||||
/// The ? symbol, used for optional values.
|
||||
QuestionMark,
|
||||
/// The @ symbol.
|
||||
At,
|
||||
}
|
||||
|
||||
/// Most KCL tokens correspond to LSP semantic tokens (but not all).
|
||||
impl TryFrom<TokenType> for SemanticTokenType {
|
||||
type Error = anyhow::Error;
|
||||
fn try_from(token_type: TokenType) -> Result<Self> {
|
||||
// If you return a new kind of `SemanticTokenType`, make sure to update `SEMANTIC_TOKEN_TYPES`
|
||||
// in the LSP implementation.
|
||||
Ok(match token_type {
|
||||
TokenType::Number => Self::NUMBER,
|
||||
TokenType::Word => Self::VARIABLE,
|
||||
TokenType::Keyword => Self::KEYWORD,
|
||||
TokenType::Type => Self::TYPE,
|
||||
TokenType::Operator => Self::OPERATOR,
|
||||
TokenType::QuestionMark => Self::OPERATOR,
|
||||
TokenType::String => Self::STRING,
|
||||
TokenType::Bang => Self::OPERATOR,
|
||||
TokenType::LineComment => Self::COMMENT,
|
||||
TokenType::BlockComment => Self::COMMENT,
|
||||
TokenType::Function => Self::FUNCTION,
|
||||
TokenType::Whitespace
|
||||
| TokenType::Brace
|
||||
| TokenType::Comma
|
||||
| TokenType::Colon
|
||||
| TokenType::Period
|
||||
| TokenType::DoublePeriod
|
||||
| TokenType::Hash
|
||||
| TokenType::Dollar
|
||||
| TokenType::At
|
||||
| TokenType::Unknown => {
|
||||
anyhow::bail!("unsupported token type: {:?}", token_type)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TokenType {
|
||||
pub fn is_whitespace(&self) -> bool {
|
||||
matches!(self, Self::Whitespace)
|
||||
}
|
||||
|
||||
pub fn is_comment(&self) -> bool {
|
||||
matches!(self, Self::LineComment | Self::BlockComment)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct Token {
|
||||
pub token_type: TokenType,
|
||||
/// Offset in the source code where this token begins.
|
||||
pub start: usize,
|
||||
/// Offset in the source code where this token ends.
|
||||
pub end: usize,
|
||||
pub(super) module_id: ModuleId,
|
||||
pub(super) value: String,
|
||||
}
|
||||
|
||||
impl ContainsToken<Token> for (TokenType, &str) {
|
||||
fn contains_token(&self, token: Token) -> bool {
|
||||
self.0 == token.token_type && self.1 == token.value
|
||||
}
|
||||
}
|
||||
|
||||
impl ContainsToken<Token> for TokenType {
|
||||
fn contains_token(&self, token: Token) -> bool {
|
||||
*self == token.token_type
|
||||
}
|
||||
}
|
||||
|
||||
impl Token {
|
||||
pub fn from_range(
|
||||
range: std::ops::Range<usize>,
|
||||
module_id: ModuleId,
|
||||
token_type: TokenType,
|
||||
value: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
start: range.start,
|
||||
end: range.end,
|
||||
module_id,
|
||||
value,
|
||||
token_type,
|
||||
}
|
||||
}
|
||||
pub fn is_code_token(&self) -> bool {
|
||||
!matches!(
|
||||
self.token_type,
|
||||
TokenType::Whitespace | TokenType::LineComment | TokenType::BlockComment
|
||||
)
|
||||
}
|
||||
|
||||
pub fn as_source_range(&self) -> SourceRange {
|
||||
SourceRange::new(self.start, self.end, self.module_id)
|
||||
}
|
||||
|
||||
pub fn as_source_ranges(&self) -> Vec<SourceRange> {
|
||||
vec![self.as_source_range()]
|
||||
}
|
||||
|
||||
pub fn visibility_keyword(&self) -> Option<ItemVisibility> {
|
||||
if !matches!(self.token_type, TokenType::Keyword) {
|
||||
return None;
|
||||
}
|
||||
match self.value.as_str() {
|
||||
"export" => Some(ItemVisibility::Export),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn numeric_value(&self) -> Option<f64> {
|
||||
if self.token_type != TokenType::Number {
|
||||
return None;
|
||||
}
|
||||
let value = &self.value;
|
||||
let value = value
|
||||
.split_once(|c: char| c == '_' || c.is_ascii_alphabetic())
|
||||
.map(|(s, _)| s)
|
||||
.unwrap_or(value);
|
||||
value.parse().ok()
|
||||
}
|
||||
|
||||
pub fn numeric_suffix(&self) -> NumericSuffix {
|
||||
if self.token_type != TokenType::Number {
|
||||
return NumericSuffix::None;
|
||||
}
|
||||
|
||||
if self.value.ends_with('_') {
|
||||
return NumericSuffix::Count;
|
||||
}
|
||||
|
||||
for suffix in NUM_SUFFIXES {
|
||||
if self.value.ends_with(suffix) {
|
||||
return suffix.parse().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
NumericSuffix::None
|
||||
}
|
||||
|
||||
/// Is this token the beginning of a variable/function declaration?
|
||||
/// If so, what kind?
|
||||
/// If not, returns None.
|
||||
pub fn declaration_keyword(&self) -> Option<VariableKind> {
|
||||
if !matches!(self.token_type, TokenType::Keyword) {
|
||||
return None;
|
||||
}
|
||||
Some(match self.value.as_str() {
|
||||
"fn" => VariableKind::Fn,
|
||||
"var" | "let" | "const" => VariableKind::Const,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Token> for SourceRange {
|
||||
fn from(token: Token) -> Self {
|
||||
Self::new(token.start, token.end, token.module_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Token> for SourceRange {
|
||||
fn from(token: &Token) -> Self {
|
||||
Self::new(token.start, token.end, token.module_id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lex(s: &str, module_id: ModuleId) -> Result<TokenStream, KclError> {
|
||||
tokeniser::lex(s, module_id).map_err(From::from)
|
||||
}
|
||||
|
||||
impl From<ParseError<Input<'_>, winnow::error::ContextError>> for KclError {
|
||||
fn from(err: ParseError<Input<'_>, winnow::error::ContextError>) -> Self {
|
||||
let (input, offset): (Vec<char>, usize) = (err.input().chars().collect(), err.offset());
|
||||
let module_id = err.input().state.module_id;
|
||||
|
||||
if offset >= input.len() {
|
||||
// From the winnow docs:
|
||||
//
|
||||
// This is an offset, not an index, and may point to
|
||||
// the end of input (input.len()) on eof errors.
|
||||
|
||||
return KclError::Lexical(crate::errors::KclErrorDetails {
|
||||
source_ranges: vec![SourceRange::new(offset, offset, module_id)],
|
||||
message: "unexpected EOF while parsing".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Add the Winnow tokenizer context to the error.
|
||||
// See https://github.com/KittyCAD/modeling-app/issues/784
|
||||
let bad_token = &input[offset];
|
||||
// TODO: Add the Winnow parser context to the error.
|
||||
// See https://github.com/KittyCAD/modeling-app/issues/784
|
||||
KclError::Lexical(crate::errors::KclErrorDetails {
|
||||
source_ranges: vec![SourceRange::new(offset, offset + 1, module_id)],
|
||||
message: format!("found unknown token '{}'", bad_token),
|
||||
})
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
780
rust/kcl-lib/src/parsing/token/tokeniser.rs
Normal file
780
rust/kcl-lib/src/parsing/token/tokeniser.rs
Normal file
@ -0,0 +1,780 @@
|
||||
use fnv::FnvHashMap;
|
||||
use lazy_static::lazy_static;
|
||||
use winnow::{
|
||||
ascii::{digit1, multispace1},
|
||||
combinator::{alt, opt, peek, preceded, repeat},
|
||||
error::{ContextError, ParseError},
|
||||
prelude::*,
|
||||
stream::{Location, Stream},
|
||||
token::{any, none_of, one_of, take_till, take_until},
|
||||
LocatingSlice, Stateful,
|
||||
};
|
||||
|
||||
use super::TokenStream;
|
||||
use crate::{
|
||||
parsing::token::{Token, TokenType},
|
||||
ModuleId,
|
||||
};
|
||||
|
||||
lazy_static! {
|
||||
pub(crate) static ref RESERVED_WORDS: FnvHashMap<&'static str, TokenType> = {
|
||||
let mut set = FnvHashMap::default();
|
||||
set.insert("if", TokenType::Keyword);
|
||||
set.insert("else", TokenType::Keyword);
|
||||
set.insert("for", TokenType::Keyword);
|
||||
set.insert("while", TokenType::Keyword);
|
||||
set.insert("return", TokenType::Keyword);
|
||||
set.insert("break", TokenType::Keyword);
|
||||
set.insert("continue", TokenType::Keyword);
|
||||
set.insert("fn", TokenType::Keyword);
|
||||
set.insert("let", TokenType::Keyword);
|
||||
set.insert("mut", TokenType::Keyword);
|
||||
set.insert("as", TokenType::Keyword);
|
||||
set.insert("loop", TokenType::Keyword);
|
||||
set.insert("true", TokenType::Keyword);
|
||||
set.insert("false", TokenType::Keyword);
|
||||
set.insert("nil", TokenType::Keyword);
|
||||
// This isn't a type because brackets are used for the type.
|
||||
set.insert("array", TokenType::Keyword);
|
||||
set.insert("and", TokenType::Keyword);
|
||||
set.insert("or", TokenType::Keyword);
|
||||
set.insert("not", TokenType::Keyword);
|
||||
set.insert("var", TokenType::Keyword);
|
||||
set.insert("const", TokenType::Keyword);
|
||||
// "import" is special because of import().
|
||||
set.insert("export", TokenType::Keyword);
|
||||
set.insert("type", TokenType::Keyword);
|
||||
set.insert("interface", TokenType::Keyword);
|
||||
set.insert("new", TokenType::Keyword);
|
||||
set.insert("self", TokenType::Keyword);
|
||||
set.insert("record", TokenType::Keyword);
|
||||
set.insert("struct", TokenType::Keyword);
|
||||
set.insert("object", TokenType::Keyword);
|
||||
|
||||
set.insert("string", TokenType::Type);
|
||||
set.insert("number", TokenType::Type);
|
||||
set.insert("bool", TokenType::Type);
|
||||
set.insert("Sketch", TokenType::Type);
|
||||
set.insert("SketchSurface", TokenType::Type);
|
||||
set.insert("Solid", TokenType::Type);
|
||||
set.insert("Plane", TokenType::Type);
|
||||
|
||||
set
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn lex(i: &str, module_id: ModuleId) -> Result<TokenStream, ParseError<Input<'_>, ContextError>> {
|
||||
let state = State::new(module_id);
|
||||
let input = Input {
|
||||
input: LocatingSlice::new(i),
|
||||
state,
|
||||
};
|
||||
Ok(TokenStream::new(repeat(0.., token).parse(input)?))
|
||||
}
|
||||
|
||||
pub(super) type Input<'a> = Stateful<LocatingSlice<&'a str>, State>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(super) struct State {
|
||||
pub module_id: ModuleId,
|
||||
}
|
||||
|
||||
impl State {
|
||||
fn new(module_id: ModuleId) -> Self {
|
||||
Self { module_id }
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn token(i: &mut Input<'_>) -> PResult<Token> {
|
||||
match winnow::combinator::dispatch! {peek(any);
|
||||
'"' | '\'' => string,
|
||||
'/' => alt((line_comment, block_comment, operator)),
|
||||
'{' | '(' | '[' => brace_start,
|
||||
'}' | ')' | ']' => brace_end,
|
||||
',' => comma,
|
||||
'?' => question_mark,
|
||||
'@' => at,
|
||||
'0'..='9' => number,
|
||||
':' => colon,
|
||||
'.' => alt((number, double_period, period)),
|
||||
'#' => hash,
|
||||
'$' => dollar,
|
||||
'!' => alt((operator, bang)),
|
||||
' ' | '\t' | '\n' | '\r' => whitespace,
|
||||
_ => alt((operator, keyword_type_or_word))
|
||||
}
|
||||
.parse_next(i)
|
||||
{
|
||||
Ok(token) => Ok(token),
|
||||
Err(x) => {
|
||||
// TODO: Handle non ascii cases
|
||||
if i.len() == 0 || !i.is_ascii() {
|
||||
return Err(x);
|
||||
}
|
||||
|
||||
Ok(Token::from_range(
|
||||
i.location()..i.location() + 1,
|
||||
i.state.module_id,
|
||||
TokenType::Unknown,
|
||||
i.next_slice(1).to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn block_comment(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let inner = ("/*", take_until(0.., "*/"), "*/").take();
|
||||
let (value, range) = inner.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::BlockComment,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn line_comment(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let inner = (r#"//"#, take_till(0.., ['\n', '\r'])).take();
|
||||
let (value, range) = inner.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::LineComment,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn number(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let number_parser = alt((
|
||||
// Digits before the decimal point.
|
||||
(digit1, opt(('.', digit1)), opt('_'), opt(alt(super::NUM_SUFFIXES))).map(|_| ()),
|
||||
// No digits before the decimal point.
|
||||
('.', digit1, opt('_'), opt(alt(super::NUM_SUFFIXES))).map(|_| ()),
|
||||
));
|
||||
let (value, range) = number_parser.take().with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Number,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn whitespace(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = multispace1.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Whitespace,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn inner_word(i: &mut Input<'_>) -> PResult<()> {
|
||||
one_of(('a'..='z', 'A'..='Z', '_')).parse_next(i)?;
|
||||
repeat::<_, _, (), _, _>(0.., one_of(('a'..='z', 'A'..='Z', '0'..='9', '_'))).parse_next(i)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn word(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = inner_word.take().with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Word,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn operator(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = alt((
|
||||
">=", "<=", "==", "=>", "!=", "|>", "*", "+", "-", "/", "%", "=", "<", ">", r"\", "^", "|", "&",
|
||||
))
|
||||
.with_span()
|
||||
.parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Operator,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn brace_start(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = alt(('{', '(', '[')).with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Brace,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn brace_end(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = alt(('}', ')', ']')).with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Brace,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn comma(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = ','.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Comma,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn hash(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = '#'.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Hash,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn bang(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = '!'.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Bang,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn dollar(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = '$'.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Dollar,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn question_mark(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = '?'.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::QuestionMark,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn at(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = '@'.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::At,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn colon(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = ':'.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Colon,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn period(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = '.'.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::Period,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn double_period(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = "..".with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::DoublePeriod,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Zero or more of either:
|
||||
/// 1. Any character except " or \
|
||||
/// 2. Any character preceded by \
|
||||
fn inner_double_quote(i: &mut Input<'_>) -> PResult<()> {
|
||||
repeat(0.., alt((none_of(('"', '\\')), preceded('\\', winnow::token::any)))).parse_next(i)
|
||||
}
|
||||
|
||||
/// Zero or more of either:
|
||||
/// 1. Any character except ' or \
|
||||
/// 2. Any character preceded by \
|
||||
fn inner_single_quote(i: &mut Input<'_>) -> PResult<()> {
|
||||
repeat(0.., alt((none_of(('\'', '\\')), preceded('\\', winnow::token::any)))).parse_next(i)
|
||||
}
|
||||
|
||||
fn string(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let single_quoted_string = ('\'', inner_single_quote.take(), '\'');
|
||||
let double_quoted_string = ('"', inner_double_quote.take(), '"');
|
||||
let either_quoted_string = alt((single_quoted_string.take(), double_quoted_string.take()));
|
||||
let (value, range): (&str, _) = either_quoted_string.with_span().parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
TokenType::String,
|
||||
value.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
fn import_keyword(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let (value, range) = "import".with_span().parse_next(i)?;
|
||||
let token_type = peek(alt((' '.map(|_| TokenType::Keyword), '('.map(|_| TokenType::Word)))).parse_next(i)?;
|
||||
Ok(Token::from_range(
|
||||
range,
|
||||
i.state.module_id,
|
||||
token_type,
|
||||
value.to_owned(),
|
||||
))
|
||||
}
|
||||
|
||||
fn unambiguous_keyword_type_or_word(i: &mut Input<'_>) -> PResult<Token> {
|
||||
let mut w = word.parse_next(i)?;
|
||||
if let Some(token_type) = RESERVED_WORDS.get(w.value.as_str()) {
|
||||
w.token_type = *token_type;
|
||||
}
|
||||
Ok(w)
|
||||
}
|
||||
|
||||
fn keyword_type_or_word(i: &mut Input<'_>) -> PResult<Token> {
|
||||
alt((import_keyword, unambiguous_keyword_type_or_word)).parse_next(i)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use winnow::LocatingSlice;
|
||||
|
||||
use super::*;
|
||||
use crate::parsing::token::TokenSlice;
|
||||
|
||||
fn assert_parse_err<'i, P, O, E>(mut p: P, s: &'i str)
|
||||
where
|
||||
O: std::fmt::Debug,
|
||||
P: Parser<Input<'i>, O, E>,
|
||||
{
|
||||
let state = State::new(ModuleId::default());
|
||||
let mut input = Input {
|
||||
input: LocatingSlice::new(s),
|
||||
state,
|
||||
};
|
||||
assert!(p.parse_next(&mut input).is_err(), "parsed {s} but should have failed");
|
||||
}
|
||||
|
||||
// Returns the token and whether any more input is remaining to tokenize.
|
||||
fn assert_parse_ok<'i, P, O, E>(mut p: P, s: &'i str) -> (O, bool)
|
||||
where
|
||||
E: std::fmt::Debug,
|
||||
O: std::fmt::Debug,
|
||||
P: Parser<Input<'i>, O, E>,
|
||||
{
|
||||
let state = State::new(ModuleId::default());
|
||||
let mut input = Input {
|
||||
input: LocatingSlice::new(s),
|
||||
state,
|
||||
};
|
||||
let res = p.parse_next(&mut input);
|
||||
assert!(res.is_ok(), "failed to parse {s}, got {}", res.unwrap_err());
|
||||
(res.unwrap(), !input.is_empty())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number() {
|
||||
for (valid, expected) in [
|
||||
("1", false),
|
||||
("1 abc", true),
|
||||
("1.1", false),
|
||||
("1.1 abv", true),
|
||||
("1.1 abv", true),
|
||||
("1", false),
|
||||
(".1", false),
|
||||
("5?", true),
|
||||
("5 + 6", true),
|
||||
("5 + a", true),
|
||||
("5.5", false),
|
||||
("1abc", true),
|
||||
] {
|
||||
let (_, remaining) = assert_parse_ok(number, valid);
|
||||
assert_eq!(expected, remaining, "`{valid}` expected another token to be {expected}");
|
||||
}
|
||||
|
||||
for invalid in ["a", "?", "?5"] {
|
||||
assert_parse_err(number, invalid);
|
||||
}
|
||||
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let input = Input {
|
||||
input: LocatingSlice::new("0.0000000000"),
|
||||
state: State::new(module_id),
|
||||
};
|
||||
|
||||
assert_eq!(number.parse(input).unwrap().value, "0.0000000000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_number_suffix() {
|
||||
for (valid, expected_val, expected_next) in [
|
||||
("1_", 1.0, false),
|
||||
("1_mm", 1.0, false),
|
||||
("1_yd", 1.0, false),
|
||||
("1m", 1.0, false),
|
||||
("1inch", 1.0, false),
|
||||
("1toot", 1.0, true),
|
||||
("1.4inch t", 1.4, true),
|
||||
] {
|
||||
let (t, remaining) = assert_parse_ok(number, valid);
|
||||
assert_eq!(expected_next, remaining);
|
||||
assert_eq!(
|
||||
Some(expected_val),
|
||||
t.numeric_value(),
|
||||
"{valid} has incorrect numeric value, expected {expected_val} {t:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_word() {
|
||||
for valid in ["a", "a ", "a5", "a5a"] {
|
||||
assert_parse_ok(word, valid);
|
||||
}
|
||||
|
||||
for invalid in ["5", "5a", "5a5"] {
|
||||
assert_parse_err(word, invalid);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_operator() {
|
||||
for valid in [
|
||||
"+", "+ ", "-", "<=", "<= ", ">=", ">= ", "> ", "< ", "|> ", "^ ", "% ", "+* ", "| ", "& ",
|
||||
] {
|
||||
assert_parse_ok(operator, valid);
|
||||
}
|
||||
|
||||
for invalid in ["5 + 5", "a", "a+", "a+5", "5a+5", ", newVar", ","] {
|
||||
assert_parse_err(operator, invalid);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_string() {
|
||||
for valid in [
|
||||
"\"\"",
|
||||
"\"a\"",
|
||||
"\"a\" ",
|
||||
"\"a\"5",
|
||||
"'a'5",
|
||||
"\"with escaped \\\" backslash\"",
|
||||
"\'with escaped \\\' backslash\'",
|
||||
"'c'",
|
||||
] {
|
||||
assert_parse_ok(string, valid);
|
||||
}
|
||||
|
||||
for invalid in ["\"", "\"a", "a\"", " \"a\"", "5\"a\"", "a + 'str'"] {
|
||||
assert_parse_err(string, invalid);
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
fn assert_tokens(expected: &[(TokenType, usize, usize)], actual: TokenSlice) {
|
||||
let mut e = 0;
|
||||
let mut issues = vec![];
|
||||
for a in actual {
|
||||
if expected[e].0 != a.token_type {
|
||||
if a.token_type == TokenType::Whitespace {
|
||||
continue;
|
||||
}
|
||||
issues.push(format!(
|
||||
"Type mismatch: expected `{}`, found `{}` (`{a:?}`), at index {e}",
|
||||
expected[e].0, a.token_type
|
||||
));
|
||||
}
|
||||
|
||||
if expected[e].1 != a.start || expected[e].2 != a.end {
|
||||
issues.push(format!(
|
||||
"Source range mismatch: expected {}-{}, found {}-{} (`{a:?}`), at index {e}",
|
||||
expected[e].1, expected[e].2, a.start, a.end
|
||||
));
|
||||
}
|
||||
|
||||
e += 1;
|
||||
}
|
||||
if e < expected.len() {
|
||||
issues.push(format!("Expected `{}` tokens, found `{e}`", expected.len()));
|
||||
}
|
||||
assert!(issues.is_empty(), "{}", issues.join("\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program0() {
|
||||
let program = "const a=5";
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex(program, module_id).unwrap();
|
||||
|
||||
use TokenType::*;
|
||||
assert_tokens(
|
||||
&[(Keyword, 0, 5), (Word, 6, 7), (Operator, 7, 8), (Number, 8, 9)],
|
||||
actual.as_slice(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program1() {
|
||||
let program = "54 + 22500 + 6";
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex(program, module_id).unwrap();
|
||||
|
||||
use TokenType::*;
|
||||
assert_tokens(
|
||||
&[
|
||||
(Number, 0, 2),
|
||||
(Operator, 3, 4),
|
||||
(Number, 5, 10),
|
||||
(Operator, 11, 12),
|
||||
(Number, 13, 14),
|
||||
],
|
||||
actual.as_slice(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program2() {
|
||||
let program = r#"const part001 = startSketchAt([0.0000000000, 5.0000000000])
|
||||
|> line([0.4900857016, -0.0240763666], %)
|
||||
|
||||
const part002 = "part002"
|
||||
const things = [part001, 0.0]
|
||||
let blah = 1
|
||||
const foo = false
|
||||
let baz = {a: 1, part001: "thing"}
|
||||
|
||||
fn ghi = (part001) => {
|
||||
return part001
|
||||
}
|
||||
|
||||
show(part001)"#;
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex(program, module_id).unwrap();
|
||||
insta::assert_debug_snapshot!(actual.tokens);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program3() {
|
||||
let program = r#"
|
||||
// this is a comment
|
||||
const yo = { a: { b: { c: '123' } } }
|
||||
|
||||
const key = 'c'
|
||||
const things = "things"
|
||||
|
||||
// this is also a comment"#;
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex(program, module_id).unwrap();
|
||||
|
||||
use TokenType::*;
|
||||
assert_tokens(
|
||||
&[
|
||||
(Whitespace, 0, 1),
|
||||
(LineComment, 1, 21),
|
||||
(Whitespace, 21, 22),
|
||||
(Keyword, 22, 27),
|
||||
(Whitespace, 27, 28),
|
||||
(Word, 28, 30),
|
||||
(Whitespace, 30, 31),
|
||||
(Operator, 31, 32),
|
||||
(Whitespace, 32, 33),
|
||||
(Brace, 33, 34),
|
||||
(Whitespace, 34, 35),
|
||||
(Word, 35, 36),
|
||||
(Colon, 36, 37),
|
||||
(Whitespace, 37, 38),
|
||||
(Brace, 38, 39),
|
||||
(Whitespace, 39, 40),
|
||||
(Word, 40, 41),
|
||||
(Colon, 41, 42),
|
||||
(Whitespace, 42, 43),
|
||||
(Brace, 43, 44),
|
||||
(Whitespace, 44, 45),
|
||||
(Word, 45, 46),
|
||||
(Colon, 46, 47),
|
||||
(Whitespace, 47, 48),
|
||||
(String, 48, 53),
|
||||
(Whitespace, 53, 54),
|
||||
(Brace, 54, 55),
|
||||
(Whitespace, 55, 56),
|
||||
(Brace, 56, 57),
|
||||
(Whitespace, 57, 58),
|
||||
(Brace, 58, 59),
|
||||
(Whitespace, 59, 61),
|
||||
(Keyword, 61, 66),
|
||||
(Whitespace, 66, 67),
|
||||
(Word, 67, 70),
|
||||
(Whitespace, 70, 71),
|
||||
(Operator, 71, 72),
|
||||
(Whitespace, 72, 73),
|
||||
(String, 73, 76),
|
||||
(Whitespace, 76, 77),
|
||||
(Keyword, 77, 82),
|
||||
(Whitespace, 82, 83),
|
||||
(Word, 83, 89),
|
||||
(Whitespace, 89, 90),
|
||||
(Operator, 90, 91),
|
||||
(Whitespace, 91, 92),
|
||||
(String, 92, 100),
|
||||
(Whitespace, 100, 102),
|
||||
(LineComment, 102, 127),
|
||||
],
|
||||
actual.as_slice(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_program4() {
|
||||
let program = "const myArray = [0..10]";
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex(program, module_id).unwrap();
|
||||
|
||||
use TokenType::*;
|
||||
assert_tokens(
|
||||
&[
|
||||
(Keyword, 0, 5),
|
||||
(Word, 6, 13),
|
||||
(Operator, 14, 15),
|
||||
(Brace, 16, 17),
|
||||
(Number, 17, 18),
|
||||
(DoublePeriod, 18, 20),
|
||||
(Number, 20, 22),
|
||||
(Brace, 22, 23),
|
||||
],
|
||||
actual.as_slice(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lexer_negative_word() {
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex("-legX", module_id).unwrap();
|
||||
|
||||
use TokenType::*;
|
||||
assert_tokens(&[(Operator, 0, 1), (Word, 1, 5)], actual.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_eq() {
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex("!=", module_id).unwrap();
|
||||
let expected = vec![Token {
|
||||
token_type: TokenType::Operator,
|
||||
value: "!=".to_owned(),
|
||||
start: 0,
|
||||
end: 2,
|
||||
module_id,
|
||||
}];
|
||||
assert_eq!(actual.tokens, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unrecognized_token() {
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex("12 ; 8", module_id).unwrap();
|
||||
|
||||
use TokenType::*;
|
||||
assert_tokens(&[(Number, 0, 2), (Unknown, 3, 4), (Number, 5, 6)], actual.as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_keyword() {
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex("import foo", module_id).unwrap();
|
||||
let expected = Token {
|
||||
token_type: TokenType::Keyword,
|
||||
value: "import".to_owned(),
|
||||
start: 0,
|
||||
end: 6,
|
||||
module_id,
|
||||
};
|
||||
assert_eq!(actual.tokens[0], expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_function() {
|
||||
let module_id = ModuleId::from_usize(1);
|
||||
let actual = lex("import(3)", module_id).unwrap();
|
||||
let expected = Token {
|
||||
token_type: TokenType::Word,
|
||||
value: "import".to_owned(),
|
||||
start: 0,
|
||||
end: 6,
|
||||
module_id,
|
||||
};
|
||||
assert_eq!(actual.tokens[0], expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_code_token() {
|
||||
let module_id = ModuleId::default();
|
||||
let actual = lex("foo (4/* comment */ +,2,\"sdfsdf\") // comment", module_id).unwrap();
|
||||
let non_code = [1, 4, 5, 12, 13];
|
||||
for i in 0..14 {
|
||||
if non_code.contains(&i) {
|
||||
assert!(
|
||||
!actual.tokens[i].is_code_token(),
|
||||
"failed test {i}: {:?}",
|
||||
&actual.tokens[i],
|
||||
);
|
||||
} else {
|
||||
assert!(
|
||||
actual.tokens[i].is_code_token(),
|
||||
"failed test {i}: {:?}",
|
||||
&actual.tokens[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn test_boolean_literal() {
|
||||
let module_id = ModuleId::default();
|
||||
let actual = lex("true", module_id).unwrap();
|
||||
let expected = Token {
|
||||
token_type: TokenType::Keyword,
|
||||
value: "true".to_owned(),
|
||||
start: 0,
|
||||
end: 4,
|
||||
module_id,
|
||||
};
|
||||
assert_eq!(actual.tokens[0], expected);
|
||||
}
|
||||
#[test]
|
||||
fn test_word_starting_with_keyword() {
|
||||
let module_id = ModuleId::default();
|
||||
let actual = lex("truee", module_id).unwrap();
|
||||
let expected = Token {
|
||||
token_type: TokenType::Word,
|
||||
value: "truee".to_owned(),
|
||||
start: 0,
|
||||
end: 5,
|
||||
module_id,
|
||||
};
|
||||
assert_eq!(actual.tokens[0], expected);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user