Optimizations, regex character ranges
This commit is contained in:
@@ -51,13 +51,13 @@ param_assign_list = param_assign WS "," WS param_assign_list | param_assign ;
|
|||||||
param_assign = identifier WS "=" WS identifier | identifier ;
|
param_assign = identifier WS "=" WS identifier | identifier ;
|
||||||
opt_string = string | ;
|
opt_string = string | ;
|
||||||
|
|
||||||
triple_quoted_string = "\"\"\"((\"\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|
triple_quoted_string = "\"\"\"((\"\"(`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
||||||
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+)|(\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+)|(\"(`|[0-9]|-|=| |[a-z]|\[|]|\\|'|
|
||||||
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+))*(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+))*(`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
||||||
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )*(((`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )*(((`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
||||||
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+\")|((`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+\")|((`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
||||||
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+\"\")|((`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+\"\")|((`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
||||||
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+))*\"\"\"" ;
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+))*\"\"\"" ;
|
||||||
|
|
||||||
#identifier = alpha_alphanumeric ;
|
#identifier = alpha_alphanumeric ;
|
||||||
identifier = augmented_alpha_alphanumeric ;
|
identifier = augmented_alpha_alphanumeric ;
|
||||||
@@ -66,7 +66,7 @@ scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ;
|
|||||||
|
|
||||||
#Note that to prevent confilct with nested templates (T<A<B>>) right_shift is a nonterminal contructed as follows
|
#Note that to prevent confilct with nested templates (T<A<B>>) right_shift is a nonterminal contructed as follows
|
||||||
right_shift = ">" ">" ;
|
right_shift = ">" ">" ;
|
||||||
overloadable_operator = "\+" | "-" | "\*" | "/" | "%" | "^" | "&" | "\|" | "~" | "!" | "," | "=" | "\+\+" | "--" | "<<" | right_shift | "==" | "!=" | "&&" | "\|\|" | "\+=" | "-=" | "/=" | "%=" | "^=" | "&=" | "\|=" | "\*=" | "<<=" | ">>=" | "->" | "\(" "\)" | "[]" | "[]=" ;
|
overloadable_operator = "\+" | "-" | "\*" | "/" | "%" | "^" | "&" | "\|" | "~" | "!" | "," | "=" | "\+\+" | "--" | "<<" | right_shift | "==" | "!=" | "&&" | "\|\|" | "\+=" | "-=" | "/=" | "%=" | "^=" | "&=" | "\|=" | "\*=" | "<<=" | ">>=" | "->" | "\(" "\)" | "\[]" | "\[]=" ;
|
||||||
func_identifier = identifier | identifier overloadable_operator ;
|
func_identifier = identifier | identifier overloadable_operator ;
|
||||||
# allow omitting of return type (automatic void)
|
# allow omitting of return type (automatic void)
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ expression = expression WS "<<" WS term | expression WS right_shift WS shiftand
|
|||||||
shiftand = shiftand WS "-" WS term | shiftand WS "\+" WS term | term ;
|
shiftand = shiftand WS "-" WS term | shiftand WS "\+" WS term | term ;
|
||||||
term = term WS "/" WS factor | term WS "\*" WS factor | term WS "%" WS factor | factor ;
|
term = term WS "/" WS factor | term WS "\*" WS factor | term WS "%" WS factor | factor ;
|
||||||
factor = "\+\+" WS unarad | unarad WS "\+\+" | "--" WS unarad | unarad WS "--" | "\+" WS unarad | "-" WS unarad | "!" WS unarad | "~" WS unarad | "\*" WS unarad | "&" WS unarad | unarad ;
|
factor = "\+\+" WS unarad | unarad WS "\+\+" | "--" WS unarad | unarad WS "--" | "\+" WS unarad | "-" WS unarad | "!" WS unarad | "~" WS unarad | "\*" WS unarad | "&" WS unarad | unarad ;
|
||||||
unarad = number | scoped_identifier | scoped_identifier WS template_inst | access_operation | function_call | compiler_intrinsic | bool | string | character | "\(" WS boolean_expression WS "\)" | unarad WS "[" WS expression WS "]" | lambda | cast_expression ;
|
unarad = number | scoped_identifier | scoped_identifier WS template_inst | access_operation | function_call | compiler_intrinsic | bool | string | character | "\(" WS boolean_expression WS "\)" | unarad WS "\[" WS expression WS "]" | lambda | cast_expression ;
|
||||||
cast_expression = "\(" WS boolean_expression WS "\)" WS "cast" WS type ;
|
cast_expression = "\(" WS boolean_expression WS "\)" WS "cast" WS type ;
|
||||||
number = integer | floating_literal ;
|
number = integer | floating_literal ;
|
||||||
access_operation = unarad WS "." WS identifier | unarad WS "->" WS identifier | unarad WS "." WS identifier WS template_inst | unarad WS "->" WS identifier WS template_inst ;
|
access_operation = unarad WS "." WS identifier | unarad WS "->" WS identifier | unarad WS "." WS identifier WS template_inst | unarad WS "->" WS identifier WS template_inst ;
|
||||||
@@ -141,23 +141,23 @@ access_operation = unarad WS "." WS identifier | unarad WS "->" WS identifier |
|
|||||||
assignment_statement = factor WS "=" WS boolean_expression | factor WS "\+=" WS boolean_expression | factor WS "-=" WS boolean_expression | factor WS "\*=" WS boolean_expression | factor WS "/=" WS boolean_expression ;
|
assignment_statement = factor WS "=" WS boolean_expression | factor WS "\+=" WS boolean_expression | factor WS "-=" WS boolean_expression | factor WS "\*=" WS boolean_expression | factor WS "/=" WS boolean_expression ;
|
||||||
# if it's being assigned to, we allow type inferencing
|
# if it's being assigned to, we allow type inferencing
|
||||||
declaration_statement = "var" WS identifier WS "=" WS boolean_expression | "var" WS identifier WS dec_type WS "=" WS boolean_expression | "var" WS identifier WS dec_type | "var" WS identifier WS "." WS identifier WS "\(" WS opt_parameter_list WS "\)" WS dec_type ;
|
declaration_statement = "var" WS identifier WS "=" WS boolean_expression | "var" WS identifier WS dec_type WS "=" WS boolean_expression | "var" WS identifier WS dec_type | "var" WS identifier WS "." WS identifier WS "\(" WS opt_parameter_list WS "\)" WS dec_type ;
|
||||||
hexadecimal = "0x(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)+" ;
|
hexadecimal = "0x([0-9]|[a-f])+" ;
|
||||||
integer = numeric | hexadecimal ;
|
integer = numeric | hexadecimal ;
|
||||||
floating_literal = numeric "." float_end ;
|
floating_literal = numeric "." float_end ;
|
||||||
float_end = "(0|1|2|3|4|5|6|7|8|9)+" | "(0|1|2|3|4|5|6|7|8|9)+f" | "(0|1|2|3|4|5|6|7|8|9)+d" ;
|
float_end = "[0-9]+" | "[0-9]+f" | "[0-9]+d" ;
|
||||||
bool = "true" | "false" ;
|
bool = "true" | "false" ;
|
||||||
character = "'(`|1|2|3|4|5|6|7|8|9|0|-|=|(\\t)|q|w|e|r|t|y|u|i|o|p|[|]|(\\\\)|a|s|d|f|g|h|j|k|l|;|(\\')|(\\n)|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|\"|Z|X|C|V|B|N|M|<|>|\?| |(\\0))'" ;
|
character = "'(`|[0-9]|-|=|(\\t)|[a-z]|\[|]|(\\\\)|;|(\\')|(\\n)|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|\"|<|>|\?| |(\\0))'" ;
|
||||||
|
|
||||||
keywords_also_identifiers = "obj" | "def" | "fun" | "var" | "ref" | "adt" | "cast" | "import" | "simple_passthrough" ;
|
keywords_also_identifiers = "obj" | "def" | "fun" | "var" | "ref" | "adt" | "cast" | "import" | "simple_passthrough" ;
|
||||||
alpha_alphanumeric = "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_)(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_|0|1|2|3|4|5|6|7|8|9)*" ;
|
alpha_alphanumeric = "([a-z]|[A-Z]|_)([a-z]|[A-Z]|_|[0-9])*" ;
|
||||||
augmented_alpha_alphanumeric = alpha_alphanumeric augmented_alpha_alphanumeric | keywords_also_identifiers augmented_alpha_alphanumeric | alpha_alphanumeric | keywords_also_identifiers ;
|
augmented_alpha_alphanumeric = alpha_alphanumeric augmented_alpha_alphanumeric | keywords_also_identifiers augmented_alpha_alphanumeric | alpha_alphanumeric | keywords_also_identifiers ;
|
||||||
|
|
||||||
numeric = "(0|1|2|3|4|5|6|7|8|9)+" ;
|
numeric = "[0-9]+" ;
|
||||||
# note the hacks around \things. Hmm, I feel like it actually shouldn't be like this. Added \\\* because I want to come back later
|
# note the hacks around \things. Hmm, I feel like it actually shouldn't be like this. Added \\\* because I want to come back later
|
||||||
string = triple_quoted_string | "\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|(\\\\)|(\\n)|(\\t)|(\\\*)|(\\0)|a|s|d|f|g|h|j|k|l|;|'|
|
string = triple_quoted_string | "\"(`|[0-9]|-|=| |[a-z]|\[|]|(\\\\)|(\\n)|(\\t)|(\\\*)|(\\0)|;|'|
|
||||||
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| |(\\\"))*\"" ;
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| |(\\\"))*\"" ;
|
||||||
comment = cpp_comment | c_comment ;
|
comment = cpp_comment | c_comment ;
|
||||||
cpp_comment = "//(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|\"|Z|X|C|V|B|N|M|<|>|\?| )*
|
cpp_comment = "//(`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|\"|<|>|\?| )*
|
||||||
" ;
|
" ;
|
||||||
c_comment = "(/\*/*\**((`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|
c_comment = "(/\*/*\**((`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
||||||
|z|x|c|v|b|n|m|,|.|~|!|@|#|$|%|^|&|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|\"|Z|X|C|V|B|N|M|<|>|\?| )/*\**)+\*/)|(/\*\*/)" ;
|
|,|.|~|!|@|#|$|%|^|&|\(|\)|_|\+|[A-Z]|{|}|\||:|\"|<|>|\?| )/*\**)+\*/)|(/\*\*/)" ;
|
||||||
|
|||||||
@@ -638,8 +638,7 @@ obj ast_transformation (Object) {
|
|||||||
if (factor_part->children.size == 1) {
|
if (factor_part->children.size == 1) {
|
||||||
/*println("Factor has only one child!")*/
|
/*println("Factor has only one child!")*/
|
||||||
var inner_unarad = get_node("unarad", factor_part)
|
var inner_unarad = get_node("unarad", factor_part)
|
||||||
if (get_node("\"[\"", inner_unarad)) {
|
if (get_node("\"]\"", inner_unarad)) {
|
||||||
/*println("Inner Unarad has [!")*/
|
|
||||||
var assign_to = transform(get_node("unarad", inner_unarad), scope, template_replacements)
|
var assign_to = transform(get_node("unarad", inner_unarad), scope, template_replacements)
|
||||||
var assign_idx = transform(get_node("expression", inner_unarad), scope, template_replacements)
|
var assign_idx = transform(get_node("expression", inner_unarad), scope, template_replacements)
|
||||||
var possible_bracket_assign = find_and_make_any_operator_overload_call(string("[]="), vector(assign_to, assign_idx, to_assign), scope, template_replacements)
|
var possible_bracket_assign = find_and_make_any_operator_overload_call(string("[]="), vector(assign_to, assign_idx, to_assign), scope, template_replacements)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ obj parser (Object) {
|
|||||||
var to_shift: stack< pair<*tree<int>, int> >
|
var to_shift: stack< pair<*tree<int>, int> >
|
||||||
var SPPFStepNodes: vector< pair<*tree<symbol>, int> >
|
var SPPFStepNodes: vector< pair<*tree<symbol>, int> >
|
||||||
var packed_map: map<*tree<symbol>, bool>
|
var packed_map: map<*tree<symbol>, bool>
|
||||||
|
var reduces_to_null_map: map<vector<symbol>, bool>
|
||||||
|
|
||||||
fun construct(grammerIn: grammer): *parser {
|
fun construct(grammerIn: grammer): *parser {
|
||||||
input.construct()
|
input.construct()
|
||||||
@@ -28,6 +29,7 @@ obj parser (Object) {
|
|||||||
to_shift.construct()
|
to_shift.construct()
|
||||||
SPPFStepNodes.construct()
|
SPPFStepNodes.construct()
|
||||||
packed_map.construct()
|
packed_map.construct()
|
||||||
|
reduces_to_null_map.construct()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
fun copy_construct(old: *parser) {
|
fun copy_construct(old: *parser) {
|
||||||
@@ -38,6 +40,7 @@ obj parser (Object) {
|
|||||||
to_shift.copy_construct(&old->to_shift)
|
to_shift.copy_construct(&old->to_shift)
|
||||||
SPPFStepNodes.copy_construct(&old->SPPFStepNodes)
|
SPPFStepNodes.copy_construct(&old->SPPFStepNodes)
|
||||||
packed_map.copy_construct(&old->packed_map)
|
packed_map.copy_construct(&old->packed_map)
|
||||||
|
reduces_to_null_map.copy_construct(&old->reduces_to_null_map)
|
||||||
}
|
}
|
||||||
fun operator=(old: ref parser) {
|
fun operator=(old: ref parser) {
|
||||||
destruct()
|
destruct()
|
||||||
@@ -51,6 +54,7 @@ obj parser (Object) {
|
|||||||
to_shift.destruct()
|
to_shift.destruct()
|
||||||
SPPFStepNodes.destruct()
|
SPPFStepNodes.destruct()
|
||||||
packed_map.destruct()
|
packed_map.destruct()
|
||||||
|
reduces_to_null_map.destruct()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parse_input(inputStr: string, name: string): *tree<symbol> {
|
fun parse_input(inputStr: string, name: string): *tree<symbol> {
|
||||||
@@ -386,7 +390,9 @@ obj parser (Object) {
|
|||||||
return r.position == 0 && reduces_to_null(r)
|
return r.position == 0 && reduces_to_null(r)
|
||||||
}
|
}
|
||||||
fun reduces_to_null(r: ref rule): bool {
|
fun reduces_to_null(r: ref rule): bool {
|
||||||
return gram.first_vector(r.rhs).contains(null_symbol())
|
if (!reduces_to_null_map.contains_key(r.rhs))
|
||||||
|
reduces_to_null_map[r.rhs] = gram.first_vector(r.rhs).contains(null_symbol())
|
||||||
|
return reduces_to_null_map[r.rhs]
|
||||||
}
|
}
|
||||||
fun get_nullable_parts(r: ref rule): *tree<symbol> {
|
fun get_nullable_parts(r: ref rule): *tree<symbol> {
|
||||||
if (reduces_to_null(r))
|
if (reduces_to_null(r))
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import io
|
import io
|
||||||
|
import string
|
||||||
|
import ast_transformation
|
||||||
import vector
|
import vector
|
||||||
import string
|
import string
|
||||||
import mem
|
import mem
|
||||||
@@ -15,10 +17,16 @@ fun regex(in: string::string):regex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
obj regexState (Object) {
|
obj regexState (Object) {
|
||||||
var character: char
|
// if only one character, both are the same
|
||||||
|
var characterBegin: char
|
||||||
|
var characterEnd: char
|
||||||
var next_states: set::set<*regexState>
|
var next_states: set::set<*regexState>
|
||||||
fun construct(charIn:char): *regexState {
|
fun construct(charIn:char): *regexState {
|
||||||
character = charIn
|
return construct(charIn, charIn)
|
||||||
|
}
|
||||||
|
fun construct(charFirst:char, charSecond:char): *regexState {
|
||||||
|
characterBegin = charFirst
|
||||||
|
characterEnd = charSecond
|
||||||
next_states.construct()
|
next_states.construct()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
@@ -26,17 +34,18 @@ obj regexState (Object) {
|
|||||||
return construct((0) cast char)
|
return construct((0) cast char)
|
||||||
}
|
}
|
||||||
fun copy_construct(old:*regexState): void {
|
fun copy_construct(old:*regexState): void {
|
||||||
character = old->character
|
characterBegin = old->characterBegin
|
||||||
|
characterEnd = old->characterEnd
|
||||||
next_states.copy_construct(&old->next_states)
|
next_states.copy_construct(&old->next_states)
|
||||||
}
|
}
|
||||||
fun destruct():void {
|
fun destruct():void {
|
||||||
next_states.destruct()
|
next_states.destruct()
|
||||||
}
|
}
|
||||||
fun match_char(input: char): set::set<*regexState> {
|
fun match_char(input: char): set::set<*regexState> {
|
||||||
return next_states.filter(fun(it:*regexState):bool { return it->character == input; })
|
return next_states.filter(fun(it:*regexState):bool { return it->characterBegin <= input && input <= it->characterEnd; })
|
||||||
}
|
}
|
||||||
fun is_end():bool {
|
fun is_end():bool {
|
||||||
return next_states.any_true(fun(state: *regexState):bool { return state->character == 1; })
|
return next_states.any_true(fun(state: *regexState):bool { return state->characterBegin == 1; })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,14 +76,6 @@ obj regex (Object, Serializable) {
|
|||||||
begin = old->begin
|
begin = old->begin
|
||||||
referenceCounter = old->referenceCounter
|
referenceCounter = old->referenceCounter
|
||||||
*referenceCounter += 1
|
*referenceCounter += 1
|
||||||
/*construct(old->regexString)*/
|
|
||||||
/*begin = mem::safe_recursive_clone(old->begin, fun(it: *regexState, cloner: fun(*regexState):*regexState, register: fun(*regexState):void): void {*/
|
|
||||||
/*var newOne = mem::new<regexState>()->construct(it->character)*/
|
|
||||||
/*register(newOne)*/
|
|
||||||
/*it->next_states.for_each(fun(next_state: *regexState) {*/
|
|
||||||
/*newOne->next_states.add(cloner(next_state))*/
|
|
||||||
/*})*/
|
|
||||||
/*})*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destruct():void {
|
fun destruct():void {
|
||||||
@@ -105,6 +106,7 @@ obj regex (Object, Serializable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun compile(regex_string: string::string): util::pair<*regexState, set::set<*regexState>> {
|
fun compile(regex_string: string::string): util::pair<*regexState, set::set<*regexState>> {
|
||||||
|
/*io::println(regex_string)*/
|
||||||
var first = mem::new<regexState>()->construct()
|
var first = mem::new<regexState>()->construct()
|
||||||
var previous_begin = set::set<*regexState>()
|
var previous_begin = set::set<*regexState>()
|
||||||
var previous_end = set::set<*regexState>()
|
var previous_end = set::set<*regexState>()
|
||||||
@@ -132,11 +134,14 @@ obj regex (Object, Serializable) {
|
|||||||
} else if (regex_string[i] == '(' && !escapeing) {
|
} else if (regex_string[i] == '(' && !escapeing) {
|
||||||
// note that we don't have a ')' case, as we skip past it with our indicies
|
// note that we don't have a ')' case, as we skip past it with our indicies
|
||||||
var perenEnd = i + 1
|
var perenEnd = i + 1
|
||||||
for (var depth = 1; depth > 0; perenEnd++;)
|
for (var depth = 1; depth > 0; perenEnd++;) {
|
||||||
|
if (perenEnd >= regex_string.length())
|
||||||
|
ast_transformation::error(string::string("can't find matching peren in: ") + regex_string)
|
||||||
if (regex_string[perenEnd] == '(')
|
if (regex_string[perenEnd] == '(')
|
||||||
depth++
|
depth++
|
||||||
else if (regex_string[perenEnd] == ')')
|
else if (regex_string[perenEnd] == ')')
|
||||||
depth--
|
depth--
|
||||||
|
}
|
||||||
var innerBeginEnd = compile(regex_string.slice(i+1, perenEnd-1))
|
var innerBeginEnd = compile(regex_string.slice(i+1, perenEnd-1))
|
||||||
// NOTE: perenEnd is one past the close peren
|
// NOTE: perenEnd is one past the close peren
|
||||||
i = perenEnd-1
|
i = perenEnd-1
|
||||||
@@ -158,7 +163,13 @@ obj regex (Object, Serializable) {
|
|||||||
escapeing = true
|
escapeing = true
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var next = mem::new<regexState>()->construct(regex_string[i])
|
var next: *regexState
|
||||||
|
if (regex_string[i] == '[' && !escapeing) {
|
||||||
|
next = mem::new<regexState>()->construct(regex_string[i+1], regex_string[i+3])
|
||||||
|
i += 4 // [a-b] is 5, i++ adds one
|
||||||
|
} else {
|
||||||
|
next = mem::new<regexState>()->construct(regex_string[i])
|
||||||
|
}
|
||||||
if (alternating) {
|
if (alternating) {
|
||||||
previous_end.for_each(fun(it: *regexState):void { it->next_states.add(next); })
|
previous_end.for_each(fun(it: *regexState):void { it->next_states.add(next); })
|
||||||
current_begin.add(next)
|
current_begin.add(next)
|
||||||
|
|||||||
@@ -34,8 +34,9 @@ obj set<T> (Object, Serializable) {
|
|||||||
data.copy_construct(&old->data)
|
data.copy_construct(&old->data)
|
||||||
}
|
}
|
||||||
fun operator=(rhs: ref set<T>) {
|
fun operator=(rhs: ref set<T>) {
|
||||||
destruct()
|
/*destruct()*/
|
||||||
copy_construct(&rhs)
|
/*copy_construct(&rhs)*/
|
||||||
|
data = rhs.data
|
||||||
}
|
}
|
||||||
fun serialize(): vector::vector<char> {
|
fun serialize(): vector::vector<char> {
|
||||||
return serialize::serialize(data)
|
return serialize::serialize(data)
|
||||||
@@ -43,12 +44,12 @@ obj set<T> (Object, Serializable) {
|
|||||||
fun unserialize(it: ref vector::vector<char>, pos: int): int {
|
fun unserialize(it: ref vector::vector<char>, pos: int): int {
|
||||||
return data.unserialize(it, pos)
|
return data.unserialize(it, pos)
|
||||||
}
|
}
|
||||||
fun operator==(rhs: set<T>): bool {
|
fun operator==(rhs: ref set<T>): bool {
|
||||||
if (size() != rhs.size())
|
if (size() != rhs.size())
|
||||||
return false
|
return false
|
||||||
return !data.any_true( fun(item: T): bool return !rhs.contains(item); )
|
return !data.any_true( fun(item: T): bool return !rhs.contains(item); )
|
||||||
}
|
}
|
||||||
fun operator!=(rhs: set<T>): bool {
|
fun operator!=(rhs: ref set<T>): bool {
|
||||||
return ! (*this == rhs)
|
return ! (*this == rhs)
|
||||||
}
|
}
|
||||||
fun destruct() {
|
fun destruct() {
|
||||||
@@ -57,10 +58,10 @@ obj set<T> (Object, Serializable) {
|
|||||||
fun size():int {
|
fun size():int {
|
||||||
return data.size
|
return data.size
|
||||||
}
|
}
|
||||||
fun contains(items: set<T>): bool {
|
fun contains(items: ref set<T>): bool {
|
||||||
return items.size() == 0 || !items.any_true( fun(item: T): bool return !contains(item); )
|
return items.size() == 0 || !items.any_true( fun(item: T): bool return !contains(item); )
|
||||||
}
|
}
|
||||||
fun contains(item: T): bool {
|
fun contains(item: ref T): bool {
|
||||||
return data.find(item) != -1
|
return data.find(item) != -1
|
||||||
}
|
}
|
||||||
fun operator+=(item: ref T) {
|
fun operator+=(item: ref T) {
|
||||||
@@ -84,7 +85,7 @@ obj set<T> (Object, Serializable) {
|
|||||||
fun add(items: ref set<T>) {
|
fun add(items: ref set<T>) {
|
||||||
items.for_each( fun(item: ref T) add(item); )
|
items.for_each( fun(item: ref T) add(item); )
|
||||||
}
|
}
|
||||||
fun remove(item: T) {
|
fun remove(item: ref T) {
|
||||||
var idx = data.find(item)
|
var idx = data.find(item)
|
||||||
if (idx == -1) {
|
if (idx == -1) {
|
||||||
/*io::println("CANNOT FIND ITEM TO REMOVE")*/
|
/*io::println("CANNOT FIND ITEM TO REMOVE")*/
|
||||||
|
|||||||
@@ -94,8 +94,9 @@ obj string (Object, Serializable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun operator=(str: ref string): void {
|
fun operator=(str: ref string): void {
|
||||||
destruct();
|
/*destruct();*/
|
||||||
data.copy_construct(&str.data)
|
/*data.copy_construct(&str.data)*/
|
||||||
|
data = str.data
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destruct():void {
|
fun destruct():void {
|
||||||
@@ -147,8 +148,9 @@ obj string (Object, Serializable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun operator+(str: ref string): string {
|
fun operator+(str: ref string): string {
|
||||||
var newStr.construct(str):string
|
/*var newStr.construct(str):string*/
|
||||||
var ret.construct(data + newStr.data):string
|
/*var ret.construct(data + newStr.data):string*/
|
||||||
|
var ret.construct(data + str.data):string
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +212,7 @@ obj string (Object, Serializable) {
|
|||||||
out.add(current)
|
out.add(current)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
fun join(to_join: vector::vector<string>): string {
|
fun join(to_join: ref vector::vector<string>): string {
|
||||||
var to_ret = to_join.first()
|
var to_ret = to_join.first()
|
||||||
for (var i = 1; i < to_join.size; i++;)
|
for (var i = 1; i < to_join.size; i++;)
|
||||||
to_ret += *this + to_join[i]
|
to_ret += *this + to_join[i]
|
||||||
|
|||||||
@@ -65,31 +65,36 @@ obj vector<T> (Object, Serializable) {
|
|||||||
data = 0
|
data = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun operator=(other:vector<T>):void {
|
fun operator=(other:ref vector<T>):void {
|
||||||
|
if (size < other.size) {
|
||||||
destruct()
|
destruct()
|
||||||
copy_construct(&other)
|
copy_construct(&other)
|
||||||
|
} else {
|
||||||
|
clear()
|
||||||
|
for (var i = 0; i < other.size; i++;)
|
||||||
|
addEnd(other.get(i))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun operator+(other:vector<T>):vector<T> {
|
fun operator+(other: ref vector<T>):vector<T> {
|
||||||
// lets be at least a little bit smarter by copy_constructing our copy.
|
var newVec.construct(size+other.size):vector<T>
|
||||||
// We could get a lot better than this by initially creating enough space
|
for (var i = 0; i < size; i++;)
|
||||||
// for both and copy_constructing all of them, but this is just a quick fix
|
newVec.addEnd(get(i))
|
||||||
var newVec.copy_construct(this):vector<T>
|
|
||||||
for (var i = 0; i < other.size; i++;)
|
for (var i = 0; i < other.size; i++;)
|
||||||
newVec.addEnd(other.get(i))
|
newVec.addEnd(other.get(i))
|
||||||
return newVec
|
return newVec
|
||||||
}
|
}
|
||||||
fun operator+(other: T):vector<T> {
|
fun operator+(other: ref T):vector<T> {
|
||||||
var newVec.copy_construct(this):vector<T>
|
var newVec.copy_construct(this):vector<T>
|
||||||
newVec.addEnd(other)
|
newVec.addEnd(other)
|
||||||
return newVec
|
return newVec
|
||||||
}
|
}
|
||||||
|
|
||||||
fun operator+=(other: T):void {
|
fun operator+=(other: ref T):void {
|
||||||
addEnd(other)
|
addEnd(other)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun operator+=(other:vector<T>):void {
|
fun operator+=(other: ref vector<T>):void {
|
||||||
for (var i = 0; i < other.size; i++;)
|
for (var i = 0; i < other.size; i++;)
|
||||||
addEnd(other.get(i))
|
addEnd(other.get(i))
|
||||||
}
|
}
|
||||||
@@ -180,7 +185,7 @@ obj vector<T> (Object, Serializable) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun set(index: int, dataIn: T): void {
|
fun set(index: int, dataIn: ref T): void {
|
||||||
if (index < 0 || index >= size)
|
if (index < 0 || index >= size)
|
||||||
return;
|
return;
|
||||||
data[index] = dataIn;
|
data[index] = dataIn;
|
||||||
@@ -190,7 +195,7 @@ obj vector<T> (Object, Serializable) {
|
|||||||
addEnd(dataIn[i]);
|
addEnd(dataIn[i]);
|
||||||
}
|
}
|
||||||
// same darn trick
|
// same darn trick
|
||||||
fun add_unique<U>(dataIn: U): void {
|
fun add_unique<U>(dataIn: ref U): void {
|
||||||
if (!contains(dataIn))
|
if (!contains(dataIn))
|
||||||
addEnd(dataIn)
|
addEnd(dataIn)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user