From bb23921ea8e200094962566b033ef7101de9d3b1 Mon Sep 17 00:00:00 2001 From: hellerve Date: Mon, 5 Oct 2020 23:00:40 +0200 Subject: [PATCH] et facta est lux --- .project | 3 + src/.properties | 3 + src/Carp/CarpParser.class.st | 194 ++++++++++++++++++++++++++++++++++ src/Carp/CarpScanner.class.st | 177 +++++++++++++++++++++++++++++++ src/Carp/package.st | 1 + 5 files changed, 378 insertions(+) create mode 100644 .project create mode 100644 src/.properties create mode 100644 src/Carp/CarpParser.class.st create mode 100644 src/Carp/CarpScanner.class.st create mode 100644 src/Carp/package.st diff --git a/.project b/.project new file mode 100644 index 0000000..81083cc --- /dev/null +++ b/.project @@ -0,0 +1,3 @@ +{ + 'srcDirectory' : 'src' +} \ No newline at end of file diff --git a/src/.properties b/src/.properties new file mode 100644 index 0000000..ad0471d --- /dev/null +++ b/src/.properties @@ -0,0 +1,3 @@ +{ + #format : #tonel +} \ No newline at end of file diff --git a/src/Carp/CarpParser.class.st b/src/Carp/CarpParser.class.st new file mode 100644 index 0000000..1eea29b --- /dev/null +++ b/src/Carp/CarpParser.class.st @@ -0,0 +1,194 @@ +Class { + #name : #CarpParser, + #superclass : #SmaCCGLRParser, + #category : #Carp +} + +{ #category : #'generated-accessing' } +CarpParser class >> cacheId [ + ^'2020-10-05T22:57:25.346883+02:00' +] + +{ #category : #generated } +CarpParser class >> definitionComment [ +"%glr; + + + : [0-9a-fA-F] + ; + + : \\ ([^\r\n] | (u {4,4}))+ + ; + + : (\"" ([^\""\\] | )* \"") + ; + + : \( + ; + + : \) + ; + + : \' + ; + + : | _ | \$ | \+ | \* | \/ | \? | ! | > | < | = | : + ; +default + : * + ; + + : | + ; + + : * + ; + + : ( | ,)+ + ; + + : \. + ; + + : a + ; + + : \[ + ; + + : \] + ; + + : 0 b [0-1] + ; + + : 0 x [0-9a-fA-F] + ; + + : [0-9]+ + ; + + : ( \. f?) +| ( (f|l|b)?) + ; + + : | | + ;Start + : Expression+ + ; +Expression + : Literal + ; +Literal + : String | List | Array | Symbol | Quote | Number + ; +Number + : + ; +Array + : ListContents + ; +Quote + : Expression + ; +Symbol + : ModuleOrType | Variable + ; +Variable + : + ; +ModuleOrType + : Symbol + | + ; +List + : ListContents + ; +ListContents + : Expression ListContents + | Expression + ; +String + : + ;" +] + +{ #category : #generated } +CarpParser class >> reduceTable [ +^#( + #(25 1 #reduceFor: 1310721 false ) + #(21 1 #reduceFor: 1111041 false ) + #(22 1 #reduceFor: 1137666 false ) + #(17 1 #reduceFor: 952321 false ) + #(13 1 #reduceFor: 837633 false ) + #(14 1 #reduceFor: 847873 false ) + #(15 1 #reduceFor: 863233 false ) + #(16 1 #reduceFor: 888838 false ) + #(16 1 #reduceFor: 888835 false ) + #(16 1 #reduceFor: 888837 false ) + #(16 1 #reduceFor: 888836 false ) + #(20 1 #reduceFor: 1073154 false ) + #(20 1 #reduceFor: 1073153 false ) + #(16 1 #reduceFor: 888834 false ) + #(16 1 #reduceFor: 888833 false ) + #(24 1 #reduceFor: 1244162 false ) + #(19 2 #reduceFor: 1041409 false ) + #(14 2 #reduceFor: 847874 false ) + #(23 3 #reduceFor: 1191937 false ) + #(22 3 #reduceFor: 1137665 false ) + #(18 3 #reduceFor: 984065 false ) + #(24 3 #reduceFor: 1244161 false ) + ). +] + +{ #category : #generated } +CarpParser class >> scannerClass [ + ^CarpScanner +] + +{ #category : #generated } +CarpParser class >> startingStateForStart [ + ^ 1 +] + +{ #category : #generated } +CarpParser class >> symbolNames [ + ^ #('' '' '' '' '' '' '' '' '' '' '' 'B e g i n' 'Start' 'Expression+' 'Expression' 'Literal' 'Number' 'Array' 'Quote' 'Symbol' 'Variable' 'ModuleOrType' 'List' 'ListContents' 'String' 'E O F' 'error') +] + +{ #category : #generated } +CarpParser class >> transitionTable [ +^#( +#[1 0 9 0 1 0 13 0 2 0 17 0 4 0 21 0 5 0 25 0 6 0 29 0 9 0 33 0 11 0 37 0 13 0 41 0 14 0 45 0 15 0 49 0 16 0 53 0 17 0 57 0 18 0 61 0 19 0 65 0 20 0 69 0 21 0 73 0 22 0 77 0 23 0 81 0 25] +#[0 0 6 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[1 0 9 0 1 0 13 0 2 0 17 0 4 0 21 0 5 0 25 0 6 0 29 0 9 0 33 0 11 0 85 0 15 0 49 0 16 0 53 0 17 0 57 0 18 0 61 0 19 0 65 0 20 0 69 0 21 0 73 0 22 0 77 0 23 0 89 0 24 0 81 0 25] +#[1 0 9 0 1 0 13 0 2 0 17 0 4 0 21 0 5 0 25 0 6 0 29 0 9 0 33 0 11 0 93 0 15 0 49 0 16 0 53 0 17 0 57 0 18 0 61 0 19 0 65 0 20 0 69 0 21 0 73 0 22 0 77 0 23 0 81 0 25] +#[0 0 10 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[1 0 14 0 1 0 14 0 2 0 14 0 3 0 14 0 4 0 14 0 5 0 14 0 6 0 14 0 7 0 97 0 8 0 14 0 9 0 14 0 10 0 14 0 11 0 14 0 26] +#[1 0 9 0 1 0 13 0 2 0 17 0 4 0 21 0 5 0 25 0 6 0 29 0 9 0 33 0 11 0 85 0 15 0 49 0 16 0 53 0 17 0 57 0 18 0 61 0 19 0 65 0 20 0 69 0 21 0 73 0 22 0 77 0 23 0 101 0 24 0 81 0 25] +#[0 0 18 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 0 0 26] +#[1 0 9 0 1 0 13 0 2 0 17 0 4 0 21 0 5 0 25 0 6 0 29 0 9 0 33 0 11 0 105 0 15 0 49 0 16 0 53 0 17 0 57 0 18 0 61 0 19 0 65 0 20 0 69 0 21 0 73 0 22 0 77 0 23 0 81 0 25 0 22 0 26] +#[0 0 26 0 1 0 2 0 4 0 5 0 6 0 9 0 11 0 26] +#[0 0 30 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 34 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 38 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 42 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 46 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 50 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 54 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 58 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 62 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[1 0 66 0 3 0 109 0 7 0 66 0 10] +#[0 0 113 0 3] +#[0 0 70 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[1 0 21 0 5 0 25 0 6 0 117 0 20 0 69 0 21 0 73 0 22] +#[0 0 121 0 10] +#[0 0 74 0 1 0 2 0 4 0 5 0 6 0 9 0 11 0 26] +#[1 0 9 0 1 0 13 0 2 0 17 0 4 0 21 0 5 0 25 0 6 0 29 0 9 0 33 0 11 0 85 0 15 0 49 0 16 0 53 0 17 0 57 0 18 0 61 0 19 0 65 0 20 0 69 0 21 0 73 0 22 0 77 0 23 0 125 0 24 0 81 0 25] +#[0 0 78 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 82 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 86 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 9 0 10 0 11 0 26] +#[0 0 90 0 3 0 10] + ). +] diff --git a/src/Carp/CarpScanner.class.st b/src/Carp/CarpScanner.class.st new file mode 100644 index 0000000..debfeeb --- /dev/null +++ b/src/Carp/CarpScanner.class.st @@ -0,0 +1,177 @@ +Class { + #name : #CarpScanner, + #superclass : #SmaCCScanner, + #category : #Carp +} + +{ #category : #generated } +CarpScanner >> emptySymbolTokenId [ + ^ 26 +] + +{ #category : #generated } +CarpScanner >> errorTokenId [ + ^ 27 +] + +{ #category : #generated } +CarpScanner >> scan1 [ + [ self step. + currentCharacter == $" + ifTrue: [ ^ self recordAndReportMatch: #(1) ]. + currentCharacter == $\ + ifTrue: [ self step. + (currentCharacter <= Character tab + or: [ (currentCharacter between: Character pageUp and: Character newPage) + or: [ currentCharacter >= (Character value: 14) ] ]) + ifTrue: [ ^ self scan2 ]. + ^ self reportLastMatch ]. + true ] whileTrue +] + +{ #category : #generated } +CarpScanner >> scan2 [ + [ self step. + currentCharacter == $" + ifTrue: [ [ self recordMatch: #(1). + self step. + currentCharacter == $" ] whileTrue. + (currentCharacter == Character lf + or: [ currentCharacter == Character cr ]) + ifTrue: [ ^ self scan1 ]. + ^ self scan2 ]. + (currentCharacter == Character lf + or: [ currentCharacter == Character cr ]) + ifTrue: [ ^ self scan1 ]. + true ] whileTrue +] + +{ #category : #generated } +CarpScanner >> scan3 [ + self step. + currentCharacter isDigit + ifTrue: [ [ self recordMatch: #(11). + self step. + currentCharacter == $f + ifTrue: [ ^ self recordAndReportMatch: #(11) ]. + currentCharacter isDigit ] whileTrue ]. + ^ self reportLastMatch +] + +{ #category : #generated } +CarpScanner >> scan4 [ + [ self recordMatch: #(11). + self step. + currentCharacter == $. + ifTrue: [ ^ self scan3 ]. + currentCharacter isDigit ] whileTrue. + ('bfl' includes: currentCharacter) + ifTrue: [ ^ self recordAndReportMatch: #(11) ]. + ^ self reportLastMatch +] + +{ #category : #generated } +CarpScanner >> scanForToken [ + self step. + currentCharacter == $" + ifTrue: [ ^ self scan1 ]. + currentCharacter == $' + ifTrue: [ ^ self recordAndReportMatch: #(4) ]. + currentCharacter == $( + ifTrue: [ ^ self recordAndReportMatch: #(2) ]. + currentCharacter == $) + ifTrue: [ ^ self recordAndReportMatch: #(3) ]. + currentCharacter == $. + ifTrue: [ ^ self recordAndReportMatch: #(8) ]. + ^ self scanForTokenX5 +] + +{ #category : #generated } +CarpScanner >> scanForTokenX1 [ + self recordMatch: #(11). + self step. + currentCharacter == $. + ifTrue: [ ^ self scan3 ]. + currentCharacter == $b + ifTrue: [ self recordMatch: #(11). + self step. + (currentCharacter between: $0 and: $1) + ifTrue: [ ^ self recordAndReportMatch: #(11) ]. + ^ self reportLastMatch ]. + currentCharacter == $x + ifTrue: [ self step. + (currentCharacter isDigit + or: [ (currentCharacter between: $A and: $F) + or: [ currentCharacter between: $a and: $f ] ]) + ifTrue: [ ^ self recordAndReportMatch: #(11) ]. + ^ self reportLastMatch ]. + currentCharacter isDigit + ifTrue: [ ^ self scan4 ]. + ('fl' includes: currentCharacter) + ifTrue: [ ^ self recordAndReportMatch: #(11) ]. + ^ self reportLastMatch +] + +{ #category : #generated } +CarpScanner >> scanForTokenX2 [ + [ self recordMatch: #(6). + self step. + currentCharacter isLowercase + or: [ currentCharacter isDigit + or: [ ('!$' includes: currentCharacter) + or: [ (currentCharacter between: $* and: $+) + or: [ ('/:' includes: currentCharacter) + or: [ (currentCharacter between: $< and: $?) + or: [ currentCharacter == $_ ] ] ] ] ] ] ] whileTrue. + ^ self reportLastMatch +] + +{ #category : #generated } +CarpScanner >> scanForTokenX3 [ + [ self recordMatch: #(5). + self step. + currentCharacter isLowercase + or: [ currentCharacter isDigit + or: [ ('!$' includes: currentCharacter) + or: [ (currentCharacter between: $* and: $+) + or: [ ('/:' includes: currentCharacter) + or: [ (currentCharacter between: $< and: $?) + or: [ currentCharacter == $_ ] ] ] ] ] ] ] whileTrue +] + +{ #category : #generated } +CarpScanner >> scanForTokenX4 [ + [ self recordMatch: #(7). + self step. + currentCharacter isSpaceSeparator or: [ currentCharacter == $, ] ] + whileTrue. + ^ self reportLastMatch +] + +{ #category : #generated } +CarpScanner >> scanForTokenX5 [ + currentCharacter == $0 + ifTrue: + [ ^ self scanForTokenX1 ]. + currentCharacter == $[ + ifTrue: [ ^ self recordAndReportMatch: #(9) ]. + currentCharacter == $] + ifTrue: [ ^ self recordAndReportMatch: #(10) ]. + currentCharacter isDigit + ifTrue: [ ^ self scan4 ]. + (currentCharacter isSpaceSeparator or: [ currentCharacter == $, ]) + ifTrue: + [ ^ self scanForTokenX4 ]. + currentCharacter isUppercase + ifTrue: + [ ^ self scanForTokenX2 ]. + (currentCharacter isLowercase + or: [ ('!$' includes: currentCharacter) + or: [ (currentCharacter between: $* and: $+) + or: [ ('/:' includes: currentCharacter) + or: [ (currentCharacter between: $< and: $?) + or: [ currentCharacter == $_ ] ] ] ] ]) + ifTrue: + [ self scanForTokenX3 ]. + ^ self reportLastMatch +] diff --git a/src/Carp/package.st b/src/Carp/package.st new file mode 100644 index 0000000..7753f2e --- /dev/null +++ b/src/Carp/package.st @@ -0,0 +1 @@ +Package { #name : #Carp }