Transpiler for HTML-in-PowerShell, PSX (like JSX)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler: barebones following https://serhii.io/posts/writing-your-own-lexer-with-simple-steps

+135
+135
Compiler.ps1
··· 1 + param ( 2 + $PsxFile 3 + ) 4 + 5 + <# 6 + PsxElement := 7 + PsxSelfClosingElement 8 + | PsxOpeningElement PsxChildren? PsxClosingElement 9 + 10 + PsxSelfClosingElement : 11 + '<' PsxElementName PsxAttributes? '/>' 12 + 13 + PsxOpeningElement : 14 + '<' PsxElementName PsxAttributes? '>' 15 + 16 + PsxClosingElement : 17 + '</' PsxElementName '>' 18 + 19 + PsxFragment : 20 + '<>' PsxChildren? '</>' 21 + 22 + PsxElementName : 23 + PsxIdentifier 24 + | PsxMemberExpression 25 + 26 + PsxIdentifier : 27 + IdentifierStart 28 + | PsxIdentifier IdentifierPart 29 + | PsxIdentifier [no WhiteSpace or Comment here] - 30 + 31 + PsxMemberExpression : 32 + PsxIdentifier '.' PsxIdentifier 33 + | PsxMemberExpression '.' PsxIdentifier 34 + 35 + --- 36 + 37 + PsxAttributes := 38 + PsxSpreadAttribute PsxAttributes? 39 + | PsxAttribute PsxAttributes? 40 + PsxSpreadAttribute := 41 + '{' ... AssignmentExpression '}' 42 + PsxAttribute := 43 + PsxAttributeName PsxAttributeInitializer? 44 + PsxAttributeName := 45 + PsxIdentifier 46 + PsxAttributeInitializer := 47 + '=' PsxAttributeValue 48 + PsxAttributeValue := 49 + '"' PsxDoubleStringCharacters? '"' 50 + | ''' PsxSingleStringCharacters? ''' 51 + | '{' AssignmentExpression '}' 52 + | PsxElement 53 + | PsxFragment 54 + PsxDoubleStringCharacters ::= 55 + | PsxDoubleStringCharacter PsxDoubleStringCharacters? 56 + PsxDoubleStringCharacter ::= 57 + | PsxStringCharacter EXCEPT '"' 58 + PsxSingleStringCharacters ::= 59 + | PsxSingleStringCharacter PsxSingleStringCharacters? 60 + PsxSingleStringCharacter ::= 61 + | PsxStringCharacter EXCEPT ''' 62 + 63 + --- 64 + 65 + PsxChildren := 66 + PsxChild PsxChildren? 67 + PsxChild := 68 + PsxText 69 + | PsxElement 70 + | PsxFragment 71 + | '{' PsxChildExpression? '}' 72 + PsxText ::= 73 + | PsxTextCharacter PsxText? 74 + PsxTextCharacter ::= 75 + | PsxStringCharacter EXCEPT '{' '<' '>' '}' 76 + PsxChildExpression := 77 + AssignmentExpression 78 + | '...' AssignmentExpression 79 + 80 + 81 + 82 + Element := 83 + '<' Tag Attributes? '>' Children* '</' Tag '>' 84 + | '<' Tag Attributes? '/>' 85 + 86 + Tag := 87 + [a-zA-Z0-9_-]+ 88 + 89 + Attributes := 90 + (AttributeName '=' Value)* 91 + 92 + #> 93 + 94 + enum TokenType { 95 + OPEN_ELEMENT_START # < 96 + CLOSE_ELEMENT # > 97 + VOID_ELEMENT_CLOSE # /> 98 + EQUAL # = 99 + OPEN_ELEMENT_END # </ 100 + 101 + PS_BRACE_START # { 102 + PS_BRACE_END # } 103 + 104 + IDENTIFIER # [a-zA-Z0-9_-\.]+ 105 + } 106 + 107 + class Token { 108 + [TokenType] $Type 109 + [String] $Literal 110 + 111 + Token($Type, $Literal) { 112 + $this.Type = $Type 113 + $this.Literal = $Literal 114 + } 115 + 116 + [String] ToString() { 117 + return "{0} {1}" -f $this.Type, $this.Literal 118 + } 119 + 120 + [Boolean] Equals($that) { 121 + return (($this.Type -eq $that.Type) -and ($this.Literal -eq $that.Literal)) 122 + } 123 + } 124 + 125 + class Lexer { 126 + $LexInput 127 + 128 + Lexer($LexInput) { 129 + $this.LexInput = $LexInput 130 + } 131 + 132 + [Token] NextToken() { 133 + return [Token]::new([TokenType]::OPEN_ELEMENT_START, $this.LexInput) 134 + } 135 + }