||| Copyright (C) 1998-2011, Sumisho Computer Systems Corp. All Rights Reserved. ||| Licensed under the Apache License, Version 2.0 (the "License"); ||| you may not use this file except in compliance with the License. ||| You may obtain a copy of the License at ||| ||| http://www.apache.org/licenses/LICENSE-2.0 ||| ||| Unless required by applicable law or agreed to in writing, software ||| distributed under the License is distributed on an "AS IS" BASIS, ||| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ||| See the License for the specific language governing permissions and ||| limitations under the License. {define-macro public {define-screen-command ?name:identifier ?event-spec:{optional on ?:expression} ?target-spec:{optional at ?:expression} ?screen-spec:{optional of ?:expression} ?enabled:{optional {enabled? ?:statements}} do ?execute-body:verbatim } || Event Target let target-var-decl:#CurlSource = null {syntax-switch target-spec, must-match? = true case {pattern} do || do nothing. case {pattern at ?expr:expression} do let valid?:bool = false {type-switch expr case sb:SingleBinding do {if sb.value == null and sb.type != null then def target-type = {non-null sb.type} set target-var-decl = {expand-template let ?sb = self.meta-data.target asa ?target-type } set valid? = true } } {if not valid? then {expr.parse-error "Unexpected expression '%s'", {expr.get-text} } } } || Event let event-var-decl:#CurlSource = null {syntax-switch event-spec, must-match? = true case {pattern} do || do nothing. case {pattern on ?expr:expression} do let valid?:bool = false {type-switch expr case sb:SingleBinding do {if sb.value == null and sb.type != null then def event-type = {non-null sb.type} set event-var-decl = {expand-template let ?sb = self.meta-data.event asa ?event-type } set valid? = true } } {if not valid? then {expr.parse-error "Unexpected expression '%s'", {expr.get-text} } } } || Screen class let screen-type:#CurlSource = null let screen-var-decl:#CurlSource = null {syntax-switch screen-spec, must-match? = true case {pattern} do set screen-type = {Identifier "BaseScreen"} case {pattern of ?type:identifier} do set screen-type = type case {pattern of ?expr:expression} do let valid?:bool = false {type-switch expr case sb:SingleBinding do {if sb.value == null and sb.type != null then set screen-type = {non-null sb.type} set screen-var-decl = {expand-template let ?sb = self.screen } set valid? = true } } {if not valid? then {expr.parse-error "Unexpected expression '%s'", {expr.get-text} } } } || Command class def command-name = {Literal name.name} def command-class = {Identifier {screen-type.get-text} & '_' & command-name.value } || default constructor def constructor-src = {expand-template {constructor public {default screen:?screen-type} {construct-super ?command-name, screen} } } || enabled? getter def enabled-src = {syntax-switch enabled, must-match? = true case {pattern} do {EmptySource} case {pattern {enabled? ?enabled-body:statements}} do {expand-template {getter public {enabled?}:bool ?screen-var-decl {return {value ?enabled-body} and super.enabled?} } } } || execute method def execute-src = {expand-template {method public {execute}:void ?event-var-decl ?target-var-decl ?screen-var-decl ?execute-body } } {return {expand-template {define-class public ?=command-class {inherits {ScreenCommand-of ?screen-type}} ?constructor-src ?enabled-src ?execute-src } {do {ScreenCommandContext.registry.register-command ?command-name, ?screen-type, ?command-class } } } } }