summaryrefslogtreecommitdiff
path: root/RGens/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'RGens/src/main')
-rw-r--r--RGens/src/main/java/bjc/RGens/parser/RBGrammarReader.java8
-rw-r--r--RGens/src/main/java/bjc/RGens/parser/ReaderState.java2
-rwxr-xr-xRGens/src/main/java/bjc/RGens/parser/sample-grammars/24hr-rpg.gram9
-rwxr-xr-xRGens/src/main/java/bjc/RGens/parser/sample-grammars/anime.gram27
-rw-r--r--RGens/src/main/java/bjc/RGens/parser/sample-grammars/college.gram515
-rwxr-xr-xRGens/src/main/java/bjc/RGens/parser/sample-grammars/dungeon-enviroment.gram2
-rw-r--r--RGens/src/main/java/bjc/RGens/parser/sample-grammars/insults.gram156
-rw-r--r--RGens/src/main/java/bjc/RGens/parser/sample-grammars/mission.gram461
-rw-r--r--RGens/src/main/java/bjc/RGens/server/GrammarServer.java188
-rw-r--r--RGens/src/main/java/bjc/RGens/server/ReaderState.java184
-rw-r--r--RGens/src/main/java/bjc/RGens/server/ServerGrammarReader.java261
11 files changed, 1788 insertions, 25 deletions
diff --git a/RGens/src/main/java/bjc/RGens/parser/RBGrammarReader.java b/RGens/src/main/java/bjc/RGens/parser/RBGrammarReader.java
index 48e21b1..bf3a40c 100644
--- a/RGens/src/main/java/bjc/RGens/parser/RBGrammarReader.java
+++ b/RGens/src/main/java/bjc/RGens/parser/RBGrammarReader.java
@@ -158,7 +158,7 @@ public class RBGrammarReader {
actualName.deleteCharAt(actualName.length() - 1);
actualName.append("]");
- retList = gram.generateGenericValues(actualName.toString(), (s) -> s, " ");
+ retList = gramm.generateGenericValues(actualName.toString(), (s) -> s, " ");
} else {
// @FIXME notify the user they did something wrong
retList.add(strang);
@@ -168,11 +168,7 @@ public class RBGrammarReader {
return retList;
};
- Runnable specialReset = () -> {
- vars.clear();
- };
-
- gram.configureSpecial(specialPredicate, specialAction, specialReset);
+ gram.configureSpecial(specialPredicate, specialAction);
return gram;
} catch (IOException ioex) {
diff --git a/RGens/src/main/java/bjc/RGens/parser/ReaderState.java b/RGens/src/main/java/bjc/RGens/parser/ReaderState.java
index 8e846cf..14d7ff8 100644
--- a/RGens/src/main/java/bjc/RGens/parser/ReaderState.java
+++ b/RGens/src/main/java/bjc/RGens/parser/ReaderState.java
@@ -150,6 +150,8 @@ public class ReaderState {
*/
public void startNewRule(String ruleName) {
currentGrammar.addRule(ruleName);
+
+ currentRule = ruleName;
}
/**
diff --git a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/24hr-rpg.gram b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/24hr-rpg.gram
index 7c4eadf..344d9a8 100755
--- a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/24hr-rpg.gram
+++ b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/24hr-rpg.gram
@@ -1,6 +1,6 @@
-[rpg] [rpg-part] , [rpg-part] and <rpg-part>
- [rpg-part] and <rpg-part>
- [rpg-part] the <rpg-part>
+[rpg] [rpg-part] , [rpg-part] and [rpg-part]
+ [rpg-part] and [rpg-part]
+ [rpg-part] the [rpg-part]
pragma initial-rule [rpg]
@@ -201,5 +201,4 @@ pragma initial-rule [rpg]
skies
madness
economy
- the 60s
-
+ the 60s
diff --git a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/anime.gram b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/anime.gram
index 1a695c8..0cc21d8 100755
--- a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/anime.gram
+++ b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/anime.gram
@@ -1,19 +1,20 @@
-[initial-name] [two-name]
- [three-name]
+[anime-name] [anime-two-name]
+ [anime-three-name]
-pragma initial-rule [name]
+pragma initial-rule [anime-name]
+pragma export-rule [anime-name]
-[two-name] [first-name] [third-name]
- [second-name] [third-name]
+[anime-two-name] [anime-first-name] [anime-third-name]
+ [anime-second-name] [anime-third-name]
-[name] [first-name] [first-name]
- [first-name] [second-name]
- [second-name] [first-name]
- [second-name] [second-name]
+[anime-three-name] [anime-first-name] [anime-first-name]
+ [anime-first-name] [anime-second-name]
+ [anime-second-name] [anime-first-name]
+ [anime-second-name] [anime-second-name]
-pragma suffix-with [name] [third-name]
+pragma suffix-with [anime-name] [anime-third-name]
-[first-name] Vampire
+[anime-first-name] Vampire
Cat
Death
Mermaid
@@ -40,7 +41,7 @@ pragma suffix-with [name] [third-name]
Lucid
Space
-[second-name] Princess
+[anime-second-name] Princess
Planet
Blade
Bride
@@ -68,7 +69,7 @@ pragma suffix-with [name] [third-name]
Blackout
Phantom
-[third-name] Forever
+[anime-third-name] Forever
Detectives
Memories
Outlaw
diff --git a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/college.gram b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/college.gram
new file mode 100644
index 0000000..f1bee8e
--- /dev/null
+++ b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/college.gram
@@ -0,0 +1,515 @@
+[college-announcement] next [course-time] , [university] will offer ' [college-course] '
+ the [university] class ' [college-course] ' has been cancelled due to lack of interest
+ starting next year, incoming freshmen at [university] will be required to take ' [college-course] '
+ ' [college-course] ' will no longer be offered at [university] due to lack of interest
+ ' [college-course] ' is the most popular [course-level] class at [university]
+ due to overwhelming popularity, an additional section of ' [college-course] ' will be offered at [university] next semester
+ not one single student signed up for [university] 's ' [college-course ' last semester
+ a [poll] of students at [university] revealed ' [college-course] ' is the [popular] popular [class-type] offered
+
+pragma initial-rule [college-announcement]
+
+[course-time] fall
+ year
+ semester
+
+[course-level] graduate
+ undergraduate
+ freshmen
+ liberal arts
+
+[poll] poll
+ survey
+
+[popular] least
+ most
+
+[class-type] class
+ course
+
+pragma range-rule [past-years] 1800 1970
+
+[college-course] [course-adj] [course-noun] [course-suffix]
+ [course-adj] [course-noun] : [course-ending]
+ [course-adj] [course-noun] and [course-adj] [course-noun] [course-suffix]
+ [course-noun] and [course-noun] [course-suffix]
+ [course-group1] [course-group2] [course-life] [course-suffix]
+ [course-group2] [course-noun] [course-life] [course-suffix]
+ [course-group1] [course-group2] [course-life] since [past-years]
+ [course-group2] [course-life] : [course-ending]
+ contemporary [course-group2] [course-life] and [course-life]
+ contemporary [course-group2] [course-life] : [course-ending]
+ transforming the [course-group1] [course-group2] experience
+ [course-prefix] [course-group1] [course-group2] [course-life]
+ [course-prefix] [course-group2] [course-life] [course-suffix]
+ [course-prefix] [course-adj] [course-noun] [course-suffix]
+ [course-prefix] the [course-group1] [course-group2] [course-movement] [course-suffix]
+ [course-adj] [course-life] : [course-ending]
+ [course-adj] [course-noun] in modern [course-medium]
+ [course-noun] [course-suffix] : [course-ending]
+ [course-prefix] [course-noun] and [course-noun] [course-suffix]
+ the [course-adj] dimension of [course-group1] [course-group2] [course-medium]
+ [course-prefix] [course-topic] in [course-group2] [course-medium] : [course-ending]
+ [course-topic] and [course-topic] [course-suffix]
+ [course-group2] [course-medium] interpretation: [course-ending]
+ [course-group2] [course-medium] as a [course-adj] genre
+ [course-prefix] [course-group1] [course-group2] [course-medium]
+ [course-life] of [course-group2] [course-noun] : [course-ending]
+ [course-prefix] [course-popculture] : [course-ending]
+ [course-popculture] [course-suffix] : [course-ending]
+ [course-prefix] [course-adj] [course-noun] and [theory]
+ [course-prefix] [course-action] : [course-ending]
+ [course-action] [course-suffix] : [course-ending]
+ [course-prefix] [course-nounprefix] [course-ancient] [course-medium] : [course-ending]
+ ethnicity [course-suffix] : the [course-group1] [course-group2] [condition]
+ masterpieces of [course-group1] [course-group2] [course-medium]
+ [course-buzzword2] , [course-buzzword2] and [course-buzzword2] [course-suffix] : [course-ending]
+ [course-buzzword2] , [course-buzzword2] and [course-buzzword2] in [course-group2] [course-medium] : [course-ending]
+ [course-prefix] [course-event] : [course-ending]
+ [course-event] as [course-explored] in [course-group1] [course-group2] [course-medium]
+ [university-subject] as [course-explored] in [course-group1] [course-group2] [course-medium]
+ [course-impactof] : [course-ending]
+ [course-static]
+ [course-static]
+
+[condition] condition
+ experience
+
+[course-static] [course-env1] : [course-prefix] [course-env2]
+ [course-prefix] [course-env3] : policy [course-suffix]
+ the meaning of life as [course-explored] in [course-group1] [course-group2] [course-medium]
+ the [course-impact] of [course-group2] [thinker-type] on [course-contemporary] [university-subject] : [course-ending]
+ the [rise] of [course-group2] [thinker-type] in [course-contemporary] [university-subject] : [course-ending]
+ [course-ancient] [course-medium] as the [roots] of [course-contemporary] [university-subject]]
+ [course-buzzword2] , [course-buzzword2] and [course-buzzword2] as [course-explored] in [course-contemporary] [films] : [course-ending]
+ the history of [course-group2] [course-life] : [course-ending]
+ the [archetype] of the [quest] in [course-group1] [course-group2] [course-medium]
+ [cross-cultural] [studies] [course-group2] [course-life]
+
+[course-event] the african diaspora
+ the harlem renaissance
+ the civil rights movement
+ the italian renaissance
+ westward expansion
+ manifest destiny
+ women's suffrage
+ world war I
+ world war II
+ the war of 1812
+ the american revolution
+ the french revolution
+ the russian revolution
+ the american civil war
+ the franco-prussian war
+ the jfk assasination
+
+[thinker-type] researchers
+ thinkers
+ scientists
+
+[rise] rise
+ emergence
+ success
+ empowerment
+
+[roots] roots
+ foundations
+
+[films] film
+ fiction
+ television
+ cinema
+ theater
+
+[archetype] archetype
+ symbolism
+
+[quest] quest paradigm
+ journey
+ awakening
+ rite of passage
+
+[cross-cultural] cross-cultural
+ multi-ethnic
+
+[studies] studies in
+ perspectives on
+[course-env1] saving the world
+ the end of the word
+ the sky is falling
+ here come the mass extinctions
+
+[course-env2] modern enviromentalism
+ enviromental biology
+ enviromental activism
+
+[course-env3] the greenhouse effect
+ planetwide climatic change
+ global warning
+
+[course-action] basketweaving
+ aquatic ballet
+ synchronized swimming
+ professional sports
+ the [course-adj] pottery experience
+ home economics
+ cardplaying
+ [sportship]
+ the culinary [experience]
+
+[sportship] sportspersonship
+ sportsmanship
+
+[experience] arts
+ experience
+
+[course-noun] diversity
+ globalism
+ equality
+ feminism
+ sexuality
+ self-actualization
+ political correctness
+ enviromentalism
+ marxism
+ socialsm
+ communism
+ darwinism
+ activism
+ queer theory
+ [course-nounprefix] romanticism
+ [course-nounprefix] dadaism
+ [course-nounprefix] cubism
+ [course-nounprefix] realism
+ paganism
+ homosexuality
+ sexuality
+ evolution
+ poverty
+ fundamentalism
+ intellectualism
+ multiculturalism
+
+[course-nounprefix] post-
+ pre-
+ early
+ classical
+
+[course-adj] progressive
+ liberal
+ liberal
+ aesthetic
+ postmodern
+ feminist
+ radical
+ populist
+ humanist
+ reformist
+ liberated
+
+[course-prefix] ad-hoc investigation of
+ ad-hoc investigation of
+ the potential of
+ foundations of
+ literature of
+ the history of
+ principles of
+ exploration of
+ philosophy of
+ psychology of
+ meta-physics of
+ dynamic exploration of
+ symbolism of
+ topics in
+ advanced topics in
+ selected topics in
+ special topics in
+ survey of
+ the universe of
+ the meaning of
+ theories of
+ perspectives in
+ topics in
+ special studies in
+ introduction to
+ research capstone in
+ quantitative methods in
+ colloquium in
+ senior seminar in
+ critical perspectives in
+ brief survey of
+ concepts in
+ the highlights of
+
+[course-suffix] in the postmodern era
+ in the postmodern world
+ in the modern adge
+ in modern society
+ in modern america
+ in today's society
+ in the american landscape
+ in the united states
+ in the 21st century
+ in recent times
+ in the real world
+ in the [college-adj] world
+
+[course-ending] ideas in conflict
+ ideas in transition
+ critical issues facing the [course-contemporary] [course-person]
+ a process approach
+ [course-buzzword] , [course-buzzword] and [course-buzzword]
+ a [course-metaphor] of [course-noun] [course-suffix]
+ a [course-metaphor] of [course-ancient] [course-suffix]
+ a [course-metaphor] [course-explored] in american [course-medium]
+ a [course-metaphor] [course-explored] in [course-contemporary] [course-medium]
+ what is to be learned from it?
+ an interdisciplinary [study]
+ from [last-name] to [last-name]
+ [theory] at work
+ policy [course-suffix]
+ different points of view
+ [course-buzzword] and [course-buzzword]
+ the big picture
+ a paradigm shift
+ [modern] [theories]
+ myth and reality
+ the untold story
+ [journey] [discovery]
+
+[modern] modern
+ contemporary
+
+[theories] ideas
+ theories
+
+[journey] a journey of
+ a quest for
+ an odyssey of
+
+[discovery] discovery
+ exploration
+ thought
+ self-actualization
+
+[study] study
+ approach
+
+[course-group1] gay and lesbian
+ homosexual
+ bisexual
+ transgender
+ inner city
+ rural
+ suburban
+ urban
+ southern
+ western
+ eastern
+ liberated
+ upper class
+ middle class
+ [course-adj]
+
+[course-group2] african-american
+ hispanic
+ european
+ latino
+ native american
+ pacific islander
+ australian
+ latvian
+ elbonian
+ italian
+ african
+ american
+ asian
+ chinese
+ japanese
+ french
+ german
+ russian
+ middle eastern
+ scandinavian
+ mexican
+ female
+ female
+ female
+ neo-pagan
+ atheist
+ polytheistic
+ minority
+ multi-ethnic
+
+[course-ancient] roman
+ etruscan
+ greek
+ byzantine
+ mayan
+ incan
+ aztec
+ viking
+ bablyonian
+ egyptian
+ sumerian
+ hittite
+ renaissance
+ chinese
+ native american
+
+[course-life] life
+ literature
+ music
+ art
+ issues
+ perspectives
+ lifestyles
+ thought
+ ethics
+ values
+ landscapes
+ culture
+ society
+ images
+ ideas
+ endeavors
+ expression
+ affairs
+ morals
+ retrospectives
+ symbols
+ religion
+ traditions
+ civilization
+
+[course-metaphor] metaphor
+ study
+ presentation
+ collage
+ figure
+ symbol
+
+[course-explored] explored
+ expressed
+ analyzed
+ interpreted
+ seen
+
+[course-person] individual
+ american
+ person
+ citizen
+ student
+ well-rounded person
+ woman
+ minority
+ liberal
+
+[course-buzzword] understanding
+ understanding
+ analysis
+ synthesis
+ synergy
+ practice
+ the human condition
+ development
+ cross-cultural awareness
+ cross-cultural perspectives
+ evaluation
+ interpretation
+ abstraction
+ decision-making
+ perspectives
+ context
+ paradigms
+ critical thinking
+ relationships
+ discovery
+ empowerment
+
+[course-buzzword2] race
+ class
+ status
+ gender
+ age
+ sex
+ work
+ family
+ community
+ culture
+ politics
+ struggle
+ conflict
+
+[course-movement] movement
+ revolution
+ evolution
+ transformation
+ metamorphosis
+ campaign
+
+[course-medium] art
+ paintings
+ literature
+ folklore
+ mythology
+ poetry
+ sculptures
+ music
+ architecture
+ dance
+ drama
+
+[course-topic] sex
+ death
+ suicide
+ trauma
+ drama
+ life
+ mythology
+ crime
+ love
+ hate
+ anger
+ passion
+ infidelity
+ horror
+
+[course-popculture] 'star wars'
+ 'star trek'
+ cyberpunk literature
+ harlequin romances
+ 'the simpsons'
+ 'the x-files'
+ daytime soap operas
+ radio talk shows
+ shakespeare's [comedy]
+ 'the scarlet letter;
+ 'seinfeld'
+ classic american literature
+ classic [course-ancient] [literature]
+ political cartoons
+ pornography
+ 'the jerry springer show'
+
+[comedy] comedies
+ tragedies
+
+[literature] literature
+ art
+
+[course-contemporary] contemporary
+ modern
+ 21st century
+ 20th century
+
+[course-impactof] the [course-impact] of [course-ancient] [course-medium] on [course-group1] [course-group2] [course-medium] [course-suffix]
+ the [course-impact] of [course-ancient] [course-medium] on [course-contemporary] [university-subject]
+ the [course-impact] of [course-ancient] [course-medium] on [course-contemporary] [course-adj] [course-noun]
+ the [course-impact] of [course-group1] [course-group2] [course-medium] on [course-contemporary] [course-adj] [course-noun]
+ the [course-impact] of [course-group1] [course-group2] [course-medim] on [university-subject]
+
+[course-impact] impact
+ effect
+ consequences
+ influence
diff --git a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/dungeon-enviroment.gram b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/dungeon-enviroment.gram
index 6ac9858..f521125 100755
--- a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/dungeon-enviroment.gram
+++ b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/dungeon-enviroment.gram
@@ -137,4 +137,4 @@ pragma initial-rule [enviroment]
an interrogatin room with a table and chair
an empty classroom
a room whose ceiling is a giant human
- aa room that is constantly swaying
+ a room that is constantly swaying
diff --git a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/insults.gram b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/insults.gram
new file mode 100644
index 0000000..1b3881b
--- /dev/null
+++ b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/insults.gram
@@ -0,0 +1,156 @@
+[insult] Thou [insult-1] [insult2] [insult3]!
+
+pragma initial-rule [insult]
+
+[insult-1] artless
+ bawdy
+ beslubbering
+ bootless
+ churlish
+ cockered
+ clouted
+ craven
+ currish
+ dankish
+ dissembling
+ droning
+ errant
+ fawning
+ fobbing
+ froward
+ frothy
+ gleeking
+ goatish
+ gorbellied
+ impertinent
+ infectious
+ jarring
+ loggerheaded
+ lumpish
+ mammering
+ mangled
+ mewling
+ paunchy
+ pribbling
+ puking
+ puny
+ qualling
+ rank
+ reeky
+ roguish
+ ruttish
+ saucy
+ spleeny
+ spongy
+ surly
+ tottering
+ unmuzzled
+ vain
+ venomed
+ villainous
+ warped
+ wayward
+ weedy
+ yeasty
+
+[insult-2] base-court
+ bat-fowling
+ beef-witted
+ beetle-headed
+ boil-brained
+ clapper-clawed
+ clay-brained
+ common-kissing
+ crook-pated
+ dismal-dreaming
+ dizzy-eyed
+ doghearted
+ dread-bolted
+ earth-vexing
+ elf-skinned
+ fat-kidneyed
+ fen-sucked
+ flap-mouthed
+ fly-bitten
+ folly-fallen
+ fool-born
+ full-gorged
+ guts-griping
+ half-faced
+ hasty-witted
+ hedge-born
+ hell-hated
+ idle-headed
+ ill-breeding
+ ill-nurtured
+ knotty-pated
+ milk-livered
+ motley-minded
+ onion-eyed
+ plume-plucked
+ pottle-deep
+ pox-marked
+ reeling-ripe
+ rough-hewn
+ rude-growing
+ rump-fed
+ shard-borne
+ sheep-biting
+ spur-galled
+ swag-bellied
+ tardy-gaited
+ tickle-brained
+ toad-spotted
+ unchin-snouted
+ weather-bitten
+
+[insults-3] apple-john
+ baggage
+ barnacle
+ bladder
+ boar-pig
+ bugbear
+ bum-bailey
+ canker-blossom
+ clack-dish
+ clotpole
+ coxcomb
+ codpiece
+ death-token
+ dewberry
+ flap-dragon
+ flax-wench
+ flirt-gill
+ foot-licker
+ fustilarian
+ giglet
+ gudgeon
+ haggard
+ harpy
+ hedge-pig
+ horn-beast
+ hugger-mugger
+ joithead
+ lewdster
+ lout
+ maggot-pie
+ malt-worm
+ mammet
+ measle
+ minnow
+ miscreant
+ moldwarp
+ mumble-news
+ nut-hook
+ pigeon-egg
+ pignut
+ puttock
+ pumpion
+ ratsbane
+ scut
+ skainsmate
+ strumpet
+ varlet
+ vassal
+ whey-face
+ wagtail
diff --git a/RGens/src/main/java/bjc/RGens/parser/sample-grammars/mission.gram b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/mission.gram
new file mode 100644
index 0000000..9dce28a
--- /dev/null
+++ b/RGens/src/main/java/bjc/RGens/parser/sample-grammars/mission.gram
@@ -0,0 +1,461 @@
+[mission-statement] [opening] [work-phrase] [verb-part] [noun-part]
+ [opening] [work-phrase2] [verb-part2] [noun-part]
+ [opening] [verb-part] [noun-part]
+ [opening] [work-phrase] [verb-part] [noun-part] and [verb-part] [noun-part]
+ [opening] [work-phrase2] [verb-part2] [noun-part] and [verb-part2] [noun-part]
+ [opening] [verb-part] [noun-part] and [noun-part]
+ [opening] [work-phrase] [verb-part] [noun-part] [connector] [goal]
+ [opening] [work-phrase2] [verb-part2] [noun-part] [connector] [goal]
+ [opening] [verb-part] [noun-part] [connector] [goal]
+ [opening] [work-phrase] [verb-part] [noun-part] [connector] [goal] and [goal]
+ [opening] [work-phrase2] [verb-part2] [noun-part] [connector] [goal] and [goal]
+ [opening] [verb-part] [noun-part] [connector] [goal] and [goal]
+ [opening] [work-phrase] [verb-part] [noun-part] and [verb-part] [noun-part] [connector] [goal]
+ [opening] [work-phrase2] [verb-part2] [noun-part] and [verb-part2] [noun-part] [connector] [goal]
+ [opening] [verb-part] [noun-part] and [noun-part] [connector] [goal]
+ [opening] [verb-part] [noun-part], [noun-part] and [noun-part] [connector] [goal]
+ [opening] [work-phrase] [verb-part] [noun-part] [connector] [verb-part] [noun-part] [connector] [goal]
+ [opening] [work-phrase2] [verb-part2] [noun-part] [connector] [verb-part] [noun-part] [connector] [goal]
+ [opening] [verb-part] [noun-part] [connector] [verb-part] [noun-part] [connector] [goal]
+
+pragma initial-rule [mission-statement]
+
+[verb-part] [verb-how] [verb]
+ [verb]
+
+[verb-part2] [verb-how] [verb-gerund]
+ [verb-gerund]
+
+[noun-part] our [adjective] [noun]
+ our [noun]
+ our [noun-prefix] [noun]
+ [adjective] [noun-prefix] [noun]
+ [adjective] [noun]
+ [noun]
+
+[opening] it's our [duty] to
+ it is our [duty] to
+ it is our [mission] to
+ it's our [mission] to
+ our [mission] is to
+ our [duty] is
+ we are committed to
+ we have committed to
+ we
+ we resolve to
+
+[duty] duty
+ responsibility
+ obligation
+
+[mission] mission
+ task
+ goal
+ job
+ business
+ function
+
+[verb] aggregate
+ deliver
+ deploy
+ embrace
+ empower
+ enable
+ engage
+ engineer
+ enhance
+ envision
+ extend
+ facilitate
+ generate
+ harness
+ implement
+ innovate
+ integrate
+ leverage
+ maximize
+ optimize
+ reinvent
+ revolutionize
+ simplify
+ spearhead
+ strategize
+ streamline
+ syndicate
+ synergize
+ synthesize
+ transform
+ unleash
+ utilize
+ visualize
+
+[verb-gerund] aggregating
+ delivering
+ deploying
+ embracing
+ empowering
+ enabling
+ engaging
+ engineering
+ enhancing
+ envisioning
+ extending
+ facilitating
+ generating
+ harnessing
+ implementing
+ innovating
+ integrating
+ leveraging
+ maximizing
+ optimizing
+ reinventing
+ revolutionizing
+ simplifying
+ spearheading
+ strategizing
+ streamlining
+ syndicating
+ synergizing
+ synthesizing
+ transforming
+ unleashing
+ utilizing
+ visualizing
+
+[verb-how] dramatically
+ practically
+ conveniently
+ efficiently
+ productively
+ rapidly
+ enthusiastically
+ completely
+ competently
+ assertively
+ quickly
+ intelligently
+ endlessly
+ tirelessly
+ effectively
+ skillfully
+ proficiently
+ professionally
+ swiftly
+ energetically
+ vigorously
+ zealously
+ briskly
+ speedily
+ shrewdly
+ cleverly
+ sharply
+ astutely
+ successfully
+ expertly
+
+[work-phrase] strive to
+ work to
+ endeavor to
+ continue to
+ execute a strategic plan to
+
+[work-phrase2] strive towards
+ work towards
+ endeavor towards
+ continue towards
+ make progress towards
+ make strides towards
+ take steps towards
+ achieve progress in
+ engage in
+ execute a strategic plan involving
+
+[noun] action items
+ architectures
+ assets
+ bandwidth
+ channels
+ communities
+ content
+ deliverables
+ eyeballs
+ face time
+ functionalities
+ infomediaries
+ infrastructures
+ initiatives
+ interfaces
+ key players
+ leadership skills
+ markets
+ metrics
+ middleware
+ mindshare
+ perspectives
+ networks
+ niches
+ paradigms
+ partnerships
+ platforms
+ portals
+ relationship corridors
+ relationships
+ synergies
+ schemas
+ skill sets
+ solutions
+ strategic alliances
+ supply-chains
+ synergies
+ technologies
+ total quality management
+ version control
+ vision
+ catalysts for [noun]
+
+[noun-prefix] sub-
+ meta-
+ mega-
+ e-
+ E-
+ cyber-
+ Net-
+
+[adjective] best-of-breed
+ bilateral
+ bleeding-edge
+ client-centered
+ cross-platform
+ cross-media
+ customer-centric
+ cutting-edge
+ distributed
+ dot-com
+ dynamic
+ effective
+ efficient
+ effort-intensive
+ enterprise
+ evolutionary
+ extensible
+ forward-thinking
+ frictionless
+ future-proof
+ global
+ granular
+ hyperlinked
+ idiot-proof
+ innovative
+ integrated
+ interactive
+ intuitive
+ killer
+ leading-edge
+ legacy
+ massively-parallel
+ mission-critical
+ multilevel
+ next-generation
+ object-oriented
+ open-source
+ proactive
+ progressive
+ real-time
+ revolutionary
+ robust
+ scalable
+ seamless
+ strategic
+ synergistic
+ transparent
+ turn-key
+ two-tier
+ ubiquitous
+ user-centric
+ value-added
+ vertical
+ viral
+ virtual
+ visionary
+ wireless
+ world-class
+
+[connector] so that we may
+ in order to
+ as part of our master plan to
+ as part of a larger strategy to
+ to
+ to
+ in order that we may
+ to allow us to
+ to enable us to
+ to permit us to
+ so that hopefully we may
+ as part of our five-year plan to
+ as part of our business plan to
+ as a component of our plan to
+ as the first step in our scheme to
+
+[goal] [make] a lot of [money]
+ produce [profit] for our [shareholders]
+ produce more [profit] for our [shareholders]
+ [increase] [profit] for our [shareholders]
+ better serve our customers
+ better serve our [shareholders]
+ better serve the [world]
+ [increase] our [bottom-line]
+ get out of debt
+ prevent bankruptcy
+ stay competitive for [todays] [world]
+ remain profitable in [todays] [world]
+ [set-us-apart] [competition]
+ [defeat] [competition]
+ [increase] customer satisfaction
+ create a [better] [product]
+ market a [lesser] [product]
+ produce a [better] [product] that kicks [competition] 's [butt]
+ market a [lesser] [product] that [make] s us a lot of [money]
+ exceed customer [demands]
+ meet the [demands] of our valued customers
+ meet the [demands] of the [world]
+ successfully market an overhyped [lesser] [product]
+ take over the [world]
+ dominate the [world]
+ waste a lot of time in meetings
+ make our founder enough [money] to exceed the net worth of the world's richest man
+
+[demands] demands
+ expectations
+ wants
+ needs
+ requirements
+
+[product] product
+ product line
+ line of products
+ line of services
+ brand
+
+[better] better
+ superior
+ finer
+ more affordable
+ quality
+ higher quality
+ popular
+ robust
+
+[lesser] lesser
+ highly inferior
+ subpar
+ worse
+ more expensive
+ weak
+ lower quality
+ poor
+
+[make] make
+ earn
+ produce
+ create
+ yield
+
+[defeat] defeat
+ counter
+ challenge
+ beat
+ strike back at
+ conquer
+ crush
+ shellac
+ rout
+ vanquish
+ reign victorious over
+ overwhelm
+ beat the snot out of
+
+[competition] the competition
+ our competitors
+ the rest of the industry
+ our evil competitors
+ the market
+ the industry
+ our enemies
+
+[set-us-apart] set us apart from
+ pull ahead from
+ distance us from
+ take us ahead of
+
+[todays] today's
+ tomorrow's
+ the future
+
+[shareholders] shareholders
+ employees
+ executive officers
+ head honchos
+ workers
+ serfs
+ investors
+ venture capitalists
+ sponsors
+
+[increase] increase
+ shore up
+ inflate
+ enlarge
+ enrich
+ add to
+ augment
+ advance
+ expand
+ burgeon
+ grow
+ multiply
+ make greater
+
+[profit] profit
+ dividends
+ cash
+ money
+ revenue
+ income
+ earnings
+ proceeds
+ rewards
+ benefits
+
+[money] money
+ cash
+ currency
+ moola
+ greenbacks
+ dough
+ bread
+ scratch
+ bucks
+ simoleons
+
+[world] world
+ industry
+ globe
+ universe
+ nation
+ country
+ market
+ economy
+
+[butt] butt
+ ass
+ rear end
+ posterior
+ behind
+
+[bottom-line] bottom line
+ stock price
+ net worth
+ earnings
+ revenue
+ sales
diff --git a/RGens/src/main/java/bjc/RGens/server/GrammarServer.java b/RGens/src/main/java/bjc/RGens/server/GrammarServer.java
new file mode 100644
index 0000000..3efe6a3
--- /dev/null
+++ b/RGens/src/main/java/bjc/RGens/server/GrammarServer.java
@@ -0,0 +1,188 @@
+package bjc.RGens.server;
+
+import bjc.utils.funcdata.FunctionalMap;
+import bjc.utils.funcdata.IMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcutils.ListUtils;
+import bjc.utils.gen.WeightedGrammar;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.FileInputStream;
+
+import java.util.Scanner;
+import java.util.function.Supplier;
+
+public class GrammarServer {
+ private Scanner scn;
+
+ public final IMap<String, WeightedGrammar<String>> loadedGrammars;
+
+ public final IMap<String, WeightedGrammar<String>> exportedRules;
+
+ public GrammarServer(Scanner scn) {
+ this.scn = scn;
+
+ this.loadedGrammars = new FunctionalMap<>();
+ this.exportedRules = new FunctionalMap<>();
+
+ ServerGrammarReader.setExportedRules(exportedRules);
+ }
+
+ public static void main(String[] args) {
+ System.out.println("GrammarServer 1.0");
+
+ Scanner scn = new Scanner(System.in);
+
+ GrammarServer serv = new GrammarServer(scn);
+
+ System.out.print("Enter a command (m for help): ");
+
+ char comm = scn.nextLine().charAt(0);
+
+ while(comm != 'e') {
+ switch(comm) {
+ case 'm':
+ System.out.println("GrammarServer Commands:");
+ System.out.println("\tm: Print command help");
+ System.out.println("\te: Exit GrammarServer");
+ System.out.println("\tl: Load grammar from file");
+ System.out.println("\ts: Show loaded grammars");
+ System.out.println("\tg: Generate text");
+ break;
+ case 'g':
+ serv.generateText();
+ break;
+ case 's':
+ // @TODO expand to general show stuff method
+ System.out.printf("Currently loaded grammars (%d total):\n",
+ serv.loadedGrammars.getSize());
+
+ serv.loadedGrammars.forEachKey(key -> {
+ System.out.println("\t" + key);
+ });
+
+ break;
+ case 'l':
+ serv.loadGrammar();
+ break;
+ default:
+ System.out.println("? Unrecognized Command");
+ }
+
+ System.out.print("Enter a command (m for help): ");
+
+ comm = scn.nextLine().charAt(0);
+ }
+
+ System.out.println("GrammarServer exiting");
+ }
+
+ private void generateText() {
+ System.out.println("Entering Generate Mode");
+
+ System.out.print("(Generate Mode) Enter a command (m for help): ");
+
+ char comm = scn.nextLine().charAt(0);
+
+ while(comm != 'e') {
+ switch(comm) {
+ case 'm':
+ System.out.println("GrammarServer Generate Mode Commands: ");
+ System.out.println("\tm: Show command help");
+ System.out.println("\tx: Generate from exported rules");
+ System.out.println("\te: Exit Generate Mode");
+ break;
+ case 'x':
+ System.out.print("Enter the name of the rule to generate"
+ + " (l to list, enter to cancel): ");
+
+ String ruleName = scn.nextLine().trim();
+
+ while(true) {
+ if(ruleName.equals("")) break;
+
+ if(ruleName.equals("l")) {
+ System.out.println("Current exported rules: ");
+ exportedRules.forEachKey(key -> {
+ System.out.println("\t" + key);
+ });
+ } else if (exportedRules.containsKey(ruleName)) {
+ String ruleResult = ListUtils.collapseTokens(
+ exportedRules.get(ruleName)
+ .generateListValues(ruleName, " "));
+
+ System.out.println("Generated Result: ");
+ System.out.println(ruleResult.replaceAll("\\s+", " "));
+
+ System.out.println("Generate again from this rule? (yes/no)");
+
+ String resp = scn.nextLine().trim();
+
+ if(resp.equalsIgnoreCase("yes")) {
+ continue;
+ }
+ } else {
+ System.out.println("? Unrecognized external rule");
+ }
+
+ System.out.print("Enter the name of the rule to generate"
+ + " (l to list, enter to cancel): ");
+
+ ruleName = scn.nextLine().trim();
+ }
+ break;
+ default:
+ System.out.println("? Unrecognized command");
+ }
+
+ System.out.print("(Generate Mode) Enter a command (m for help): ");
+
+ comm = scn.nextLine().charAt(0);
+ }
+
+ System.out.println("Exiting Generate Mode");
+ }
+
+ private void loadGrammar() {
+ System.out.print("Enter path to load grammar from: ");
+
+ String grammarPath = scn.nextLine().trim();
+
+ File grammarFile = new File(grammarPath);
+
+ String grammarName = grammarFile.getName().trim();
+
+ grammarName = grammarName.substring(0, grammarName.lastIndexOf("."));
+
+ System.out.printf("Enter grammar name or press enter for"
+ + " the default (%s): ", grammarName);
+
+ String inputName = scn.nextLine();
+
+ if(!inputName.equals("")) {
+ grammarName = inputName;
+ }
+
+ System.out.printf("Loading grammar (named %s) from path %s\n",
+ grammarName, grammarPath);
+
+ try (FileInputStream inputStream = new FileInputStream(grammarPath)) {
+ WeightedGrammar<String> newGram =
+ ServerGrammarReader.fromStream(inputStream).merge((gram, exports) -> {
+ for(String export : exports.toIterable()) {
+ exportedRules.put(export, gram);
+ }
+
+ return gram;
+ });
+
+ loadedGrammars.put(grammarName, newGram);
+ } catch (IOException ioex) {
+ System.out.printf("? Error reading grammar from file"
+ + " (reason: %s)", ioex.getMessage());
+ }
+
+ return;
+ }
+}
diff --git a/RGens/src/main/java/bjc/RGens/server/ReaderState.java b/RGens/src/main/java/bjc/RGens/server/ReaderState.java
new file mode 100644
index 0000000..9285f7b
--- /dev/null
+++ b/RGens/src/main/java/bjc/RGens/server/ReaderState.java
@@ -0,0 +1,184 @@
+package bjc.RGens.server;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Stack;
+import java.util.function.Supplier;
+
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.IList;
+import bjc.utils.gen.WeightedGrammar;
+
+/**
+ * Represents the internal state of reader
+ *
+ * @author ben
+ *
+ */
+public class ReaderState {
+ private WeightedGrammar<String> currentGrammar;
+ private String currentRule;
+ private boolean isUniform;
+
+ private IList<String> exports;
+
+ /**
+ * Create a new reader state
+ */
+ public ReaderState() {
+ currentGrammar = new WeightedGrammar<>();
+
+ // Grammars start out uniform
+ isUniform = true;
+
+ exports = new FunctionalList<>();
+ }
+
+ public void addExport(String export) {
+ exports.add(export);
+ }
+
+ public IList<String> getExports() {
+ return exports;
+ }
+
+ /**
+ * Get the rule names for the current grammar
+ *
+ * @return The rule names for the current grammar
+ */
+ public IList<String> getRuleNames() {
+ return currentGrammar.getRuleNames();
+ }
+
+ /**
+ * Check if this reader is currently in uniform mode
+ *
+ * @return Whether this grammar is in uniform mode
+ */
+ public boolean isUniform() {
+ return isUniform;
+ }
+
+ /**
+ * Set the current grammar to be the specified one
+ *
+ * @param newWorkingGrammar
+ * The new grammar to use
+ */
+ public void setCurrentGrammar(WeightedGrammar<String> newWorkingGrammar) {
+ currentGrammar = newWorkingGrammar;
+ }
+
+ /**
+ * Set the rule currently being worked on
+ *
+ * @param ruleName
+ * The rule currently being worked on
+ */
+ public void setCurrentRule(String ruleName) {
+ currentRule = ruleName;
+ }
+
+ /**
+ * Set the initial rule of this grammar
+ *
+ * @param ruleName
+ * The initial rule of this grammar
+ */
+ public void setInitialRule(String ruleName) {
+ currentGrammar.setInitialRule(ruleName);
+ }
+
+ /**
+ * Toggle this uniformity setting for this grammar
+ */
+ public void toggleUniformity() {
+ isUniform = !isUniform;
+ }
+
+ /**
+ * Add a case to the current grammar
+ *
+ * @param ruleProbability
+ * The probability for this case to occur
+ * @param ruleParts
+ * The parts that make up this case
+ */
+ public void addCase(int ruleProbability, IList<String> ruleParts) {
+ currentGrammar.addCase(currentRule, ruleProbability, ruleParts);
+ }
+
+ /**
+ * Add a special rule to the grammar
+ *
+ * @param ruleName The name of the special rule
+ * @param cse The special case for the rule
+ */
+ public void addSpecialRule(String ruleName, Supplier<IList<String>> cse) {
+ currentGrammar.addSpecialRule(ruleName, cse);
+ }
+
+ /**
+ * Start editing a new rule in the current grammar
+ *
+ * @param ruleName
+ * The name of the new rule to edit
+ */
+ public void startNewRule(String ruleName) {
+ currentGrammar.addRule(ruleName);
+
+ currentRule = ruleName;
+ }
+
+ /**
+ * Convert this package of state into a weighted grammar
+ *
+ * @return The grammar represented by this state
+ */
+ public WeightedGrammar<String> getGrammar() {
+ return currentGrammar;
+ }
+
+ /**
+ * Prefix a token onto all of the cases for the specified rule
+ *
+ * @param ruleName
+ * The rule to do prefixing on
+ * @param prefixToken
+ * The token to prefix onto each case
+ * @param additionalProbability
+ * The probability modification of the prefixed cases
+ */
+ public void prefixRule(String ruleName, String prefixToken,
+ int additionalProbability) {
+ currentGrammar.prefixRule(ruleName, prefixToken,
+ additionalProbability);
+ }
+
+ /**
+ * Delete a rule from the current grammar
+ *
+ * @param ruleName
+ * The name of the rule to delete
+ */
+ public void deleteRule(String ruleName) {
+ currentGrammar.deleteRule(ruleName);
+ }
+
+ /**
+ * Suffix a token onto all of the cases for the specified rule
+ *
+ * @param ruleName
+ * The rule to do suffixing on
+ * @param suffixToken
+ * The token to suffix onto each case
+ * @param additionalProbability
+ * The probability modification of the suffixed cases
+ */
+ public void suffixRule(String ruleName, String suffixToken,
+ int additionalProbability) {
+ currentGrammar.suffixRule(ruleName, suffixToken,
+ additionalProbability);
+ }
+}
diff --git a/RGens/src/main/java/bjc/RGens/server/ServerGrammarReader.java b/RGens/src/main/java/bjc/RGens/server/ServerGrammarReader.java
new file mode 100644
index 0000000..e59a225
--- /dev/null
+++ b/RGens/src/main/java/bjc/RGens/server/ServerGrammarReader.java
@@ -0,0 +1,261 @@
+package bjc.RGens.server;
+
+import com.mifmif.common.regex.Generex;
+
+import java.io.InputStream;
+import java.util.Random;
+import java.util.function.BiFunction;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+import bjc.utils.data.IPair;
+import bjc.utils.data.Pair;
+import bjc.utils.funcdata.FunctionalStringTokenizer;
+import bjc.utils.funcdata.FunctionalList;
+import bjc.utils.funcdata.FunctionalMap;
+import bjc.utils.funcdata.IList;
+import bjc.utils.funcdata.IMap;
+import bjc.utils.funcutils.ListUtils;
+import bjc.utils.gen.WeightedGrammar;
+import bjc.utils.parserutils.RuleBasedConfigReader;
+
+/**
+ * Read a grammar from a stream
+ *
+ * @author ben
+ *
+ */
+public class ServerGrammarReader {
+ private static RuleBasedConfigReader<ReaderState> reader;
+
+ private static Random numgen = new Random();
+
+ private static IMap<String, WeightedGrammar<String>> exportedRules;
+
+ public static void setExportedRules(IMap<String, WeightedGrammar<String>> rules) {
+ exportedRules = rules;
+ }
+
+ static {
+ setupReader();
+
+ initPragmas();
+ }
+
+ private static void debugGrammar(ReaderState state) {
+ System.out.println("Printing rule names: ");
+
+ for (String currentRule : state.getRuleNames().toIterable()) {
+ System.out.println("\t" + currentRule);
+ }
+
+ System.out.println();
+ }
+
+ private static void doCase(FunctionalStringTokenizer tokenizer, ReaderState state) {
+ int ruleProbability = readOptionalProbability(tokenizer, state);
+
+ state.addCase(ruleProbability, tokenizer.toList());
+ }
+
+ /**
+ * Read a grammar from a stream
+ *
+ * @param inputStream
+ * The stream to load the grammar from
+ *
+ * @return A grammar read from the stream
+ *
+ */
+ public static IPair<WeightedGrammar<String>, IList<String>>
+ fromStream(InputStream inputStream) {
+ ReaderState initialState = new ReaderState();
+
+ WeightedGrammar<String> gram = reader.fromStream(inputStream, initialState).getGrammar();
+
+ IMap<String, IList<String>> vars = new FunctionalMap<>();
+
+ Predicate<String> specialPredicate = (strang) -> {
+ if(strang.matches("\\{\\S+\\}") || strang.matches("\\[\\S+\\}")) {
+ return true;
+ }
+
+ return false;
+ };
+
+ BiFunction<String, WeightedGrammar<String>, IList<String>>
+ specialAction = (strang, gramm) -> {
+ IList<String> retList = new FunctionalList<>();
+
+ if(strang.matches("\\{\\S+\\}")) {
+ if(strang.matches("\\{\\S+:=\\S+\\}")) {
+ String[] varParts = strang.split(":=");
+
+ String varName = varParts[0].substring(1);
+ String ruleName = varParts[1].substring(0, varParts[1].length());
+
+ IList<String> varValue = gramm.generateGenericValues(
+ ruleName, (s) -> s, " ");
+
+ vars.put(varName, varValue);
+ } else if(strang.matches("\\{\\S+=\\S+\\}")) {
+ String[] varParts = strang.split("=");
+
+ String varName = varParts[0].substring(1);
+ String varValue = varParts[1].substring(0, varParts[1].length());
+
+ vars.put(varName, new FunctionalList<>(varValue));
+ } else {
+ // @FIXME notify the user they did something wrong
+ retList.add(strang);
+ }
+ } else {
+ if(strang.matches("\\[\\$\\S+\\]")) {
+ String varName = strang.substring(2, strang.length());
+
+ retList = vars.get(varName);
+ } else if(strang.matches("\\[\\$\\S+\\-\\S+\\]")) {
+ String[] varParts = strang.substring(1, strang.length()).split("-");
+
+ StringBuilder actualName = new StringBuilder("[");
+
+ for(String varPart : varParts) {
+ if(varPart.startsWith("$")) {
+ IList<String> varName = vars.get(varPart.substring(1));
+
+ if(varName.getSize() != 1) {
+ // @FIXME notify the user they did something wrong
+ }
+
+ actualName.append(varName.first() + "-");
+ } else {
+ actualName.append(varPart + "-");
+ }
+ }
+
+ // Trim trailing -
+ actualName.deleteCharAt(actualName.length() - 1);
+ actualName.append("]");
+
+ retList = gramm.generateGenericValues(actualName.toString(), (s) -> s, " ");
+ } else if (exportedRules.containsKey(strang)) {
+ return exportedRules.get(strang)
+ .generateGenericValues(strang, (s) -> s, " ");
+ } else {
+ // @FIXME notify the user they did something wrong
+ retList.add(strang);
+ }
+ }
+
+ return retList;
+ };
+
+ gram.configureSpecial(specialPredicate, specialAction);
+
+ return new Pair<>(gram, initialState.getExports());
+ }
+
+ private static void initialRule(FunctionalStringTokenizer tokenizer, ReaderState state) {
+ String initialRuleName = tokenizer.nextToken();
+
+ state.setInitialRule(initialRuleName);
+ }
+
+ private static void initPragmas() {
+ reader.addPragma("debug", (tokenizer, state) -> {
+ debugGrammar(state);
+ });
+
+ reader.addPragma("uniform", (tokenizer, state) -> {
+ state.toggleUniformity();
+ });
+
+ reader.addPragma("initial-rule", ServerGrammarReader::initialRule);
+
+ reader.addPragma("remove-rule", ServerGrammarReader::removeRule);
+
+ reader.addPragma("prefix-with", ServerGrammarReader::prefixRule);
+ reader.addPragma("suffix-with", ServerGrammarReader::suffixRule);
+
+ reader.addPragma("regex-rule", (tokenizer, state) -> {
+ String ruleName = tokenizer.nextToken();
+
+ IList<String> regx = tokenizer.toList();
+ Generex regex = new Generex(ListUtils.collapseTokens(regx));
+
+ state.addSpecialRule(ruleName, () -> {
+ return new FunctionalList<>(regex.random().split(" "));
+ });
+ });
+
+ reader.addPragma("range-rule", (tokenizer, state) -> {
+ String ruleName = tokenizer.nextToken();
+
+ int start = Integer.parseInt(tokenizer.nextToken());
+ int end = Integer.parseInt(tokenizer.nextToken());
+
+ state.addSpecialRule(ruleName, () -> {
+ return new FunctionalList<>(Integer.toString(
+ numgen.nextInt((end - start) + 1) + start));
+ });
+ });
+
+ reader.addPragma("export-rule", (tokenizer, state) -> {
+ String ruleName = tokenizer.nextToken();
+
+ state.addExport(ruleName);
+ });
+ }
+
+ private static void prefixRule(FunctionalStringTokenizer tokenizer, ReaderState state) {
+ String ruleName = tokenizer.nextToken();
+ String prefixToken = tokenizer.nextToken();
+
+ int additionalProbability = readOptionalProbability(tokenizer, state);
+
+ state.prefixRule(ruleName, prefixToken, additionalProbability);
+ }
+
+ private static int readOptionalProbability(FunctionalStringTokenizer tokenizer, ReaderState state) {
+ if (state.isUniform()) {
+ return 0;
+ }
+
+ return Integer.parseInt(tokenizer.nextToken());
+ }
+
+ private static void removeRule(FunctionalStringTokenizer tokenizer, ReaderState state) {
+ String ruleName = tokenizer.nextToken();
+
+ state.deleteRule(ruleName);
+ }
+
+ private static void setupReader() {
+ reader = new RuleBasedConfigReader<>(null, null, null);
+
+ reader.setStartRule((tokenizer, stateTokenPair) -> {
+ stateTokenPair.doWith((initToken, state) -> {
+ state.startNewRule(initToken);
+
+ doCase(tokenizer, state);
+ });
+ });
+
+ reader.setContinueRule((tokenizer, state) -> {
+ doCase(tokenizer, state);
+ });
+
+ reader.setEndRule((tokenizer) -> {
+ tokenizer.setCurrentRule(null);
+ });
+ }
+
+ private static void suffixRule(FunctionalStringTokenizer tokenizer, ReaderState state) {
+ String ruleName = tokenizer.nextToken();
+ String suffixToken = tokenizer.nextToken();
+
+ int additionalProbability = readOptionalProbability(tokenizer, state);
+
+ state.suffixRule(ruleName, suffixToken, additionalProbability);
+ }
+}