Migrating code with SmaCC
John Brant brant@refactoryworkers.com
Migrating code with SmaCC John Brant brant@refactoryworkers.com - - PowerPoint PPT Presentation
Migrating code with SmaCC John Brant brant@refactoryworkers.com Migration Strategy Define Parser SmaCC Create transformation program Compatibility layer Normal development continues -Keeps same design garbage in
John Brant brant@refactoryworkers.com
✓Normal development continues
SmaCC
<number> : \d+ (\. \d*)? ; <whitespace> : \s+; %left "+"; %root Expression; %suffix Node; Expression : Expression 'left' "+" 'operator' Expression 'right' {{Binary}} | "(" 'leftParen' Expression ")" 'rightParen' {{Expression}} | <number> 'value' {{Number}} ;
ExpressionNode
BinaryNode
NumberNode
and properties
Quick to write One-off expressions
General syntax Control flow
<number> : \d+ (\. \d*) ? ; <whitespace> : \s+; <patternToken> : `[^`]+`; %glr; %left "+"; %root Expression; %suffix Node; Expression : Expression 'left' "+" 'operator' Expression 'right' {{Binary}} | "(" 'leftParen' Expression ")" 'rightParen' {{Expression}} | <number> 'value' {{Number}} ;
`a` + `a` ⇒ `a` * 2 Patterns can match any AST node
`a` = 3 `a` + `a`
BinaryNode: + Anything: `a` Anything: `a`
Search Pattern:
3 + 3
BinaryNode: + NumberNode: 3 NumberNode: 3
Source:
string is generated
`a` * 2 `a` = 3 3 * 2
Replacement: Matched patterns:
for `a` := `b` to `c` - 1 do `d` ⇒ for (`a` = `b`; `a` < `c`; `a`++) `\d\` `a/Forms.TCustomForm`.Constraints.MinHeight := `b` ⇒ `a`.MinimumSize = new Size(`a`.MinimumSize.Width, `b`)
code
Edit expressions Control flow General Smalltalk code
#replace:with: #replaceAll:with: …
#move:before: #move:after …
#insert:before: #insert:afterAll: …
#delete: #deleteWithWhitespaceAfter: …
#processChild: #processChildren #continue
“{ }” For: DelphiStatementBlockNode When: true Do: self replace: match beginToken with: '{'. self replace: match endToken with: ‘}'. self continue “function objects” For: PBTypeDeclarationNode When: match from source sameAs: 'function_object' Do: self isStatic: true. self classStart: match startPosition. self replace: match with: 'public partial class ' , self functionsClassName , ' {'
http://www.refactoryworkers.com/SmaCC/ Download for Pharo:
Gofer new smalltalkhubUser: 'JohnBrant' project: 'SmaCC'; configurationOf: 'SmaCC'; loadBleedingEdge