Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 4 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 21, 2012
@MaximTrushin Replaced closure separator.
Macros are changed to function calls in the test expectations.
c2d258f
@MaximTrushin Rule prefix_expression is improved. 11904d0
@MaximTrushin closure_stmt_macro is implemented.
closure_20 is passed.
29b026c
Commits on Mar 22, 2012
@MaximTrushin Rule invocation_with_block is improved.
closures_20 passed.
c428a02
View
1  src/Boo.OMeta.Parser/AST.boo
@@ -358,6 +358,7 @@ def newConditionalExpression(condition, trueValue, falseValue):
return ConditionalExpression(Condition: condition, TrueValue: trueValue, FalseValue: falseValue)
def newBlockExpression(start as OMetaInput, end as OMetaInput, parameters as List, body):
+ parameters = [[], null] if parameters is null
node = BlockExpression(Body: body)
for p in parameters[0]:
node.Parameters.Add(p)
View
62 src/Boo.TinyAst/TinyAstEvaluator.boo
@@ -222,21 +222,6 @@ ometa TinyAstEvaluator(compilerParameters as CompilerParameters):
accessor[key] = --attributes_line >> att, Pair(Left: (inline_attributes >> in_att, member_modifiers >> mod, key >> name), Right: (block) >> body) \
^ newMethod([att, in_att], mod, tokenValue(name), [[],null], null, null, body)
- prefix[rule] = Prefix(Operator: rule >> e, Operand: _ >> newInput), $(success(newInput, e))
- optional_prefix[rule] = (Prefix(Operator: rule >> e, Operand: _ >> newInput), $(success(newInput, e))) | ""
-
- optional[rule] = (rule >> e, $(success(e, input))) | ""
-
- prefix2[rule] = Prefix(Operand: rule >> e, Operator: _ >> newInput), $(success(newInput, e))
- optional_prefix2[rule] = (Prefix(Operand: rule >> e, Operator: _ >> newInput), $(success(newInput, e))) | ""
-
- prefixOrId = id \
- |(
- Prefix(Operator: id >> e, Operand: _ >> newInput), $(success(newInput, e))
- )
- prefixOrInfix = (Prefix(Operator: _ >> e, Operand: _ >> newInput), $(success(OMetaInput.For([e, newInput]), e))) \
- | (Infix() >> e, $(success(e, e)))
-
inline_attributes = inline_attributes_prescan | ("" ^ [])
inline_attributes_prescan = (Prefix(Operator: attributes_group >> l, Operand: (inline_attributes_prescan >> r, _ >> newInput)), $(success(newInput, prepend(l, r))) )\
@@ -309,10 +294,13 @@ ometa TinyAstEvaluator(compilerParameters as CompilerParameters):
closure_block = here >> i, multiline_pair_block >> body, \
closure_block_left >> parameters, next[i] ^ newBlockExpression(null, null, parameters, body)
-
+
invocation_with_block = here >> i, \
- prefix[invocation] >> e, multiline_pair_block >> body, closure_block_left >> parameters \
- , next[i] ^ newInvocationWithBlock(e, newBlockExpression(null, null, parameters, body))
+ (
+ (prefix[invocation] >> e, closure_block >> be)
+ | (multiline_pair_block >> b, invocation >> e)
+ ), next[i] ^ newInvocationWithBlock(e, (be if be is not null else newBlockExpression(null, null, [[], null], b)))
+
dsl_friendly_invocation = ~_
@@ -350,10 +338,17 @@ ometa TinyAstEvaluator(compilerParameters as CompilerParameters):
closure_stmt_list = (closure_stmt >> s ^ [s]) | (Block(Forms: ++closure_stmt >> s) ^ s)
- closure_stmt = closure_stmt_expression | stmt_return | stmt_raise | stmt_unpack
+ closure_stmt = closure_stmt_expression \
+ | stmt_return \
+ | stmt_raise \
+ | stmt_unpack \
+ | closure_stmt_macro
closure_stmt_expression = here >> i, (assignment >> e | (prefix[assignment] >> e, stmt_modifier >> m) ), next[i] ^ ExpressionStatement(Expression: e, Modifier: m)
-
+
+ closure_stmt_macro = here >> i, prefix_or_rule[macro_id] >> name, optional_prefix_or_rule[assignment_list] >> args\
+ , optional_prefix_or_rule[stmt_modifier] >> mod, next[i] ^ newMacro(name, args, null, mod)
+
array_literal = array_literal_multi | array_literal_multi_typed
array_literal_multi = Brackets(
@@ -483,7 +478,7 @@ ometa TinyAstEvaluator(compilerParameters as CompilerParameters):
Pair(Left: macro_id >> name, Right: block >> b) | \
Prefix(
Operator: macro_id >> name,
- Operand: (optional_assignment_list >> args, ~_) | Pair(Left: optional_assignment_list >> args, Right: block >> b)
+ Operand: (assignment_list >> args, ~_) | Pair(Left: assignment_list >> args, Right: block >> b)
) ^ newMacro(name, args, b, null)
macro_id = Identifier(Name: _ >> name, IsKeyword: _ >> k and (k == false)) ^ name
@@ -535,6 +530,31 @@ ometa TinyAstEvaluator(compilerParameters as CompilerParameters):
qq_return = (RETURN | Prefix(Operator: RETURN, Operand: assignment >> e)) ^ ReturnStatement(Expression: e, Modifier: null)
qq_macro = prefix[id] >> name, optional_assignment_list >> args ^ newMacro(name, args, null, null)
+
+ #region "auxiliary rules"
+
+ prefix[rule] = Prefix(Operator: rule >> e, Operand: _ >> newInput), $(success(newInput, e))
+ optional_prefix[rule] = (Prefix(Operator: rule >> e, Operand: _ >> newInput), $(success(newInput, e))) | ""
+
+ optional_prefix_or_rule[rule] = (Prefix(Operator: rule >> e, Operand: _ >> newInput), $(success(newInput, e))) | optional[rule]
+
+ prefix_or_rule[rule] = (Prefix(Operator: rule >> e, Operand: _ >> newInput), $(success(newInput, e))) | rule
+
+ rule_or_prefix[rule] = (Prefix(Operator: rule >> e, Operand: _ >> newInput), $(success(newInput, e))) | rule
+
+ optional[rule] = (rule >> e, $(success(input, e))) | ""
+
+ prefix2[rule] = Prefix(Operand: rule >> e, Operator: _ >> newInput), $(success(newInput, e))
+ optional_prefix2[rule] = (Prefix(Operand: rule >> e, Operator: _ >> newInput), $(success(newInput, e))) | ""
+
+ prefixOrId = id \
+ |(
+ Prefix(Operator: id >> e, Operand: _ >> newInput), $(success(newInput, e))
+ )
+ prefixOrInfix = (Prefix(Operator: _ >> e, Operand: _ >> newInput), $(success(OMetaInput.For([e, newInput]), e))) \
+ | (Infix() >> e, $(success(e, e)))
+
+ #endregion
def getStatement(s):
return s if s isa Statement
View
4 src/Boo.TinyAst/TinyAstParser.boo
@@ -171,10 +171,10 @@ ometa TinyAstParser < WhitespaceSensitiveTokenizer:
,(
(
(("" and (op isa Identifier and not (op as Identifier).IsKeyword), enter_tuple2) | reset_tuple2)
- , prefix_expression >> e
+ , ++prefix_expression >> e
//, (("" and (op isa Identifier and not (op as Identifier).IsKeyword), leave_tuple2) | "")
)
- ) ^ newPrefix(op, e, null, null)
+ ) ^ getRight(op, e)
) \
| pair | tuple2 | high_pr_pair #right infix
View
6 tests/testcases/evaluation/closures-20.boo
@@ -1,6 +1,6 @@
"""
-c1 = { print 'foo' }
-c2 = { item | print item if (item is not null) }
+c1 = { print('foo') }
+c2 = { item | print(item) if (item is not null) }
"""
c1 = { print "foo" }
-c2 = { item | print item if item is not null }
+c2 = { item => print item if item is not null }

No commit comments for this range

Something went wrong with that request. Please try again.