mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-07 10:19:57 +08:00
Merge branch 'develop' into best_practices
This commit is contained in:
commit
cd05b1f750
98
.clang-format
Normal file
98
.clang-format
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: false
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BraceWrapping:
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
BreakAfterJavaFieldAnnotations: true
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BreakBeforeInheritanceComma: true
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 0
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 2
|
||||||
|
ContinuationIndentWidth: 2
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
DerivePointerAlignment: true
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: true
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeCategories:
|
||||||
|
- Priority: 2
|
||||||
|
Regex: ^"(llvm|llvm-c|clang|clang-c)/
|
||||||
|
- Priority: 3
|
||||||
|
Regex: ^(<|"(gtest|gmock|isl|json)/)
|
||||||
|
- Priority: 1
|
||||||
|
Regex: .*
|
||||||
|
IncludeIsMainRegex: (Test)?$
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: true
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
Language: Cpp
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 2
|
||||||
|
NamespaceIndentation: Inner
|
||||||
|
ObjCBlockIndentWidth: 7
|
||||||
|
ObjCSpaceAfterProperty: true
|
||||||
|
ObjCSpaceBeforeProtocolList: false
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: false
|
||||||
|
SortUsingDeclarations: false
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 0
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Cpp11
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Never
|
||||||
|
|
||||||
1
contrib/vim
Normal file
1
contrib/vim
Normal file
@ -0,0 +1 @@
|
|||||||
|
vim support can be found at https://github.com/ChaiScript/vim-chaiscript
|
||||||
@ -1,7 +0,0 @@
|
|||||||
Install ftdetect, indent and syntax subdirectories to:
|
|
||||||
|
|
||||||
~/.vim/
|
|
||||||
|
|
||||||
See the vim documentation on this:
|
|
||||||
|
|
||||||
http://vimdoc.sourceforge.net/htmldoc/syntax.html#mysyntaxfile
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
au BufRead,BufNewFile *.chai set filetype=chaiscript
|
|
||||||
|
|
||||||
@ -1,50 +0,0 @@
|
|||||||
" Vim indent file
|
|
||||||
" Language: ChaiScript
|
|
||||||
" Maintainer: Jason Turner <lefticus 'at' gmail com>
|
|
||||||
|
|
||||||
" Only load this indent file when no other was loaded.
|
|
||||||
if exists("b:did_indent")
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
let b:did_indent = 1
|
|
||||||
|
|
||||||
setlocal indentexpr=GetChaiScriptIndent()
|
|
||||||
setlocal autoindent
|
|
||||||
|
|
||||||
" Only define the function once.
|
|
||||||
if exists("*GetChaiScriptIndent")
|
|
||||||
finish
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! GetChaiScriptIndent()
|
|
||||||
" Find a non-blank line above the current line.
|
|
||||||
let lnum = prevnonblank(v:lnum - 1)
|
|
||||||
|
|
||||||
" Hit the start of the file, use zero indent.
|
|
||||||
if lnum == 0
|
|
||||||
return 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Add a 'shiftwidth' after lines that start a block:
|
|
||||||
" lines containing a {
|
|
||||||
let ind = indent(lnum)
|
|
||||||
let flag = 0
|
|
||||||
let prevline = getline(lnum)
|
|
||||||
if prevline =~ '^.*{.*'
|
|
||||||
let ind = ind + &shiftwidth
|
|
||||||
let flag = 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Subtract a 'shiftwidth' after lines containing a { followed by a }
|
|
||||||
" to keep it balanced
|
|
||||||
if flag == 1 && prevline =~ '.*{.*}.*'
|
|
||||||
let ind = ind - &shiftwidth
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Subtract a 'shiftwidth' on lines ending with }
|
|
||||||
if getline(v:lnum) =~ '^\s*\%(}\)'
|
|
||||||
let ind = ind - &shiftwidth
|
|
||||||
endif
|
|
||||||
|
|
||||||
return ind
|
|
||||||
endfunction
|
|
||||||
@ -1,99 +0,0 @@
|
|||||||
" Vim syntax file
|
|
||||||
" Language: ChaiScript
|
|
||||||
" Maintainer: Jason Turner <lefticus 'at' gmail com>
|
|
||||||
|
|
||||||
" Quit when a (custom) syntax file was already loaded
|
|
||||||
if exists("b:current_syntax")
|
|
||||||
finish
|
|
||||||
end
|
|
||||||
|
|
||||||
let s:cpo_save = &cpo
|
|
||||||
set cpo&vim
|
|
||||||
|
|
||||||
syn case match
|
|
||||||
|
|
||||||
" syncing method
|
|
||||||
syn sync fromstart
|
|
||||||
|
|
||||||
" Strings
|
|
||||||
syn region chaiscriptString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=chaiscriptSpecial,chaiscriptEval,@Spell
|
|
||||||
|
|
||||||
" Escape characters
|
|
||||||
syn match chaiscriptSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}"
|
|
||||||
|
|
||||||
" String evals
|
|
||||||
syn region chaiscriptEval contained start="${" end="}"
|
|
||||||
|
|
||||||
" integer number
|
|
||||||
syn match chaiscriptNumber "\<\d\+\>"
|
|
||||||
|
|
||||||
" floating point number, with dot, optional exponent
|
|
||||||
syn match chaiscriptFloat "\<\d\+\.\d*\%(e[-+]\=\d\+\)\=\>"
|
|
||||||
|
|
||||||
" floating point number, starting with a dot, optional exponent
|
|
||||||
syn match chaiscriptFloat "\.\d\+\%(e[-+]\=\d\+\)\=\>"
|
|
||||||
|
|
||||||
" floating point number, without dot, with exponent
|
|
||||||
syn match chaiscriptFloat "\<\d\+e[-+]\=\d\+\>"
|
|
||||||
|
|
||||||
" Hex strings
|
|
||||||
syn match chaiscriptNumber "\<0x\x\+\>"
|
|
||||||
|
|
||||||
" Binary strings
|
|
||||||
syn match chaiscriptNumber "\<0b[01]\+\>"
|
|
||||||
|
|
||||||
" Various language features
|
|
||||||
syn keyword chaiscriptCond if else
|
|
||||||
syn keyword chaiscriptRepeat while for do
|
|
||||||
syn keyword chaiscriptStatement break continue return switch case default
|
|
||||||
syn keyword chaiscriptExceptions try catch throw
|
|
||||||
|
|
||||||
"Keyword
|
|
||||||
syn keyword chaiscriptKeyword def true false attr
|
|
||||||
|
|
||||||
"Built in types
|
|
||||||
syn keyword chaiscriptType fun var auto
|
|
||||||
|
|
||||||
"Built in funcs, keep it simple
|
|
||||||
syn keyword chaiscriptFunc eval throw
|
|
||||||
|
|
||||||
"Let's treat all backtick operator function lookups as built in too
|
|
||||||
syn region chaiscriptFunc matchgroup=chaiscriptFunc start="`" end="`"
|
|
||||||
|
|
||||||
" Account for the "[1..10]" syntax, treating it as an operator
|
|
||||||
" Intentionally leaving out all of the normal, well known operators
|
|
||||||
syn match chaiscriptOperator "\.\."
|
|
||||||
|
|
||||||
" Guard seperator as an operator
|
|
||||||
syn match chaiscriptOperator ":"
|
|
||||||
|
|
||||||
" Comments
|
|
||||||
syn match chaiscriptComment "//.*$" contains=@Spell
|
|
||||||
syn region chaiscriptComment matchgroup=chaiscriptComment start="/\*" end="\*/" contains=@Spell
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hi def link chaiscriptExceptions Exception
|
|
||||||
hi def link chaiscriptKeyword Keyword
|
|
||||||
hi def link chaiscriptStatement Statement
|
|
||||||
hi def link chaiscriptRepeat Repeat
|
|
||||||
hi def link chaiscriptString String
|
|
||||||
hi def link chaiscriptNumber Number
|
|
||||||
hi def link chaiscriptFloat Float
|
|
||||||
hi def link chaiscriptOperator Operator
|
|
||||||
hi def link chaiscriptConstant Constant
|
|
||||||
hi def link chaiscriptCond Conditional
|
|
||||||
hi def link chaiscriptFunction Function
|
|
||||||
hi def link chaiscriptComment Comment
|
|
||||||
hi def link chaiscriptTodo Todo
|
|
||||||
hi def link chaiscriptError Error
|
|
||||||
hi def link chaiscriptSpecial SpecialChar
|
|
||||||
hi def link chaiscriptFunc Identifier
|
|
||||||
hi def link chaiscriptType Type
|
|
||||||
hi def link chaiscriptEval Special
|
|
||||||
|
|
||||||
let b:current_syntax = "chaiscript"
|
|
||||||
|
|
||||||
let &cpo = s:cpo_save
|
|
||||||
unlet s:cpo_save
|
|
||||||
" vim: nowrap sw=2 sts=2 ts=8 noet
|
|
||||||
@ -168,48 +168,57 @@ namespace chaiscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
[[nodiscard]] auto parse_num(const std::string_view &t_str) noexcept
|
template<typename T>
|
||||||
-> typename std::enable_if<!std::is_integral<T>::value, T>::type
|
auto parse_num(const char *t_str) -> typename std::enable_if<!std::is_integral<T>::value, T>::type
|
||||||
{
|
{
|
||||||
T t = 0;
|
T t = 0;
|
||||||
T base = 0;
|
T base;
|
||||||
T decimal_place = 0;
|
T decimal_place = 0;
|
||||||
bool exponent = false;
|
int exponent = 0;
|
||||||
bool neg_exponent = false;
|
|
||||||
|
|
||||||
const auto final_value = [](const T val, const T baseval, const bool hasexp, const bool negexp) -> T {
|
for (char c;; ++t_str) {
|
||||||
if (!hasexp) {
|
c = *t_str;
|
||||||
return val;
|
switch (c)
|
||||||
} else {
|
{
|
||||||
return baseval * std::pow(T(10), val*T(negexp?-1:1));
|
case '.':
|
||||||
}
|
decimal_place = 10;
|
||||||
};
|
break;
|
||||||
|
case 'e':
|
||||||
for (const auto c : t_str) {
|
case 'E':
|
||||||
if (c == '.') {
|
exponent = 1;
|
||||||
decimal_place = 10;
|
decimal_place = 0;
|
||||||
} else if (c == 'e' || c == 'E') {
|
base = t;
|
||||||
exponent = true;
|
t = 0;
|
||||||
decimal_place = 0;
|
break;
|
||||||
base = t;
|
case '-':
|
||||||
t = 0;
|
exponent = -1;
|
||||||
} else if (c == '-' && exponent) {
|
break;
|
||||||
neg_exponent = true;
|
case '+':
|
||||||
} else if (c == '+' && exponent) {
|
break;
|
||||||
neg_exponent = false;
|
case '0':
|
||||||
} else if (c < '0' || c > '9') {
|
case '1':
|
||||||
return final_value(t, base, exponent, neg_exponent);
|
case '2':
|
||||||
} else if (decimal_place < T(10)) {
|
case '3':
|
||||||
t *= T(10);
|
case '4':
|
||||||
t += T(c - '0');
|
case '5':
|
||||||
} else {
|
case '6':
|
||||||
t += (T(c - '0') / (T(decimal_place)));
|
case '7':
|
||||||
decimal_place *= 10;
|
case '8':
|
||||||
}
|
case '9':
|
||||||
}
|
if (decimal_place < 10) {
|
||||||
|
t *= 10;
|
||||||
return final_value(t, base, exponent, neg_exponent);
|
t += c - '0';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
t += (c - '0') / decimal_place;
|
||||||
|
decimal_place *= 10;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return exponent ? base * std::pow(T(10), t * exponent) : t;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str_equal {
|
struct str_equal {
|
||||||
|
|||||||
@ -97,7 +97,7 @@ namespace chaiscript {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool contains_var_decl_in_scope(const eval::AST_Node_Impl<T> &node) noexcept
|
bool contains_var_decl_in_scope(const eval::AST_Node_Impl<T> &node) noexcept
|
||||||
{
|
{
|
||||||
if (node.identifier == AST_Node_Type::Var_Decl || node.identifier == AST_Node_Type::Assign_Decl) {
|
if (node.identifier == AST_Node_Type::Var_Decl || node.identifier == AST_Node_Type::Assign_Decl || node.identifier == AST_Node_Type::Reference) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +107,7 @@ namespace chaiscript {
|
|||||||
const auto &child = child_at(node, i);
|
const auto &child = child_at(node, i);
|
||||||
if (child.identifier != AST_Node_Type::Block
|
if (child.identifier != AST_Node_Type::Block
|
||||||
&& child.identifier != AST_Node_Type::For
|
&& child.identifier != AST_Node_Type::For
|
||||||
|
&& child.identifier != AST_Node_Type::Ranged_For
|
||||||
&& contains_var_decl_in_scope(child)) {
|
&& contains_var_decl_in_scope(child)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -392,21 +393,21 @@ namespace chaiscript {
|
|||||||
const auto &prefix_node = child_at(*for_node, 2);
|
const auto &prefix_node = child_at(*for_node, 2);
|
||||||
|
|
||||||
if (child_count(*for_node) == 4
|
if (child_count(*for_node) == 4
|
||||||
&& eq_node.identifier == AST_Node_Type::Equation
|
&& eq_node.identifier == AST_Node_Type::Assign_Decl
|
||||||
&& child_count(eq_node) == 2
|
&& child_count(eq_node) == 2
|
||||||
&& child_at(eq_node, 0).identifier == AST_Node_Type::Var_Decl
|
&& child_at(eq_node, 0).identifier == AST_Node_Type::Id
|
||||||
&& child_at(eq_node, 1).identifier == AST_Node_Type::Constant
|
&& child_at(eq_node, 1).identifier == AST_Node_Type::Constant
|
||||||
&& binary_node.identifier == AST_Node_Type::Binary
|
&& binary_node.identifier == AST_Node_Type::Binary
|
||||||
&& binary_node.text == "<"
|
&& binary_node.text == "<"
|
||||||
&& child_count(binary_node) == 2
|
&& child_count(binary_node) == 2
|
||||||
&& child_at(binary_node, 0).identifier == AST_Node_Type::Id
|
&& child_at(binary_node, 0).identifier == AST_Node_Type::Id
|
||||||
&& child_at(binary_node, 0).text == child_at(child_at(eq_node,0), 0).text
|
&& child_at(binary_node, 0).text == child_at(eq_node,0).text
|
||||||
&& child_at(binary_node, 1).identifier == AST_Node_Type::Constant
|
&& child_at(binary_node, 1).identifier == AST_Node_Type::Constant
|
||||||
&& prefix_node.identifier == AST_Node_Type::Prefix
|
&& prefix_node.identifier == AST_Node_Type::Prefix
|
||||||
&& prefix_node.text == "++"
|
&& prefix_node.text == "++"
|
||||||
&& child_count(prefix_node) == 1
|
&& child_count(prefix_node) == 1
|
||||||
&& child_at(prefix_node, 0).identifier == AST_Node_Type::Id
|
&& child_at(prefix_node, 0).identifier == AST_Node_Type::Id
|
||||||
&& child_at(prefix_node, 0).text == child_at(child_at(eq_node,0), 0).text)
|
&& child_at(prefix_node, 0).text == child_at(eq_node,0).text)
|
||||||
{
|
{
|
||||||
const Boxed_Value &begin = dynamic_cast<const eval::Constant_AST_Node<T> &>(child_at(eq_node, 1)).m_value;
|
const Boxed_Value &begin = dynamic_cast<const eval::Constant_AST_Node<T> &>(child_at(eq_node, 1)).m_value;
|
||||||
const Boxed_Value &end = dynamic_cast<const eval::Constant_AST_Node<T> &>(child_at(binary_node, 1)).m_value;
|
const Boxed_Value &end = dynamic_cast<const eval::Constant_AST_Node<T> &>(child_at(binary_node, 1)).m_value;
|
||||||
|
|||||||
@ -18,4 +18,9 @@ for (x : retro(range([1,2,3,4]))) {
|
|||||||
|
|
||||||
assert_true(result > .6 && result < .7);
|
assert_true(result > .6 && result < .7);
|
||||||
|
|
||||||
|
var m=["a": ["t": "val"], "b": ["t": "val"]];
|
||||||
|
|
||||||
|
for (i : m) {
|
||||||
|
var &ref=i.second["t"];
|
||||||
|
print(ref);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user