|
[boo]
boo, ometa and extensible parsing I
[
bamboo
]
Meanwhile in a repository not far away:
namespace metaboo
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.OMeta
import Boo.OMeta.Parser
syntax Units:
atom = mass | super
mass = (integer >> value as Expression, "kg") ^ [| Mass($value, "kg") |]
syntax Ranges:
atom = integer_range | super
integer_range = (integer >> begin as Expression, DOT, DOT, integer >> end as Expression) ^ [| range($begin, $end) |]
def parse(code as string):
compiler = BooCompiler()
compiler.Parameters.References.Add(System.Reflection.Assembly.GetExecutingAssembly())
compiler.Parameters.Input.Add(IO.StringInput("code", code))
compiler.Parameters.Pipeline = CompilerPipeline()
compiler.Parameters.Pipeline.Add(BooParserStep())
return compiler.Run()
code = """
import metaboo.Units
import metaboo.Ranges
a = 3kg
print a
for i in 1..3:
print i
"""
result = parse(code)
assert 0 == len(result.Errors), result.Errors.ToString()
assert 1 == len(result.CompileUnit.Modules)
print result.CompileUnit.Modules[0].ToCodeString()
And the output is, of course:
import metaboo.Units import metaboo.Ranges a = Mass(3, 'kg') print a for i in range(1, 3): print i BOO-1 is finally about to die :) --Cedric, August 5, 2008 10:53 AM
Now that's cool. --Alexey Romanov, August 5, 2008 12:23 PM
Cedric: Boo 1 hasn't even come out yet :-P --Justin Chase, August 5, 2008 12:25 PM
This is extremely cool, but the meta-syntax syntax is a little confusing. --Avish, August 5, 2008 07:21 PM
Avish, when the new parser is ready we'll definitely have a special ometa syntax, the cool thing is that it will simply be an extension :) About boo-extensions being the right place, it definitely won't be the final home of Boo.OMeta. Best wishes, --Rodrigo B. de Oliveira, August 5, 2008 08:34 PM
Post a comment
|