Why does ocamldebug's install_printer report "Unbound identifier"? - ocaml

I've written print functions (print_id, for example) for several types in my program, and have loaded them into ocamldebug (with 'load_printer _build/default/print.cma') but when I try to install them (with 'install_printer print_id' or 'install_printer Print.print_id'), it fails (with 'Unbound identifier print_id' or 'Unbound identifier Print.print_id'). What am I missing?
open Error
open Ast
let print_id (Id { name; position }) =
begin
Format.open_box 5;
Format.print_string ("Id { name=" ^ name ^ ";");
Format.print_space ();
Format.print_string ("position=" ^ (string_of_position position) ^ " }");
Format.close_box;
end

Related

How to print errors in lua script without running script?

I'm new using Lua in C++. I have some problem with printing error of script.
My purpose is :
Find errors of syntax, function name using luaL_dofile or luaL_dostring without running code like
build codes in Visual studio.
(When using luaL_loadfile or luaL_loadstring, it just find syntax error like 'a == 1', but can't find function name error like 'prit(a)')
Want to print all errors.(In lua, if there was 2 or more errors, it only prints error that was occurred first)
For example I made lua script like this :
test.lua
function sayHello(name)
print("Hello, " .. name .. "!")
end
for a=0, 10
print(a)
end
sayHello()
and in c++ code :
test.cpp
...
int ret;
ret = luaL_dofile(LuaState, filename);
if(ret != 0) {
cout << "error : " << lua_tostring(LuaState, -1) << endl;
lua_pop(LuaState, 1);
}
I want to print errors like :
lua: test.lua:2: attempt to concatenate local `name' (a nil value)
lua: test.lua:7: `do' expected near `print'
Could anybody teach me?

Error while compiling protocol buffer on mac

I am following the tutorial for protocol buffers and I keep running into different errors while compiling. my addressbook.proto file is in /Users/flexmaster411/protobuffer
protoc -I=/Users/flexmaster411/protobuffer --python_out= /Users/flexmaster411/protobuffer/addressbook.proto /Users/flexmaster411/protobuffer
I keep getting the following error even though I have syntax = "proto3" on my proto file
[libprotobuf WARNING google/protobuf/compiler/parser.cc:471] No syntax specified for the proto file. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
Not sure if I have correctly done the destination folders set up which is causing this or not Any help appreciated
syntax = "proto3";
package tutorial;
message Person {
string name = 1;
int32 id = 2; // Unique ID number for this person.
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phones = 4;
}
// Our address book file is just one of these.
message AddressBook {
repeated Person people = 1;
}
It looks like you reversed the order of the parameters. /Users/flexmaster411/protobuffer is your output directory, so it should appear with --python_out. Since you specified it second, protoc thinks you're telling it that /Users/flexmaster411/protobuffer is an input. So it's trying to open a directory and then parse it as a .proto file. Amusingly, read() on a directory returns no data, which protoc interprets as a perfectly valid .proto file that simply doesn't declare anything! But it then gives you a warning because this empty file doesn't have any syntax line.
I think what you meant to type is:
protoc -I=/Users/flexmaster411/protobuffer --python_out=/Users/flexmaster411/protobuffer /Users/flexmaster411/protobuffer/addressbook.proto

PHPExcel: formula error (IF)

I'm trying to insert this formula
=IF(Datenbasis!B3<0;((Datenbasis!K3-Datenbasis!B3)/ABS(Datenbasis!B3))^(1/9)-1;(Datenbasis!$K$3/Datenbasis!$B$3)^(1/9)-1)
into this samplefile1 with this code:
// ....
try
{
$inputFileType = PHPExcel_IOFactory::identify("phpexceltest.xls");
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load("phpexceltest.xls");
}
catch(Exception $e)
{
$_loadingerror = TRUE;
}
if ($_loadingerror === TRUE)
{
// Fehler beim Laden der Vorlagen-Datei!
die("Fehler!");
}
$objPHPExcel->setActiveSheetIndex("0");
// ....
$objPHPExcel->getActiveSheet()->setCellValue("J4", "=IF(Datenbasis!B3<0;((Datenbasis!K3-Datenbasis!B3)/ABS(Datenbasis!B3))^(1/9)-1;(Datenbasis!$" . "K$3/Datenbasis!$" . "B$3)^(1/9)-1)");
// ....
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save("ready.xls");
I get this error
Fatal error: Uncaught exception 'Exception' with message 'Results!J4 -> undefined variable ';'' in ...\PHPExcel\Cell.php:288 Stack trace: #0 ...\PHPExcel\Writer\Excel5\Worksheet.php(441): PHPExcel_Cell->getCalculatedValue() #1 ...\PHPExcel\Writer\Excel5.php(171): PHPExcel_Writer_Excel5_Worksheet->close() #2 phpexceltest.php(446): PHPExcel_Writer_Excel5->save('ready.xls') #3 {main} thrown in ...\PHPExcel\Cell.php on line 288
and I have no idea why. When I use this formula in Excel directly, it's working.
Any ideas, what to do?
Rules for writing formulae in PHPExcel (as described in the documentation)
Decimal separator is '.' (period)
Function argument separator is ',' (comma)
Matrix row separator is ';' (semicolon)
English function names must be used
unless you've explicitly set a locale for the calculation engine
You're using a semi-colon (';') as a function argument separator

Parse error while running sonar on file that contains Boost_Foreach instruction

I getting an parse error when I run sonar analysis for file that contains Boost_Foreach instruction
File that contains Boost_Foreach instruction:
BOOST_FOREACH(SExcludedType entry, excludedFiles)
{
CString keyName;
keyName.Format(format, counter);
CString textRepresentation = SExcludedType::GetStringRepresentation(entry);
persistentSettings_.SaveNow(const_cast<PTSTR>(keyName.GetString()), textRepresentation);
++counter;
}
Parse error:
08:18:11.639 ERROR - Unable to parse file: C:\Users\aogonowski\Desktop\Defragler missing files\MainFrame.cpp
com.sonar.sslr.api.RecognitionException: Parse error at line 3793 column 1 failed to match all of: RECOVERED_EXPRESSION_STATEMENT STATEMENT
3787: ::GetStringRepresentation(entry);
3788: persistentSettings_.SaveNow(const_cast(keyName.GetString()), textRepresentation);
3789:
3790: ++counter;
3791: }
3792:
--> }
Failed at rules:
/-RECOVERED_EXPRESSION_STATEMENT consumed from (3782, 2) to (3791, 3): ... ) ) , textRepresentation ) ; ++ counter ; }
STATEMENT
I was looking for any solution how to set sonnar to analyse that file but I haven't found any solution expect to comment out that problematic code lines.
Try setting the property sonar.cxx.defines to BOOST_FOREACH(x,y) in your Sonar runner config file or pom.xml (whatever you are using).

