• R/O
  • SSH
  • HTTPS

nina: Commit


Commit MetaInfo

Revision669 (tree)
Time2018-05-12 06:09:24
Authory-moriguchi

Log Message

supports states which skips spaces

Change Summary

Incremental Difference

--- nina/java/src/net/morilib/nina/DFABuilder.java (revision 668)
+++ nina/java/src/net/morilib/nina/DFABuilder.java (revision 669)
@@ -232,6 +232,8 @@
232232
233233 Collection<DBS> identical = null;
234234
235+ boolean skipSpaces;
236+
235237 private Range allRange = null;
236238
237239 private void _linkRange(DBS d, Range o, Interval r, Object m) {
@@ -500,6 +502,10 @@
500502 edges == null && recursive == null && dynamic == null);
501503 }
502504
505+ public boolean isSkipSpaces() {
506+ return skipSpaces;
507+ }
508+
503509 @Override
504510 public boolean isAccepted() {
505511 return accepted;
@@ -1006,7 +1012,7 @@
10061012 quoted = quoted.replaceAll("/", "\\\\/");
10071013 } else {
10081014 quoted = quoted.replaceFirst("^/", "\\\\/");
1009- quoted = quoted.replaceFirst("^([^/]+)/$", "\\1\\\\/");
1015+ quoted = quoted.replaceFirst("^([^/]+)/$", "$1\\\\/");
10101016 }
10111017 b = DoubleQuoteTokenizer.parse(quoted);
10121018 for(DoubleQuoteTokenizer.Elems p : b) {
@@ -2001,7 +2007,15 @@
20012007 vertex.accepted = accept;
20022008 }
20032009
2010+ /* (non-Javadoc)
2011+ * @see net.morilib.nina.NinaAction#setSkipSpaces(boolean)
2012+ */
20042013 @Override
2014+ public void setSkipSpaces(boolean skipSpaces) {
2015+ vertex.skipSpaces = skipSpaces;
2016+ }
2017+
2018+ @Override
20052019 public void setEdgeDynamic(NinaEvent q, String var) {
20062020 q.setEdge(new DY(var));
20072021 dynmap.put(var, var);
--- nina/java/src/net/morilib/nina/MarkovBuilder.java (revision 668)
+++ nina/java/src/net/morilib/nina/MarkovBuilder.java (revision 669)
@@ -394,6 +394,14 @@
394394 }
395395
396396 /* (non-Javadoc)
397+ * @see net.morilib.nina.NinaAction#setSkipSpaces(boolean)
398+ */
399+ @Override
400+ public void setSkipSpaces(boolean skipSpaces) {
401+ throw new NinaException("isnotdfa");
402+ }
403+
404+ /* (non-Javadoc)
397405 * @see net.morilib.nina.NinaAction#setEdgeDynamic(net.morilib.nina.NinaEvent, java.lang.String)
398406 */
399407 @Override
--- nina/java/src/net/morilib/nina/MarkovChainBuilder.java (revision 668)
+++ nina/java/src/net/morilib/nina/MarkovChainBuilder.java (revision 669)
@@ -407,6 +407,14 @@
407407 }
408408
409409 /* (non-Javadoc)
410+ * @see net.morilib.nina.NinaAction#setSkipSpaces(boolean)
411+ */
412+ @Override
413+ public void setSkipSpaces(boolean skipSpaces) {
414+ throw new NinaException("isnotdfa");
415+ }
416+
417+ /* (non-Javadoc)
410418 * @see net.morilib.nina.NinaAction#setEdgeDynamic(net.morilib.nina.NinaEvent, java.lang.String)
411419 */
412420 @Override
--- nina/java/src/net/morilib/nina/NFABuilder.java (revision 668)
+++ nina/java/src/net/morilib/nina/NFABuilder.java (revision 669)
@@ -439,6 +439,14 @@
439439 }
440440
441441 /* (non-Javadoc)
442+ * @see net.morilib.nina.NinaAction#setSkipSpaces(boolean)
443+ */
444+ @Override
445+ public void setSkipSpaces(boolean skipSpaces) {
446+ throw new NinaException("isnotdfa");
447+ }
448+
449+ /* (non-Javadoc)
442450 * @see net.morilib.nina.NinaAction#setEdgeDynamic(net.morilib.nina.NinaEvent, java.lang.String)
443451 */
444452 @Override
--- nina/java/src/net/morilib/nina/NinaAction.java (revision 668)
+++ nina/java/src/net/morilib/nina/NinaAction.java (revision 669)
@@ -271,6 +271,12 @@
271271
272272 /**
273273 *
274+ * @param skipSpace
275+ */
276+ public void setSkipSpaces(boolean skipSpace);
277+
278+ /**
279+ *
274280 * @param q
275281 * @param name
276282 */
--- nina/java/src/net/morilib/nina/NinaParser.java (revision 668)
+++ nina/java/src/net/morilib/nina/NinaParser.java (revision 669)
@@ -1489,7 +1489,7 @@
14891489 }
14901490 break;
14911491 case FI_W2:
1492- if(q.isFrameBefore() || q.isFrame() ||
1492+ if(q.get() == 's' || q.isFrameBefore() || q.isFrame() ||
14931493 q.isArrow() || q.isEntry() || q.isDone()) {
14941494 q.transformFrame();
14951495 q.setScratch2(_FRAME1);
@@ -1772,8 +1772,11 @@
17721772 break;
17731773 case FM_W:
17741774 q.setScratch(action.getVertex());
1775- if(q.isFrame() || q.isArrow() || q.isEntry()) {
1775+ if(q.isFrameSkip()) {
1776+ action.setSkipSpaces(true);
17761777 q.west();
1778+ } else if(q.isFrame() || q.isArrow() || q.isEntry()) {
1779+ q.west();
17771780 } else if(q.isDone()) {
17781781 q.east();
17791782 etat = S.FRR_E;
--- nina/java/src/net/morilib/nina/Quadro.java (revision 668)
+++ nina/java/src/net/morilib/nina/Quadro.java (revision 669)
@@ -89,6 +89,7 @@
8989 static final int WARP3 = -402;
9090 static final int FRAME_N = -501;
9191 static final int FRAME_A = -502;
92+ static final int FRAME_SKIP = -503;
9293 static final int BRANCH = -5000000;
9394 static final int BRANCH_N = 1000;
9495 static final int BRANCH_E = 100;
@@ -392,6 +393,8 @@
392393 set(FRAME_A);
393394 } else if(get() == '*' || get() == '=') {
394395 set(FRAME_N);
396+ } else if(get() == 's') {
397+ set(FRAME_SKIP);
395398 }
396399 }
397400
@@ -400,7 +403,7 @@
400403 * @return
401404 */
402405 public boolean isFrame() {
403- return get() == FRAME_N || get() == FRAME_A;
406+ return get() == FRAME_N || get() == FRAME_A || get() == FRAME_SKIP;
404407 }
405408
406409 /**
@@ -407,6 +410,14 @@
407410 *
408411 * @return
409412 */
413+ public boolean isFrameSkip() {
414+ return get() == FRAME_SKIP;
415+ }
416+
417+ /**
418+ *
419+ * @return
420+ */
410421 public boolean isArrow2() {
411422 return get() <= E2 && get() >= S2;
412423 }
--- nina/java/src/net/morilib/nina/TMBuilder.java (revision 668)
+++ nina/java/src/net/morilib/nina/TMBuilder.java (revision 669)
@@ -669,7 +669,15 @@
669669 vertex.accepted = accept;
670670 }
671671
672+ /* (non-Javadoc)
673+ * @see net.morilib.nina.NinaAction#setSkipSpaces(boolean)
674+ */
672675 @Override
676+ public void setSkipSpaces(boolean skipSpaces) {
677+ throw new NinaException("isnotdfa");
678+ }
679+
680+ @Override
673681 public void setEdgeDynamic(NinaEvent q, String var) {
674682 throw new NinaException("isnotdfa");
675683 }
--- nina/java/translator/net/morilib/nina/translate/AbstractNinaTranslator.java (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/AbstractNinaTranslator.java (revision 669)
@@ -116,6 +116,7 @@
116116 private Set<Integer> accepts = new HashSet<Integer>();
117117 private Set<Integer> deads = new HashSet<Integer>();
118118 private Set<Integer> emptyTransitions = new HashSet<Integer>();
119+ private Set<Integer> skipSpaces = new HashSet<Integer>();
119120 private Stack<DFAState<Object, ?, Void>> trz =
120121 new Stack<DFAState<Object, ?, Void>>();
121122 private Map<Range, String> rangeNameMap =
@@ -184,6 +185,9 @@
184185 ((DBS)state).isOnlyEmptyTransition()) {
185186 emptyTransitions.add(stateNo);
186187 }
188+ if(state instanceof DBS && ((DBS)state).isSkipSpaces()) {
189+ skipSpaces.add(stateNo);
190+ }
187191 trz.push(state);
188192 return stateNo++;
189193 }
@@ -277,6 +281,14 @@
277281
278282 /**
279283 *
284+ * @return
285+ */
286+ protected Set<Integer> skipSpacesIterable() {
287+ return skipSpaces;
288+ }
289+
290+ /**
291+ *
280292 * @param state
281293 * @return
282294 */
@@ -485,6 +497,12 @@
485497
486498 /**
487499 *
500+ * @param out
501+ */
502+ protected abstract void printSkipSpaces(PrintStream out);
503+
504+ /**
505+ *
488506 * @param ot
489507 * @param b1
490508 */
@@ -746,6 +764,7 @@
746764 q.isOptionDefined("useImmediateFunction") ? "t" : "");
747765 env.bind("IGNORE_CASE",
748766 q.isOptionDefined("ignoreCase") ? "t" : "");
767+ env.bind("SKIP_SPACES", q.getOptionNvl("whiteSpaces", " \\t\\n"));
749768
750769 if("prompt".equals(q.getOption("main"))) {
751770 env.bind("PUTPROMPT", "true");
@@ -1125,7 +1144,19 @@
11251144 }
11261145
11271146 });
1147+ cmd.putCommand("print_skipspaces", new ShProcess() {
11281148
1149+ @Override
1150+ public int main(ShEnvironment env, ShFileSystem fs,
1151+ InputStream stdin, PrintStream stdout,
1152+ PrintStream stderr,
1153+ String... args) throws IOException {
1154+ getsubfa(args).printSkipSpaces(stdout);
1155+ return 0;
1156+ }
1157+
1158+ });
1159+
11291160 if(o instanceof NFABuilder) {
11301161 machine = "nfa";
11311162 builder = (NFABuilder)o;
--- nina/java/translator/net/morilib/nina/translate/NinaTranslatorC.java (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/NinaTranslatorC.java (revision 669)
@@ -460,6 +460,14 @@
460460 }
461461
462462 /* (non-Javadoc)
463+ * @see net.morilib.nina.translate.AbstractNinaTranslator#printSkipSpaces(java.io.PrintStream)
464+ */
465+ @Override
466+ public void printSkipSpaces(PrintStream out) {
467+ printPStates(out, emptyTransitionsIterable());
468+ }
469+
470+ /* (non-Javadoc)
463471 * @see net.morilib.nina.translate.AbstractNinaTranslator#printAcceptToken(java.io.PrintStream)
464472 */
465473 @Override
--- nina/java/translator/net/morilib/nina/translate/NinaTranslatorCSharp.java (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/NinaTranslatorCSharp.java (revision 669)
@@ -722,6 +722,14 @@
722722 }
723723
724724 /* (non-Javadoc)
725+ * @see net.morilib.nina.translate.AbstractNinaTranslator#printSkipSpaces(java.io.PrintStream)
726+ */
727+ @Override
728+ public void printSkipSpaces(PrintStream out) {
729+ printPStates(out, skipSpacesIterable());
730+ }
731+
732+ /* (non-Javadoc)
725733 * @see net.morilib.nina.translate.AbstractNinaTranslator#printAcceptToken(java.io.PrintStream)
726734 */
727735 @Override
--- nina/java/translator/net/morilib/nina/translate/NinaTranslatorJava.java (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/NinaTranslatorJava.java (revision 669)
@@ -787,6 +787,14 @@
787787 }
788788
789789 /* (non-Javadoc)
790+ * @see net.morilib.nina.translate.AbstractNinaTranslator#printSkipSpaces(java.io.PrintStream)
791+ */
792+ @Override
793+ public void printSkipSpaces(PrintStream out) {
794+ printPStates(out, skipSpacesIterable());
795+ }
796+
797+ /* (non-Javadoc)
790798 * @see net.morilib.nina.translate.AbstractNinaTranslator#printAcceptToken(java.io.PrintStream)
791799 */
792800 @Override
--- nina/java/translator/net/morilib/nina/translate/NinaTranslatorJavaScript.java (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/NinaTranslatorJavaScript.java (revision 669)
@@ -697,6 +697,14 @@
697697 }
698698
699699 /* (non-Javadoc)
700+ * @see net.morilib.nina.translate.AbstractNinaTranslator#printSkipSpaces(java.io.PrintStream)
701+ */
702+ @Override
703+ public void printSkipSpaces(PrintStream out) {
704+ printPStates(out, skipSpacesIterable());
705+ }
706+
707+ /* (non-Javadoc)
700708 * @see net.morilib.nina.translate.AbstractNinaTranslator#printAcceptToken(java.io.PrintStream)
701709 */
702710 @Override
--- nina/java/translator/net/morilib/nina/translate/NinaTranslatorXML.java (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/NinaTranslatorXML.java (revision 669)
@@ -493,6 +493,14 @@
493493 }
494494
495495 /* (non-Javadoc)
496+ * @see net.morilib.nina.translate.AbstractNinaTranslator#printSkipSpaces(java.io.PrintStream)
497+ */
498+ @Override
499+ public void printSkipSpaces(PrintStream out) {
500+ // do nothing
501+ }
502+
503+ /* (non-Javadoc)
496504 * @see net.morilib.nina.translate.AbstractNinaTranslator#printAcceptStates(java.io.PrintStream)
497505 */
498506 @Override
--- nina/java/translator/net/morilib/nina/translate/nina_template.dfa.cs.sh (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/nina_template.dfa.cs.sh (revision 669)
@@ -73,6 +73,7 @@
7373 int DeadState();
7474 int StateSize();
7575 int FinallyState();
76+ bool SkipSpaces();
7677 }
7778 EOF
7879
@@ -156,6 +157,13 @@
156157
157158 EOF
158159
160+[ -z "$TYPE" ] && cat << EOF
161+ bool _isWhiteSpace(int ch) {
162+ return "$SKIP_SPACES".IndexOf((char)ch) >= 0;
163+ }
164+
165+EOF
166+
159167 [ -n "$ENABLE_INDENT" ] && cat << EOF
160168 private int _indent;
161169 private int _indentBefore;
@@ -1109,6 +1117,12 @@
11091117 return "${ch1}";
11101118 }
11111119
1120+ public bool SkipSpaces() {
1121+EOF
1122+ print_skipspaces $i
1123+ cat << EOF
1124+ }
1125+
11121126 }
11131127 EOF
11141128 done
@@ -1415,7 +1429,21 @@
14151429 }
14161430 else if(!__stk[__slen - 1].Dead())
14171431 {
1432+EOF
1433+ [ -z "$TYPE" ] && cat << EOF
1434+ if(__stk[__slen - 1].SkipSpaces())
1435+ {
1436+ while(_isWhiteSpace(c = _Read()));
1437+ }
1438+ else
1439+ {
1440+ c = _Read();
1441+ }
1442+EOF
1443+ [ -z "$TYPE" ] || cat << EOF
14181444 c = _Read();
1445+EOF
1446+ cat << EOF
14191447 }
14201448 else if(b)
14211449 {
--- nina/java/translator/net/morilib/nina/translate/nina_template.dfa.java.sh (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/nina_template.dfa.java.sh (revision 669)
@@ -86,6 +86,7 @@
8686 abstract int deadState();
8787 abstract int stateSize();
8888 abstract int finallyState();
89+ abstract boolean isSkipSpaces();
8990 }
9091 EOF
9192
@@ -166,6 +167,13 @@
166167
167168 EOF
168169
170+[ -z "$TYPE" ] && cat << EOF
171+ boolean _isWhiteSpace(int ch) {
172+ return "$SKIP_SPACES".indexOf(ch) >= 0;
173+ }
174+
175+EOF
176+
169177 [ -n "$ENABLE_INDENT" ] && cat << EOF
170178 private int $indent;
171179 private int $indentBefore;
@@ -999,6 +1007,12 @@
9991007 return "${ch1}";
10001008 }
10011009
1010+ boolean isSkipSpaces() {
1011+EOF
1012+ print_skipspaces $i
1013+ cat << EOF
1014+ }
1015+
10021016 };
10031017 EOF
10041018 done
@@ -1249,7 +1263,18 @@
12491263 if(__stk[__slen - 1].isEmptyTransition()) {
12501264 // do nothing
12511265 } else if(!__stk[__slen - 1].isDead()) {
1266+EOF
1267+ [ -z "$TYPE" ] && cat << EOF
1268+ if(__stk[__slen - 1].isSkipSpaces()) {
1269+ while(_isWhiteSpace(c = _read()));
1270+ } else {
1271+ c = _read();
1272+ }
1273+EOF
1274+ [ -z "$TYPE" ] || cat << EOF
12521275 c = _read();
1276+EOF
1277+ cat << EOF
12531278 } else if(b) {
12541279 __logprint("accept " + __stk[__slen - 1]);
12551280 st[0] = NINA_ACCEPT; return $nullsym;
--- nina/java/translator/net/morilib/nina/translate/nina_template.dfa.js.sub1.sh (revision 668)
+++ nina/java/translator/net/morilib/nina/translate/nina_template.dfa.js.sub1.sh (revision 669)
@@ -62,6 +62,13 @@
6262
6363 EOF
6464
65+[ -z "$TYPE" ] && cat << EOF
66+ this._isWhiteSpace = function(ch) {
67+ return "$SKIP_SPACES".indexOf(String.fromCharCode(ch)) >= 0;
68+ }
69+
70+EOF
71+
6572 [ -n "$ENABLE_BACKTRACK" ] && cat << EOF
6673 this.__backtrack = null;
6774 this.__backtrack_ptr = -1;
@@ -745,6 +752,12 @@
745752 cat << EOF
746753 }
747754
755+${CLASSNAME}.ENGINE_${ch1}.skipSpaces = function($this) {
756+EOF
757+ print_skipspaces $i
758+ cat << EOF
759+}
760+
748761 ${CLASSNAME}.ENGINE_${ch1}.toString = function() {
749762 return "${ch1}";
750763 }
@@ -952,7 +965,18 @@
952965 if(this.__stk[this.__slen - 1].emptyTransition(this)) {
953966 // do nothing
954967 } else if(!this.__stk[this.__slen - 1].dead(this)) {
968+EOF
969+ [ -z "$TYPE" ] && cat << EOF
970+ if(this.__stk[this.__slen - 1].skipSpaces(this)) {
971+ while(this._isWhiteSpace(c = this._read(rd)));
972+ } else {
973+ c = this._read(rd);
974+ }
975+EOF
976+ [ -z "$TYPE" ] || cat << EOF
955977 c = this._read(rd);
978+EOF
979+ cat << EOF
956980 } else if(b) {
957981 this.__logprint("accept " + this.__stk[this.__slen - 1].toString());
958982 st[0] = NINA_ACCEPT; return null;
Show on old repository browser