Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ build.properties
*.userprefs
test-results
.gradle
/src/Boo.Adt.Tests/obj
/src/Boo.Adt/obj
/src/Boo.OMeta.Parser.Tests/obj
/src/Boo.OMeta.Parser/obj
/src/Boo.OMeta.Tests/obj
/src/Boo.OMeta/obj
/src/OMetaParserConsole/obj
10 changes: 5 additions & 5 deletions src/Boo.Adt.Tests/Boo.Adt.Tests.booproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -9,7 +9,8 @@
<OutputType>Library</OutputType>
<RootNamespace>Boo.Adt.Tests</RootNamespace>
<AssemblyName>Boo.Adt.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -34,9 +35,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
<Reference Include="Boo.Lang, Version=2.0.9.5, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
<Reference Include="Boo.Lang.PatternMatching, Version=2.0.9.5, Culture=neutral, PublicKeyToken=32c39770e9a21a67" />
<Reference Include="nunit.framework" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataMacroTest.boo" />
Expand All @@ -48,4 +47,5 @@
<Name>Boo.Adt</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(BooBinPath)\Boo.Microsoft.Build.targets" />
</Project>
120 changes: 120 additions & 0 deletions src/Boo.OMeta.Parser.Tests/BooParserTestFixture.Generated.boo
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,31 @@ partial class BooParserTestFixture:
runTestCase("assignment-1.boo")


[Test]
def ast_literal_enum():
runTestCase("ast-literal-enum.boo")


[Test]
def ast_literal_varargs_method():
runTestCase("ast-literal-varargs-method.boo")


[Test]
def ast_literals_1():
runTestCase("ast-literals-1.boo")


[Test]
def ast_literals_10():
runTestCase("ast-literals-10.boo")


[Test]
def ast_literals_11():
runTestCase("ast-literals-11.boo")


[Test]
def ast_literals_2():
runTestCase("ast-literals-2.boo")
Expand Down Expand Up @@ -96,6 +116,16 @@ partial class BooParserTestFixture:
runTestCase("ast-literals-9.boo")


[Test]
def ast_literals_if_it_looks_like_a_block_1():
runTestCase("ast-literals-if-it-looks-like-a-block-1.boo")


[Test]
def at_operator():
runTestCase("at-operator.boo")


[Test]
def attributes_1():
runTestCase("attributes-1.boo")
Expand All @@ -121,6 +151,16 @@ partial class BooParserTestFixture:
runTestCase("callables-2.boo")


[Test]
def callables_with_varags():
runTestCase("callables-with-varags.boo")


[Test]
def cast_1():
runTestCase("cast-1.boo")


[Test]
def char_1():
runTestCase("char-1.boo")
Expand Down Expand Up @@ -216,6 +256,11 @@ partial class BooParserTestFixture:
runTestCase("closures-21.boo")


[Test]
def closures_22():
runTestCase("closures-22.boo")


[Test]
def closures_3():
runTestCase("closures-3.boo")
Expand Down Expand Up @@ -251,6 +296,11 @@ partial class BooParserTestFixture:
runTestCase("closures-9.boo")


[Test]
def collection_initializer():
runTestCase("collection-initializer.boo")


[Test]
def comments_1():
runTestCase("comments-1.boo")
Expand Down Expand Up @@ -311,6 +361,11 @@ partial class BooParserTestFixture:
runTestCase("elif-2.boo")


[Test]
def enumerable_type_shortcut():
runTestCase("enumerable-type-shortcut.boo")


[Test]
def enums_1():
runTestCase("enums-1.boo")
Expand All @@ -326,6 +381,11 @@ partial class BooParserTestFixture:
runTestCase("explode-1.boo")


[Test]
def explode_2():
runTestCase("explode-2.boo")


[Test]
def expressions_1():
runTestCase("expressions-1.boo")
Expand Down Expand Up @@ -481,6 +541,11 @@ partial class BooParserTestFixture:
runTestCase("hash-1.boo")


[Test]
def hash_initializer():
runTestCase("hash-initializer.boo")


[Test]
def iif_1():
runTestCase("iif-1.boo")
Expand Down Expand Up @@ -566,6 +631,11 @@ partial class BooParserTestFixture:
runTestCase("interpolation-3.boo")


[Test]
def interpolation_4():
runTestCase("interpolation-4.boo")


[Test]
def invocation_1():
runTestCase("invocation-1.boo")
Expand All @@ -591,6 +661,11 @@ partial class BooParserTestFixture:
runTestCase("list-1.boo")


[Test]
def long_literals_1():
runTestCase("long-literals-1.boo")


[Test]
def macro_doc():
runTestCase("macro-doc.boo")
Expand All @@ -616,6 +691,16 @@ partial class BooParserTestFixture:
runTestCase("macros-anywhere-1.boo")


[Test]
def method_declaration_in_macro_application():
runTestCase("method-declaration-in-macro-application.boo")


[Test]
def method_declarations_in_nested_macro_application():
runTestCase("method-declarations-in-nested-macro-application.boo")


[Test]
def module_1():
runTestCase("module-1.boo")
Expand All @@ -641,6 +726,11 @@ partial class BooParserTestFixture:
runTestCase("named-arguments-2.boo")


[Test]
def new_1():
runTestCase("new-1.boo")


[Test]
def not_1():
runTestCase("not-1.boo")
Expand All @@ -656,11 +746,21 @@ partial class BooParserTestFixture:
runTestCase("null-1.boo")


