presidentbeef / brat Goto Github PK
View Code? Open in Web Editor NEWBrat is a little language for people who don't like to be told what to do.
Home Page: https://www.brat-lang.info/
Brat is a little language for people who don't like to be told what to do.
Home Page: https://www.brat-lang.info/
Right now, errors are thrown using $throw(string).
Instead, use an exception object with a type and message. Standardize a bit.
I'm not familiar with Brat's internals, so I can't debug it any further. But, I am not sure if you noticed this, and maybe it helps debugging.
The code is pretty much directly taken from test-examples.brat
, but with the testy parts commented out.
If you run this code as-is, it prints true true
#*
include :assert
setup name: :x {
test "mutual recursion" {
*#
female = null #yes, this is necessary
male = { n |
true? n == 0
{ 0 }
{ n - female male(n - 1) }
}
female = { n |
true? n == 0
{ 1 }
{ n - male female(n - 1 ) }
}
p ([1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10, 11, 11, 12, 13] == {
0.to(20).map! { n | female n }
}())
p ([0, 0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 12] == {
0.to(20).map! { n | male n }
}())
#*
assert_equal [1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 8, 8, 9, 9, 10, 11, 11, 12, 13] {
0.to(20).map! { n | female n }
}
assert_equal [0, 0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 12] {
0.to(20).map! { n | male n }
}
}
}
*#
But if you uncomment the test framework, then it prints
Test failure(s):
1. 'mutual recursion': mrec.lua:888: attempt to call local '_temp6' (a table value)
So, user code can use mutual recursion as long as it isn't inside setup
/ test
?
I've tried for several hours to build on macOSx Mojave 10.14.5
I have fixed a few problems building Lua, but the build fails with
env MACOSX_DEPLOYMENT_TARGET=10.3 gcc -bundle -undefined dynamic_lookup -o md5.so lmd5.o -lcrypto
ld: library not found for -lcrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [md5.so] Error 1
While Building Oniguruma
is being executed.
I added make MACOSX_DEPLOYMENT_TARGET=10.6 DEFAULT_CC=clang -j8 PREFIX=$BRATPATH/bin/lua
to line 41 in the build file which helped a few errors.
I currently have ./configure && CFLAGS="-I/usr/local/Cellar/openssl/1.0.2k/include /usr/local/Cellar//openssl/1.0.2s/lib" make MACOSX_DEPLOYMENT_TARGET=10.6 DEFAULT_CC=clang -j8
on line 50 with no success.
Any pointers? I love Brat and would enjoy using it on my Mac, and hopefully contributing more.
In online interpreter this code does not work:
#;+
p "hi"
For arrays.
fresh install on:
mac os x v. 10.6.7
gcc version 4.2.1 (Apple Inc. build 5664)
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
treetop (1.4.9)
$ ./build
make -C src/oniguruma -f rex_onig.mak
gcc -bundle -undefined dynamic_lookup -o rex_onig.so.2.4 lonig.o lonig_f.o ../common.o -L/Users/ben/src/brat/presidentbeef-brat-d73f103/bin/lua//lib -lonig
ld: library not found for -lonig
brew install oniguruma
command 'tt' is missing
I hard coded tt path ~/.gem/... into build.sh
regards
ben
This may be intended behaviour, but the string interpolation "#{value}"
functionality doesn't seem to work in the interactive
repl.
# Interactive Brat
brat:1> a = 1
#=> 1
brat:2> p "#{a}"
#=> [string "interactive"]:12: attempt to index global '_table' (a nil value)
This does, however, work if you create a file and run brat my_file.brat
.
@presidentbeef I believe the URL brat-lang.org
has been hijacked, I was redirected to a page full of NSFW content.
I tried deploying Brat on a MacOS X thinking it would work cause MacOS X is Unix based.
When running brat command, I already obtained the error message :
lua: error loading module 'lfs' from file '/Developer/usr/bin/brat/lib/lfs.so':
dlopen(/Developer/usr/bin/brat/lib/lfs.so, 2): no suitable image found. Did find:
/Developer/usr/bin/brat/lib/lfs.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
stack traceback:
C: in function 'require'
/Developer/usr/bin/brat/bin/brat:13: in main chunk
I know Brat is not supposed to be deployed on another OS than Linux but maybe it's not a big fix to make it deployable on MacOS :D
build.sh tries to find "luajit" as "lua". Should be a simple fix.
As a workaround, I've uninstalled the normal lua, and made a symlink on my PATH.
when i start ./install.sh
mkdir: невозможно создать каталог «/usr/lib/brat/»: Файл существует
Building fresh parser...
./install.sh: line 12: tt: команда не найдена
These work:
p p(1)
p (p 1)
p p 1
p p, 1
p 9 8
p 9, 8
These don't
p (p, 1)
(9, 8)
(9 8)
9 8
p (9 8)
p (9, 8)
I think some of these are valid syntax.
They all fail with the same inexplicable error:
lua: Method error: false has no method called 'ast'.
stack traceback:
[C]: in function '_error'
stdlib/parser/brat2lua.lua:547: in function 'run'
bin/brat:108: in function 'interactive'
bin/brat:142: in main chunk
[C]: at 0x5606b9b5d150
Sorry for so many issues; I really like Brat.
I was interested in extending true?
, null?
etc so they give the condition argument to their true/false branches, so that true? 4 { x | p x }
would print 4. I have added the feature: catb0t@65fc9dd
However, I think have found a parser bug with literals and functions in argument lists. There is no combination of parentheses and commas that allows this to parse correctly; there is always a name error for x
:
true? 4 { x | x }
However these give 4
:
true? 4 { 4 }
f = { x | x }
true? 4 ->f
Similarly, this gives true
(which is not the condition):
null? null { x | x } { x | x }
I understand that probably parses as null?(null({ x | x }({x | x})))
, but adding commas like so is also a name error
null? null, { x | x }, { x | x } # x is not declared
Again, it can be worked around by not using a literal:
f = { x | x }
null? null, ->f, ->f # => null
In some cases even ->f
doesn't help; if f
is undeclared then false? 4, 0, ->f
(or any comma combination of that) will do nothing but wait for a keypress in interactive mode.
If f is declared:
f = {x | x}
false? 4, 0, ->f
#=> Argument error: function expected 1 argument(s) but was given 0.
But this is a problem with the way 0, ->f
is parsed, because false?
definitely gives the condition to the function branch.
The builtin function "find" doesnt seem to work, atleast not in the try brat online editor.
Code:
"amogus".find "gus"
Ouput:
/home/brat/brat/core/core.lua:2184: attempt to call upvalue 'block' (a table value)
stack traceback:
/home/brat/brat/core/core.lua: in function 'block'
/home/brat/brat/core/core.lua:4440: in function 'each'
/home/brat/brat/core/core.lua:2189: in function '_m__temp1_find'
[string "string"]:41: in function '_m__temp3_run_underparsed'
[string "string"]:209: in function <[string "string"]:12>
stack traceback:
[string "string"]:336: in main chunk
[C]: in function 'xpcall'
/home/brat/brat/core/core.lua:1304: in function 'protect'
/home/brat/brat/bin/brat:137: in function 'run_string'
/home/brat/brat/bin/brat:162: in main chunk
[C]: at 0x5650922ed5b0
Interestingly .include?
works but not find
mac os x v. 10.6.7
gcc version 4.2.1 (Apple Inc. build 5664)
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
treetop (1.4.9)
./build.sh => ok
./tests => ok
sudo ./install => ok
Problems:
$ brat
env: lua: No such file or directory
manual solution:
export PATH=$PATH:/usr/lib/brat/lua/bin/
$ brat
lua: /usr/lib/brat//brat:13: module 'lfs' not found:
no field package.preload['lfs']
no file './lfs.lua'
no file '/homes/ben/src/brat/brat/bin/lua/share/luajit-2.0.0-beta7/lfs.lua'
no file '/usr/local/share/lua/5.1/lfs.lua'
no file '/usr/local/share/lua/5.1/lfs/init.lua'
no file '/homes/ben/src/brat/brat/bin/lua/share/lua/5.1/lfs.lua'
no file '/homes/ben/src/brat/brat/bin/lua/share/lua/5.1/lfs/init.lua'
no file '../core/lfs.lua'
no file '../stdlib/lfs.lua'
no file '../lib/lfs.lua'
no file './lfs.so'
no file '/usr/local/lib/lua/5.1/lfs.so'
no file '/homes/ben/src/brat/brat/bin/lua/lib/lua/5.1/lfs.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '../lib/lfs.so'
stack traceback:
[C]: in function 'require'
/usr/lib/brat//brat:13: in main chunk
[C]: ?
I've tried to fix this by hacking in bin/brat, but had no luck.
Please have a look into this.
thanks
ben
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.