summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-10-19 18:27:47 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-10-19 18:27:47 (GMT)
commit05b2eb1b90620025ba9242477b0df688745dd0db (patch)
treecfa890ef8e4bb5182ba988cf817c482e2fc639e1
parent7c998717209c4ea3cd8edf329baa3e5040d15266 (diff)
Clifford Wolf:
Fixed scalar subtraction Fixed handling of -/+ scalar prefix Fixed vector handling [0 1 2] doesn't work anymore now git-svn-id: http://svn.clifford.at/openscad/trunk@109 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r--examples/example001.scad9
-rw-r--r--examples/example002.scad14
-rw-r--r--examples/example003.scad14
-rw-r--r--examples/example005.scad9
-rw-r--r--examples/example006.scad28
-rw-r--r--examples/example007.scad32
-rw-r--r--examples/example008.scad16
-rw-r--r--examples/example010.scad2
-rw-r--r--examples/example011.scad20
-rw-r--r--examples/example012.scad2
-rw-r--r--lexer.l3
-rw-r--r--mainwin.cc10
-rw-r--r--openscad.h1
-rw-r--r--parser.y24
-rw-r--r--value.cc2
15 files changed, 90 insertions, 96 deletions
diff --git a/examples/example001.scad b/examples/example001.scad
index 87e091d..50bf8ff 100644
--- a/examples/example001.scad
+++ b/examples/example001.scad
@@ -4,14 +4,15 @@ module example001()
function r_from_dia(d) = d / 2;
module rotcy(rot, r, h) {
- rotate(90, rot) cylinder(r = r, h = h, center = true);
+ rotate(90, rot)
+ cylinder(r = r, h = h, center = true);
}
difference() {
sphere(r = r_from_dia(size));
- rotcy([0 0 0], cy_r, cy_h);
- rotcy([1 0 0], cy_r, cy_h);
- rotcy([ 0 1 0], cy_r, cy_h);
+ rotcy([0, 0, 0], cy_r, cy_h);
+ rotcy([1, 0, 0], cy_r, cy_h);
+ rotcy([0, 1, 0], cy_r, cy_h);
}
size = 50;
diff --git a/examples/example002.scad b/examples/example002.scad
index ce9a516..6c4587f 100644
--- a/examples/example002.scad
+++ b/examples/example002.scad
@@ -4,17 +4,17 @@ module example002()
intersection() {
difference() {
union() {
- cube([30 30 30], center = true);
- translate([0 0 -25])
- cube([15 15 50], center = true);
+ cube([30, 30, 30], center = true);
+ translate([0, 0, -25])
+ cube([15, 15, 50], center = true);
}
union() {
- cube([50 10 10], center = true);
- cube([10 50 10], center = true);
- cube([10 10 50], center = true);
+ cube([50, 10, 10], center = true);
+ cube([10, 50, 10], center = true);
+ cube([10, 10, 50], center = true);
}
}
- translate([0 0 5])
+ translate([0, 0, 5])
cylinder(h = 50, r1 = 20, r2 = 5, center = true);
}
}
diff --git a/examples/example003.scad b/examples/example003.scad
index 2add654..531b3b4 100644
--- a/examples/example003.scad
+++ b/examples/example003.scad
@@ -3,15 +3,15 @@ module example003()
{
difference() {
union() {
- cube([30 30 30], center = true);
- cube([40 15 15], center = true);
- cube([15 40 15], center = true);
- cube([15 15 40], center = true);
+ cube([30, 30, 30], center = true);
+ cube([40, 15, 15], center = true);
+ cube([15, 40, 15], center = true);
+ cube([15, 15, 40], center = true);
}
union() {
- cube([50 10 10], center = true);
- cube([10 50 10], center = true);
- cube([10 10 50], center = true);
+ cube([50, 10, 10], center = true);
+ cube([10, 50, 10], center = true);
+ cube([10, 10, 50], center = true);
}
}
}
diff --git a/examples/example005.scad b/examples/example005.scad
index 9256149..08f0780 100644
--- a/examples/example005.scad
+++ b/examples/example005.scad
@@ -1,21 +1,20 @@
module example005()
{
- translate([0 0 -120]) {
+ translate([0, 0, -120]) {
difference() {
cylinder(h = 50, r = 100);
- translate([0 0 10]) cylinder(h = 50, r = 80);
- translate([100 0 35]) cube(50, center = true);
+ translate([0, 0, 10]) cylinder(h = 50, r = 80);
+ translate([100, 0, 35]) cube(50, center = true);
}
for (i = [0:5]) {
echo(360*i/6, sin(360*i/6)*80, cos(360*i/6)*80);
translate([sin(360*i/6)*80, cos(360*i/6)*80, 0 ])
cylinder(h = 200, r=10);
}
- translate([0 0 200])
+ translate([0, 0, 200])
cylinder(h = 80, r1 = 120, r2 = 0);
}
}
example005();
-
diff --git a/examples/example006.scad b/examples/example006.scad
index 26143a1..548339d 100644
--- a/examples/example006.scad
+++ b/examples/example006.scad
@@ -4,12 +4,12 @@ module example006()
module edgeprofile()
{
render(convexity = 2) difference() {
- cube([20 20 150], center = true);
- translate([-10 -10 0])
+ cube([20, 20, 150], center = true);
+ translate([-10, -10, 0])
cylinder(h = 80, r = 10, center = true);
- translate([-10 -10 +40])
+ translate([-10, -10, +40])
sphere(r = 10);
- translate([-10 -10 -40])
+ translate([-10, -10, -40])
sphere(r = 10);
}
}
@@ -17,23 +17,23 @@ module example006()
difference()
{
cube(100, center = true);
- for (rot = [ [0 0 0], [1 0 0], [0 1 0] ]) {
+ for (rot = [ [0, 0, 0], [1, 0, 0], [0, 1, 0] ]) {
rotate(90, rot)
- for (p = [[+1 +1 0], [-1 +1 90], [-1 -1 180], [+1 -1 270]]) {
+ for (p = [[+1, +1, 0], [-1, +1, 90], [-1, -1, 180], [+1, -1, 270]]) {
translate([ p[0]*50, p[1]*50, 0 ])
- rotate(p[2], [0 0 1])
+ rotate(p[2], [0, 0, 1])
edgeprofile();
}
}
for (i = [
- [ 0, 0, [ [0 0] ] ],
- [ 90, 0, [ [-20 -20], [+20 +20] ] ],
- [ 180, 0, [ [-20 -25], [-20 0], [-20 +25], [+20 -25], [+20 0], [+20 +25] ] ],
- [ 270, 0, [ [0 0], [-25 -25], [+25 -25], [-25 +25], [+25 +25] ] ],
- [ 0, 90, [ [-25 -25], [0 0], [+25 +25] ] ],
- [ 0, -90, [ [-25 -25], [+25 -25], [-25 +25], [+25 +25] ] ]
+ [ 0, 0, [ [0, 0] ] ],
+ [ 90, 0, [ [-20, -20], [+20, +20] ] ],
+ [ 180, 0, [ [-20, -25], [-20, 0], [-20, +25], [+20, -25], [+20, 0], [+20, +25] ] ],
+ [ 270, 0, [ [0, 0], [-25, -25], [+25, -25], [-25, +25], [+25, +25] ] ],
+ [ 0, 90, [ [-25, -25], [0, 0], [+25, +25] ] ],
+ [ 0, -90, [ [-25, -25], [+25, -25], [-25, +25], [+25, +25] ] ]
]) {
- rotate(i[0], [0 0 1]) rotate(i[1], [1 0 0]) translate([0 -50 0])
+ rotate(i[0], [0, 0, 1]) rotate(i[1], [1, 0, 0]) translate([0, -50, 0])
for (j = i[2])
translate([j[0], 0, j[1]]) sphere(10);
}
diff --git a/examples/example007.scad b/examples/example007.scad
index 19415bf..fe69f84 100644
--- a/examples/example007.scad
+++ b/examples/example007.scad
@@ -3,17 +3,17 @@ module cutout()
{
intersection()
{
- rotate(90, [1 0 0])
- translate([0 0 -50])
+ rotate(90, [1, 0, 0])
+ translate([0, 0, -50])
dxf_linear_extrude(
file = "example007.dxf",
layer = "cutout1",
height = 100,
convexity = 1);
- rotate(90, [0 0 1])
- rotate(90, [1 0 0])
- translate([0 0 -50])
+ rotate(90, [0, 0, 1])
+ rotate(90, [1, 0, 0])
+ translate([0, 0, -50])
dxf_linear_extrude(
file = "example007.dxf",
layer = "cutout2",
@@ -29,8 +29,8 @@ module clip()
file = "example007.dxf",
layer="dorn",
convexity = 3);
- for (r = [0 90])
- rotate(r, [0 0 1])
+ for (r = [0, 90])
+ rotate(r, [0, 0, 1])
cutout();
}
}
@@ -41,29 +41,29 @@ module cutview()
{
difference()
{
- translate([0 0 -10])
+ translate([0, 0, -10])
clip();
- rotate(20, [0 0 1])
- rotate(-20, [0 1 0])
- translate([18 0 0])
+ rotate(20, [0, 0, 1])
+ rotate(-20, [0, 1, 0])
+ translate([18, 0, 0])
cube(30, center = true);
}
# render(convexity = 5) intersection()
{
- translate([0 0 -10])
+ translate([0, 0, -10])
clip();
- rotate(20, [0 0 1])
- rotate(-20, [0 1 0])
- translate([18 0 0])
+ rotate(20, [0, 0, 1])
+ rotate(-20, [0, 1, 0])
+ translate([18, 0, 0])
cube(30, center = true);
}
}
}
-translate([0 0 -10])
+translate([0, 0, -10])
clip();
// cutview();
diff --git a/examples/example008.scad b/examples/example008.scad
index adf1a58..e1b0ac4 100644
--- a/examples/example008.scad
+++ b/examples/example008.scad
@@ -3,29 +3,29 @@ difference()
{
intersection()
{
- translate([ -25 -25 -25])
+ translate([ -25, -25, -25])
dxf_linear_extrude(file = "example008.dxf",
layer = "G", height = 50, convexity = 3);
- rotate(90, [1 0 0])
- translate([ -25 -125 -25])
+ rotate(90, [1, 0, 0])
+ translate([ -25, -125, -25])
dxf_linear_extrude(file = "example008.dxf",
layer = "E", height = 50, convexity = 3);
- rotate(90, [0 1 0])
- translate([ -125 -125 -25])
+ rotate(90, [0, 1, 0])
+ translate([ -125, -125, -25])
dxf_linear_extrude(file = "example008.dxf",
layer = "B", height = 50, convexity = 3);
}
intersection()
{
- translate([ -125 -25 -25])
+ translate([ -125, -25, -25])
dxf_linear_extrude(file = "example008.dxf",
layer = "X", height = 50, convexity = 1);
- rotate(90, [0 1 0])
- translate([ -125 -25 -25])
+ rotate(90, [0, 1, 0])
+ translate([ -125, -25, -25])
dxf_linear_extrude(file = "example008.dxf",
layer = "X", height = 50, convexity = 1);
}
diff --git a/examples/example010.scad b/examples/example010.scad
index cb449e7..45922dd 100644
--- a/examples/example010.scad
+++ b/examples/example010.scad
@@ -8,7 +8,7 @@ intersection()
surface(file = "example010.dat",
center = true, convexity = 5);
- rotate(45, [0 0 1])
+ rotate(45, [0, 0, 1])
surface(file = "example010.dat",
center = true, convexity = 5);
}
diff --git a/examples/example011.scad b/examples/example011.scad
index c11e65b..f35af05 100644
--- a/examples/example011.scad
+++ b/examples/example011.scad
@@ -1,16 +1,16 @@
polyeder(
points = [
- [10 0 0],
- [ 0 10 0],
- [ -10 0 0],
- [ 0 -10 0],
- [ 0 0 10]
+ [10, 0, 0],
+ [0, 10, 0],
+ [-10, 0, 0],
+ [0, -10, 0],
+ [0, 0, 10]
],
triangles = [
- [0 1 2 3],
- [4 1 0],
- [4 2 1],
- [4 3 2],
- [4 0 3]
+ [0, 1, 2, 3],
+ [4, 1, 0],
+ [4, 2, 1],
+ [4, 3, 2],
+ [4, 0, 3]
]
);
diff --git a/examples/example012.scad b/examples/example012.scad
index d77b391..677154a 100644
--- a/examples/example012.scad
+++ b/examples/example012.scad
@@ -7,6 +7,6 @@ difference()
{
sphere(20);
- translate([ -2.92 0.5 +20 ]) rotate([180 0 180])
+ translate([ -2.92, 0.5, +20 ]) rotate([180, 0, 180])
import_stl("example012.stl", convexity = 5);
}
diff --git a/lexer.l b/lexer.l
index b0975fb..68fc402 100644
--- a/lexer.l
+++ b/lexer.l
@@ -42,6 +42,7 @@ extern const char *parser_input_buffer;
if (*parser_input_buffer) { \
result = 1; \
buf[0] = *(parser_input_buffer++); \
+ parser_error_pos++; \
} else { \
result = YY_NULL; \
} \
@@ -86,7 +87,7 @@ extern const char *parser_input_buffer;
"false" return TOK_FALSE;
"undef" return TOK_UNDEF;
-[+-]?[0-9][0-9.]* { parserlval.number = atof(yytext); return TOK_NUMBER; }
+[0-9][0-9.]* { parserlval.number = atof(yytext); return TOK_NUMBER; }
"$"?[a-zA-Z0-9_]+ { parserlval.text = strdup(yytext); return TOK_ID; }
\"[^"]*\" {
diff --git a/mainwin.cc b/mainwin.cc
index 6dba9c8..23357c7 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -354,8 +354,12 @@ void MainWindow::compile(bool procevents)
root_ctx.set_variable("$t", Value(e_tval->text().toDouble()));
root_module = parse(editor->toPlainText().toAscii().data(), false);
- if (!root_module)
+ if (!root_module) {
+ QTextCursor cursor = editor->textCursor();
+ cursor.setPosition(parser_error_pos);
+ editor->setTextCursor(cursor);
goto fail;
+ }
PRINT("Compiling design (CSG Tree generation)...");
if (procevents)
@@ -608,7 +612,7 @@ void MainWindow::pasteViewportTranslation()
{
QTextCursor cursor = editor->textCursor();
QString txt;
- txt.sprintf("[ %.2f %.2f %.2f ]", -screen->object_trans_x, -screen->object_trans_y, -screen->object_trans_z);
+ txt.sprintf("[ %.2f, %.2f, %.2f ]", -screen->object_trans_x, -screen->object_trans_y, -screen->object_trans_z);
cursor.insertText(txt);
}
@@ -616,7 +620,7 @@ void MainWindow::pasteViewportRotation()
{
QTextCursor cursor = editor->textCursor();
QString txt;
- txt.sprintf("[ %.2f %.2f %.2f ]",
+ txt.sprintf("[ %.2f, %.2f, %.2f ]",
fmodf(360 - screen->object_rot_x + 90, 360), fmodf(360 - screen->object_rot_y, 360), fmodf(360 - screen->object_rot_z, 360));
cursor.insertText(txt);
}
diff --git a/openscad.h b/openscad.h
index 5345e7c..c090ccf 100644
--- a/openscad.h
+++ b/openscad.h
@@ -800,6 +800,7 @@ private slots:
extern AbstractModule *parse(const char *text, int debug);
extern int get_fragments_from_r(double r, double fn, double fs, double fa);
+extern int parser_error_pos;
extern QPointer<MainWindow> current_win;
#ifdef ENABLE_CGAL
diff --git a/parser.y b/parser.y
index e82f451..26acb99 100644
--- a/parser.y
+++ b/parser.y
@@ -22,6 +22,8 @@
#include "openscad.h"
+int parser_error_pos = -1;
+
int parserlex(void);
void yyerror(char const *s);
@@ -79,7 +81,6 @@ public:
%right '?' ':'
%type <expr> expr
-%type <value> vector_const
%type <expr> vector_expr
%type <inst> module_instantciation
@@ -275,11 +276,6 @@ expr:
$$->const_value = new Value();
$$->const_value->type = Value::VECTOR;
} |
- '[' vector_const ']' {
- $$ = new Expression();
- $$->type = "C";
- $$->const_value = $2;
- } |
'[' vector_expr ']' {
$$ = $2;
} |
@@ -400,18 +396,6 @@ expr:
delete $3;
} ;
-vector_const:
- TOK_NUMBER TOK_NUMBER {
- $$ = new Value();
- $$->type = Value::VECTOR;
- $$->vec.append(new Value($1));
- $$->vec.append(new Value($2));
- } |
- vector_const TOK_NUMBER {
- $$ = $1;
- $$->vec.append(new Value($2));
- } ;
-
vector_expr:
expr {
$$ = new Expression();
@@ -504,6 +488,7 @@ const char *parser_input_buffer;
AbstractModule *parse(const char *text, int debug)
{
lexerin = NULL;
+ parser_error_pos = -1;
parser_input_buffer = text;
module_stack.clear();
@@ -514,6 +499,9 @@ AbstractModule *parse(const char *text, int debug)
lexerlex_destroy();
+ if (module)
+ parser_error_pos = -1;
+
return module;
}
diff --git a/value.cc b/value.cc
index 8cb370d..2778e58 100644
--- a/value.cc
+++ b/value.cc
@@ -122,7 +122,7 @@ Value Value::operator - (const Value &v) const
return r;
}
if (type == NUMBER && v.type == NUMBER) {
- return Value(num + v.num);
+ return Value(num - v.num);
}
return Value();
}
contact: Jan Huwald // Impressum