Boost Filesystem Compile Error

I'm writing some code that utilizes the boost filesystem library. Here is an excerpt of my code:
artist = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? (*(paths_iterator->parent_path().end() - 1)) : (*(paths_iterator->parent_path().end() - 2));
album = (this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) ? "" : (*(paths_iterator->parent_path().end() - 1));
Types:
artist and album are of type std::string
this->find_diff returns an int
this->m_input_path is a std::string
paths_iterator is of type std::vector(open bracket)boost::filesystem::path>::iterator
I get a compile error:
error C2039: 'advance' : is not a member of 'boost::filesystem::basic_path<String,Traits>::iterator' d:\development\libraries\boost\boost\iterator\iterator_facade.hpp on line 546
This code is part of a program that outputs a batch script that uses lame.exe to convert files into mp3s.
The music library this is designed for has the format:
root/artist/song
OR
root/artist/album/song
this->m_input_path is the path to root.
I'm not sure if I'm approaching the problem properly. If I am, how do I fix the error that I am getting?
EDIT:
My code is now:
boost::filesystem::path::iterator end_path_itr = paths_iterator->parent_path().end();
if(this->find_diff(paths_iterator->parent_path(), this->m_input_path) == 1) /* For cases where: /root/artist/song */
{
album = "";
end_path_itr--;
artist = *end_path_itr;
}
else /* For cases where: /root/artist/album/song */
{
end_path_itr--;
album = *end_path_itr;
end_path_itr--; <-- Crash Here
artist = *end_path_itr;
}
The error that I now get is:
Assertion failed: itr.m_pos && "basic_path::iterator decrement pat begin()", file ... boost\filesystem\path.hpp, line 1444
basic_path::iterator is a bidirectional iterator. So arithmetic with -1 and -2 is not allowed. Operators + and - between an iterator and an integer value is defined for a RandomAccessIterator.
Instead of using .end()-1, you could resort to using --.
Your new error indicates that your end_path_iter doesn't have enough elements (should that be "decrement past begin"?), i.e. your path is shorter than you expect.