mirror of
https://github.com/vlang/v.git
synced 2025-09-12 17:07:11 -04:00
parser: fix ;
support for module x;
This commit is contained in:
parent
2cce907dcb
commit
2e0a6ea4d4
62
vlib/v/fmt/donut_card_expected.vv
Normal file
62
vlib/v/fmt/donut_card_expected.vv
Normal file
@ -0,0 +1,62 @@
|
||||
import math as m
|
||||
import term
|
||||
import strings
|
||||
import time { sleep }
|
||||
|
||||
const alt = '.,-~:;=!*#$@'
|
||||
|
||||
fn rd(cs int, ls int, a f64, b f64) {
|
||||
tt_spacing, p_spacing := 0.07, 0.02
|
||||
r1, r2, k2 := 1, 2, 5
|
||||
k1 := cs * k2 * 2 / (20 * (r1 + r2))
|
||||
c_a, s_a := m.cos(a), m.sin(a)
|
||||
c_b, s_b := m.cos(b), m.sin(b)
|
||||
mut o := [][]rune{len: cs, init: []rune{len: ls, init: ` `}}
|
||||
mut z_buffer := [][]f64{len: cs, init: []f64{len: ls, init: 0}}
|
||||
for tt := f64(0); tt < 2 * m.pi; tt += tt_spacing {
|
||||
c_tt, s_tt := m.cos(tt), m.sin(tt)
|
||||
for phi := f64(0); phi < 2 * m.pi; phi += p_spacing {
|
||||
c_p, s_p := m.cos(phi), m.sin(phi)
|
||||
c_x, c_y := r2 + r1 * c_tt, r1 * s_tt
|
||||
x := c_x * (c_b * c_p + s_a * s_b * s_p) - c_y * c_a * s_b
|
||||
y := c_x * (s_b * c_p - s_a * c_b * s_p) + c_y * c_a * c_b
|
||||
z := k2 + c_a * c_x * s_p + c_y * s_a
|
||||
ooz := 1 / z
|
||||
xp := int(cs / 2 + k1 * ooz * x)
|
||||
yp := int(ls / 2 - k1 * ooz * y)
|
||||
l := c_p * c_tt * s_b - c_a * c_tt * s_p - s_a * s_tt +
|
||||
c_b * (c_a * s_tt - c_tt * s_a * s_p)
|
||||
if l > 0 {
|
||||
if xp < 0 || yp < 0 || xp >= cs || yp >= ls {
|
||||
continue
|
||||
}
|
||||
if ooz > z_buffer[int(xp)][int(yp)] {
|
||||
z_buffer[xp][yp] = ooz
|
||||
lui := int(l * 8)
|
||||
o[xp][yp] = alt[lui]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mut sb := strings.new_builder(ls * cs)
|
||||
print('\x1b[H')
|
||||
for j := 0; j < ls; j++ {
|
||||
for i := 0; i < cs; i++ {
|
||||
sb.write_rune(o[i][j])
|
||||
}
|
||||
sb.write_rune(`\n`)
|
||||
}
|
||||
print(sb.str())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
term.clear()
|
||||
cs, ls := 80, 25
|
||||
mut a, mut b := f64(0), f64(0)
|
||||
for {
|
||||
rd(cs, ls, a, b)
|
||||
a += 0.05
|
||||
b += 0.07
|
||||
sleep(15 * time.millisecond)
|
||||
}
|
||||
}
|
18
vlib/v/fmt/donut_card_input.vv
Normal file
18
vlib/v/fmt/donut_card_input.vv
Normal file
@ -0,0 +1,18 @@
|
||||
import math as m; import term;import strings;import time{sleep}; const
|
||||
alt = '.,-~:;=!*#$@';[direct_array_access];fn rd(cs int, ls int,a f64,
|
||||
b f64) {tt_spacing, p_spacing:=0.07,0.02; r1,r2,k2 :=1,2,5; k1:=cs*k2*
|
||||
2/(20*(r1+r2));c_a,s_a:=m.cos(a),m.sin(a);c_b,s_b:=m.cos(b), m.sin(b);
|
||||
mut o:=[][]rune{len:cs, init:[]rune{len:ls,init:` `}}; mut z_buffer :=
|
||||
[][]f64{len:cs, init:[]f64{ len:ls,init: 0}};for tt:=f64(0);tt<2*m.pi;
|
||||
tt+=tt_spacing{c_tt,s_tt:=m.cos(tt),m.sin(tt);for phi:=f64(0);phi<2*m.
|
||||
pi;phi+=p_spacing{c_p,s_p:=m.cos(phi),m.sin(phi); c_x,c_y:= r2+r1*c_tt
|
||||
,r1*s_tt;x:=c_x*(c_b*c_p+s_a*s_b*s_p)-c_y*c_a*s_b;y:=c_x*(s_b*c_p-s_a*
|
||||
c_b*s_p)+c_y*c_a*c_b;z:=k2+c_a*c_x*s_p+c_y*s_a;ooz:=1/z;xp:= int(cs/2+
|
||||
k1*ooz*x);yp:=int(ls/2-k1*ooz*y);l:=c_p*c_tt*s_b-c_a*c_tt*s_p-s_a*s_tt
|
||||
+c_b*(c_a*s_tt-c_tt*s_a*s_p);if l>0{ if xp<0 || yp<0 ||xp>=cs||yp>=ls{
|
||||
continue};if ooz>z_buffer[int(xp)][int(yp)]{ z_buffer[xp][yp]=ooz; lui
|
||||
:= int(l*8);o[xp][yp] = alt[lui]}}}};mut sb:=strings.new_builder(ls*cs
|
||||
);;;; print('\x1b[H');;;;; for j:=0; j<ls; j++ { for i:=0; i<cs; i++ {
|
||||
sb.write_rune(o[i][j])};sb.write_rune(`\n`);}print(sb.str())};fn main(
|
||||
){ term.clear(); cs,ls := 80,25; mut a,mut b := f64(0), f64(0);for{rd(
|
||||
cs, ls, a, b); a += 0.05 ; b += 0.07; sleep( 15 * time.millisecond )}}
|
@ -801,6 +801,9 @@ fn (mut p Parser) top_stmt() ast.Stmt {
|
||||
.comment {
|
||||
return p.comment_stmt()
|
||||
}
|
||||
.semicolon {
|
||||
return p.semicolon_stmt()
|
||||
}
|
||||
else {
|
||||
return p.other_stmts(ast.empty_stmt)
|
||||
}
|
||||
@ -3504,7 +3507,7 @@ fn (mut p Parser) module_decl() ast.Module {
|
||||
// as it creates a wrong position when extended
|
||||
// to module_pos
|
||||
n_pos := p.tok.pos()
|
||||
if module_pos.line_nr == n_pos.line_nr && p.tok.kind != .comment && p.tok.kind != .eof {
|
||||
if module_pos.line_nr == n_pos.line_nr && p.tok.kind !in [.comment, .eof, .semicolon] {
|
||||
if p.tok.kind == .name {
|
||||
p.unexpected_with_pos(n_pos,
|
||||
prepend_msg: '`module ${name}`, you can only declare one module,'
|
||||
@ -3532,6 +3535,9 @@ fn (mut p Parser) module_decl() ast.Module {
|
||||
pos: module_pos
|
||||
name_pos: name_pos
|
||||
}
|
||||
if p.tok.kind == .semicolon {
|
||||
p.check(.semicolon)
|
||||
}
|
||||
if !is_skipped {
|
||||
p.table.module_attrs[p.mod] = module_attrs
|
||||
for ma in module_attrs {
|
||||
|
Loading…
x
Reference in New Issue
Block a user