[Test]
def omitted_member_target_1():
runTestCase("omitted-member-target-1.boo")


[Test]
def ones_complement_1():
runTestCase("ones-complement-1.boo")


[Test]
def ref_1():
runTestCase("ref-1.boo")


[Test]
def regex_literals_1():
runTestCase("regex-literals-1.boo")
Expand Down Expand Up @@ -706,6 +806,16 @@ partial class BooParserTestFixture:
runTestCase("splicing-1.boo")


[Test]
def splicing_class_body():
runTestCase("splicing-class-body.boo")


[Test]
def splicing_enum_body():
runTestCase("splicing-enum-body.boo")


[Test]
def string_literals_1():
runTestCase("string-literals-1.boo")
Expand All @@ -731,6 +841,11 @@ partial class BooParserTestFixture:
runTestCase("try-2.boo")


[Test]
def type_references_1():
runTestCase("type-references-1.boo")


[Test]
def unless_1():
runTestCase("unless-1.boo")
Expand Down Expand Up @@ -765,3 +880,8 @@ partial class BooParserTestFixture:
def yield_1():
runTestCase("yield-1.boo")


[Test]
def yield_as_member_name():
runTestCase("yield-as-member-name.boo")

3 changes: 2 additions & 1 deletion src/Boo.OMeta.Parser.Tests/BooParserTestFixture.boo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ partial class BooParserTestFixture:
fullName = Path.Combine(booRoundtripTestCasesPath(), fname)

parser = BooParser()
match parser.module(File.ReadAllText(fullName)):
text = File.ReadAllText(fullName)
match parser.module(text):
case SuccessfulMatch(Input: input, Value: m=Module()):
assert m is not null
assert m.Documentation is not null
Expand Down
55 changes: 46 additions & 9 deletions src/Boo.OMeta.Parser/AST.boo
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,37 @@ def newModule(ns as string, doc, imports, members, stmts):
for member in flatten(members):
if member isa Ast.Attribute:
m.AssemblyAttributes.Add(member)
elif member isa ModuleAttribute:
for attr in (member as ModuleAttribute).Attr:
m.Attributes.Add(attr)
elif member isa MacroStatement:
m.Globals.Add(member as Statement)
else:
m.Members.Add(member)
for stmt as Statement in stmts: m.Globals.Add(stmt)
return m

def newImport(qname as string, assembly, alias):

def newNamespaceExpr(qname as string, exprs as List) as Expression:
result as Expression = Ast.ReferenceExpression(qname)
if exprs:
mie = Ast.MethodInvocationExpression(result)
for arg in exprs:
mie.Arguments.Add(arg)
result = mie
return result

def newImportFrom(qname as string, exprs) as Import:
ns = ReferenceExpression(qname)
mie = MethodInvocationExpression(ns)
result = Import(mie, null, null)
if exprs is null:
result.Expression = ns.CleanClone()
elif exprs:
for arg in exprs:
mie.Arguments.Add(arg)
return result

def newImport(name as Expression, assembly, alias) as Import:
assemblyReference = null
if assembly isa Token:
assemblyReference = ReferenceExpression(Name: tokenValue(assembly))
Expand All @@ -109,11 +132,11 @@ def newImport(qname as string, assembly, alias):

importAlias = null
if alias isa Token:
importAlias = ReferenceExpression(Name: tokenValue(alias))
importAlias = ReferenceExpression(Name: tokenValue(alias))
else:
importAlias = ReferenceExpression(Name: alias) if alias is not null
importAlias = ReferenceExpression(Name: alias) if alias is not null

return Import(qname, AssemblyReference: assemblyReference, Alias: importAlias)
return Import(name, assemblyReference, importAlias)

def newInteger(sign, t, style as NumberStyles, suffix):
s = tokenValue(sign) + tokenValue(t)
Expand Down Expand Up @@ -215,18 +238,26 @@ def newGenericParameterDeclaration(name, constraints):

return node

def newParameterDeclaration(attributes, name, type):
def newParameterDeclaration(attributes, modifiers, name, type):
node = ParameterDeclaration(Name: tokenValue(name), Type: type)
if modifiers isa Token:
if tokenValue(modifiers) == 'ref':
node.Modifiers = ParameterModifiers.Ref
else: raise "Unknown modifier: $tokenValue(modifiers)"
elif modifiers == 'ref': raise 'misunderstood'
return setUpAttributes(node, attributes)

def newEnum(attributes, modifiers, name, members):
if members and not (members isa System.Collections.IEnumerable):
members = List() {members}
return setUpType(EnumDefinition(Name: tokenValue(name)), attributes, modifiers, null, null, members)

def newCallableTypeReference(params, paramArray, type):
node = CallableTypeReference(ReturnType: type)
i = 0
for p in flatten(params):
node.Parameters.Add(ParameterDeclaration(Name: "arg${i++}", Type: p))
for p as ParameterDeclaration in flatten(params):
p.Name = "arg${i++}"
node.Parameters.Add(p)

if paramArray is not null:
node.Parameters.Add(paramArray)
Expand Down Expand Up @@ -501,4 +532,10 @@ def checkEnumerableTypeShortcut(type, stars as List):
(enumerable as GenericTypeReference).GenericArguments.Add(type)
type = enumerable
return enumerable


class ModuleAttribute:
[Getter(Attr)]
_attr as List

def constructor(attr as List):
_attr = attr
Loading