boo-lang / boo

The Boo Programming Language.
BSD 3-Clause "New" or "Revised" License
874 stars 148 forks source link

Python style "from ns import type" #40

Closed drslump closed 11 years ago

drslump commented 12 years ago

This patch adds support for Python style from ns import symbol at the grammar level and also allows for aliased symbol names.

The following constructs are supported:

import Ast(ReferenceExpression as RefExp)           # RefExp
import Ast(ReferenceExpression as RefExp) as A  # A.RefExp

from Ast import ReferenceExpression as RefExp   # RefExp
from Ast import NullLiteralExpression, ReferenceExpression as RefExp  # NullLiteralExpression, RefExp
from Ast import *    # All symbols from Ast, just like "import Ast"

Coming from a scripting languages background I tend to prefer explicit symbol importing over namespace imports, probably because I'm not used to IDEs to provide real intellisense style suggestions. While current Boo selective import syntax gets the job done I find Python's style easier to read. I also assume that many people being introduced to Boo will have probably some experience with Python, a compatible syntax for imports will probably help them in the transition.

Important: I haven't included any unit tests yet or modified the WSA grammar, I wanted to present the changes first to know if they would be ok for you.

bamboo commented 11 years ago

This feature makes sense to me. If you provide unit tests and an updated wsa grammar I'll merge it right away. Thanks.

drslump commented 11 years ago

@bamboo I have added tests and updated the wsa grammar. Thanks

bamboo commented 11 years ago

Thanks!