Implements CollationRuleParser.Sink.
509730
@Override
    void addRelation(int strength, CharSequence prefix, CharSequence str, CharSequence extension) {
        String nfdPrefix;
        if(prefix.length() == 0) {
            nfdPrefix = "";
        } else {
            nfdPrefix = nfd.normalize(prefix);
        }
        String nfdString = nfd.normalize(str);

        // The runtime code decomposes Hangul syllables on the fly,
        // with recursive processing but without making the Jamo pieces visible for matching.
        // It does not work with certain types of contextual mappings.
        int nfdLength = nfdString.length();
        if(nfdLength >= 2) {
            char c = nfdString.charAt(0);
            if(Hangul.isJamoL(c) || Hangul.isJamoV(c)) {
                // While handling a Hangul syllable, contractions starting with Jamo L or V
                // would not see the following Jamo of that syllable.
                throw new UnsupportedOperationException(
                        "contractions starting with conjoining Jamo L or V not supported");
            }
            c = nfdString.charAt(nfdLength - 1);
            if(Hangul.isJamoL(c) ||
                    (Hangul.isJamoV(c) && Hangul.isJamoL(nfdString.charAt(nfdLength - 2)))) {
                // A contraction ending with Jamo L or L+V would require
                // generating Hangul syllables in addTailComposites() (588 for a Jamo L),
                // or decomposing a following Hangul syllable on the fly, during contraction matching.
                throw new UnsupportedOperationException(
                        "contractions ending with conjoining Jamo L or L+V not supported");
            }
            // A Hangul syllable completely inside a contraction is ok.
        }
        // Note: If there is a prefix, then the parser checked that
        // both the prefix and the string beging with NFC boundaries (not Jamo V or T).
        // Therefore: prefix.isEmpty() || !isJamoVOrT(nfdString.charAt(0))
        // (While handling a Hangul syllable, prefixes on Jamo V or T
        // would not see the previous Jamo of that syllable.)

        if(strength != Collator.IDENTICAL) {
            // Find the node index after which we insert the new tailored node.
            int index = findOrInsertNodeForCEs(strength);
            assert(cesLength > 0);
            long ce = ces[cesLength - 1];
            if(strength == Collator.PRIMARY && !isTempCE(ce) && (ce >>> 32) == 0) {
                // There is no primary gap between ignorables and the space-first-primary.
                throw new UnsupportedOperationException(
                        "tailoring primary after ignorables not supported");
            }
            if(strength == Collator.QUATERNARY && ce == 0) {
                // The CE data structure does not support non-zero quaternary weights
                // on tertiary ignorables.
                throw new UnsupportedOperationException(
                        "tailoring quaternary after tertiary ignorables not supported");
            }
            // Insert the new tailored node.
            index = insertTailoredNodeAfter(index, strength);
            // Strength of the temporary CE:
            // The new relation may yield a stronger CE but not a weaker one.
            int tempStrength = ceStrength(ce);
            if(strength < tempStrength) { tempStrength = strength; }
            ces[cesLength - 1] = tempCEFromIndexAndStrength(index, tempStrength);
        }

        setCaseBits(nfdString);

        int cesLengthBeforeExtension = cesLength;
        if(extension.length() != 0) {
            String nfdExtension = nfd.normalize(extension);
            cesLength = dataBuilder.getCEs(nfdExtension, ces, cesLength);
            if(cesLength > Collation.MAX_EXPANSION_LENGTH) {
                throw new IllegalArgumentException(
                        "extension string adds too many collation elements (more than 31 total)");
            }
        }
        int ce32 = Collation.UNASSIGNED_CE32;
        if((!nfdPrefix.contentEquals(prefix) || !nfdString.contentEquals(str)) &&
                !ignorePrefix(prefix) && !ignoreString(str)) {
            // Map from the original input to the CEs.
            // We do this in case the canonical closure is incomplete,
            // so that it is possible to explicitly provide the missing mappings.
            ce32 = addIfDifferent(prefix, str, ces, cesLength, ce32);
        }
        addWithClosure(nfdPrefix, nfdString, ces, cesLength, ce32);
        cesLength = cesLengthBeforeExtension;
    }
1336502
private <IN> void executeDataSink(GenericDataSinkBase<?> sink, int superStep) throws Exception {
		Operator<?> inputOp = sink.getInput();
		if (inputOp == null) {
			throw new InvalidProgramException("The data sink " + sink.getName() + " has no input.");
		}
		
		@SuppressWarnings("unchecked")
		List<IN> input = (List<IN>) execute(inputOp);
		
		@SuppressWarnings("unchecked")
		GenericDataSinkBase<IN> typedSink = (GenericDataSinkBase<IN>) sink;

		// build the runtime context and compute broadcast variables, if necessary
		TaskInfo taskInfo = new TaskInfo(typedSink.getName(), 1, 0, 1, 0);
		RuntimeUDFContext ctx;

		MetricGroup metrics = new UnregisteredMetricsGroup();
			
		if (RichOutputFormat.class.isAssignableFrom(typedSink.getUserCodeWrapper().getUserCodeClass())) {
			ctx = superStep == 0 ? new RuntimeUDFContext(taskInfo, userCodeClassLoader, executionConfig, cachedFiles, accumulators, metrics) :
					new IterationRuntimeUDFContext(taskInfo, userCodeClassLoader, executionConfig, cachedFiles, accumulators, metrics);
		} else {
			ctx = null;
		}

		typedSink.executeOnCollections(input, ctx, executionConfig);
	}
1176434
public final Sink sink(final Sink sink) {
    return new Sink() {
      @Override public void write(Buffer source, long byteCount) throws IOException {
        boolean throwOnTimeout = false;
        enter();
        try {
          sink.write(source, byteCount);
          throwOnTimeout = true;
        } catch (IOException e) {
          throw exit(e);
        } finally {
          exit(throwOnTimeout);
        }
      }

      @Override public void flush() throws IOException {
        boolean throwOnTimeout = false;
        enter();
        try {
          sink.flush();
          throwOnTimeout = true;
        } catch (IOException e) {
          throw exit(e);
        } finally {
          exit(throwOnTimeout);
        }
      }

      @Override public void close() throws IOException {
        boolean throwOnTimeout = false;
        enter();
        try {
          sink.close();
          throwOnTimeout = true;
        } catch (IOException e) {
          throw exit(e);
        } finally {
          exit(throwOnTimeout);
        }
      }

      @Override public Timeout timeout() {
        return AsyncTimeout.this;
      }

      @Override public String toString() {
        return "AsyncTimeout.sink(" + sink + ")";
      }
    };
  }
459913
public final void ruleParserRule() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXtext.g:241:2: ( ( ( rule__ParserRule__Group__0 ) ) )
            // InternalXtext.g:242:2: ( ( rule__ParserRule__Group__0 ) )
            {
            // InternalXtext.g:242:2: ( ( rule__ParserRule__Group__0 ) )
            // InternalXtext.g:243:3: ( rule__ParserRule__Group__0 )
            {
             before(grammarAccess.getParserRuleAccess().getGroup()); 
            // InternalXtext.g:244:3: ( rule__ParserRule__Group__0 )
            // InternalXtext.g:244:4: rule__ParserRule__Group__0
            {
            pushFollow(FollowSets000.FOLLOW_2);
            rule__ParserRule__Group__0();

            state._fsp--;


            }

             after(grammarAccess.getParserRuleAccess().getGroup()); 

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
245900
def patch(source, sink):
    
    sink = sink()
    for v in source():
        try:
            sink.send(v)
        except StopIteration:
            return
1128173
@Override
  public void sinkPrepare(FlowProcess<? extends Configuration> flowProcess, SinkCall<Corc, OutputCollector> sinkCall)
      throws IOException {
    sinkCall.setContext(new Corc(typeInfo, converterFactory));
  }
1303175
Set<NFAState<T>> nfaTransitsFor(CharRange condition)
    {
        Set<NFAState<T>> nset = new NumSet<>();
        for (NFAState<T> nfa : nfaSet)
        {
            nset.addAll(nfa.transit(condition));
        }
        return nset;
    }
315534
private final void internalBuildTailoring(String rules) throws Exception {
        CollationTailoring base = CollationRoot.getRoot();
        // Most code using Collator does not need to build a Collator from rules.
        // By using reflection, most code will not have a static dependency on the builder code.
        // CollationBuilder builder = new CollationBuilder(base);
        ClassLoader classLoader = ClassLoaderUtil.getClassLoader(getClass());
        CollationTailoring t;
        try {
            Class<?> builderClass = classLoader.loadClass("android.icu.impl.coll.CollationBuilder");
            Object builder = builderClass.getConstructor(CollationTailoring.class).newInstance(base);
            // builder.parseAndBuild(rules);
            Method parseAndBuild = builderClass.getMethod("parseAndBuild", String.class);
            t = (CollationTailoring)parseAndBuild.invoke(builder, rules);
        } catch(InvocationTargetException e) {
            throw (Exception)e.getTargetException();
        }
        t.actualLocale = null;
        adoptTailoring(t);
    }
29802
public static void profileRulesOnText(String contents,
                                        JLanguageTool lt) throws IOException {
    long[] workTime = new long[10];
    List<Rule> rules = lt.getAllActiveRules();
    int ruleCount = rules.size();
    System.out.printf("Testing %d rules%n", ruleCount);
    System.out.println("Rule ID\tTime\tSentences\tMatches\tSentences per sec.");
    List<String> sentences = lt.sentenceTokenize(contents);
    for (Rule rule : rules) {
      if (rule instanceof TextLevelRule) {
        continue; // profile rules for sentences only
      }
      int matchCount = 0;
      for (int k = 0; k < 10; k++) {
        long startTime = System.currentTimeMillis();
        for (String sentence : sentences) {
          matchCount += rule.match
                  (lt.getAnalyzedSentence(sentence)).length;
        }
        long endTime = System.currentTimeMillis();
        workTime[k] = endTime - startTime;
      }
      long time = median(workTime);
      float timeInSeconds = time / 1000.0f;
      float sentencesPerSecond = sentences.size() / timeInSeconds;
      System.out.printf(Locale.ENGLISH,
              "%s\t%d\t%d\t%d\t%.1f", rule.getId(),
              time, sentences.size(), matchCount, sentencesPerSecond);
      System.out.println();
    }
  }
318881
def _nest_at_rules(self, rule, scope, block):
        
        # TODO handle @charset, probably?
        # Interpolate the current block
        # TODO this seems like it should be done in the block header.  and more
        # generally?
        calculator = self._make_calculator(rule.namespace)
        if block.header.argument:
            # TODO is this correct?  do ALL at-rules ALWAYS allow both vars and
            # interpolation?
            node = calculator.parse_vars_and_interpolations(
                block.header.argument)
            block.header.argument = node.evaluate(calculator).render()

        # TODO merge into RuleAncestry
        new_ancestry = list(rule.ancestry.headers)
        if block.directive == '@media' and new_ancestry:
            for i, header in reversed(list(enumerate(new_ancestry))):
                if header.is_selector:
                    continue
                elif header.directive == '@media':
                    new_ancestry[i] = BlockAtRuleHeader(
                        '@media',
                        "%s and %s" % (header.argument, block.argument))
                    break
                else:
                    new_ancestry.insert(i, block.header)
            else:
                new_ancestry.insert(0, block.header)
        else:
            new_ancestry.append(block.header)

        rule.descendants += 1
        new_rule = SassRule(
            source_file=rule.source_file,
            import_key=rule.import_key,
            lineno=block.lineno,
            num_header_lines=block.header.num_lines,
            unparsed_contents=block.unparsed_contents,

            legacy_compiler_options=rule.legacy_compiler_options,
            options=rule.options.copy(),
            #properties
            #extends_selectors
            ancestry=RuleAncestry(new_ancestry),

            namespace=rule.namespace.derive(),
            nested=rule.nested + 1,
        )
        self.rules.append(new_rule)
        rule.namespace.use_import(rule.source_file)
        self.manage_children(new_rule, scope)

        self._warn_unused_imports(new_rule)
790996
@Override
    public void emitToString(Sink sink, String indent, Constructor constructor) {
    	logger.finest("Generating toString() for " + constructor.name);
        sink.write(indent + "@Override\n");
        sink.write(indent + "public String toString() {\n");
        sink.write(indent + "   return \"" + constructor.name);
        if (!constructor.args.isEmpty()) {
            sink.write("(");
            boolean first = true;
            for (Arg arg : constructor.args) {
                if (first) {
                    first = false;
                } else {
                    sink.write(", ");
                }
                sink.write(arg.name + " = \" + " + arg.name + " + \"");
            }
            sink.write(")");
        }
        sink.write("\";\n");
        sink.write(indent + "}");
    }
967872
def parse(scanner, rules, scope = ParserScope.empty)
      (rule = rules[rule_name]) && rule.parse(scanner, rules, scope)
    end
121645
public final void ruleEOF() throws RecognitionException {

        		int stackSize = keepStackSize();
        	
        try {
            // InternalXtext.g:1358:2: ( ( ( rule__EOF__Group__0 ) ) )
            // InternalXtext.g:1359:2: ( ( rule__EOF__Group__0 ) )
            {
            // InternalXtext.g:1359:2: ( ( rule__EOF__Group__0 ) )
            // InternalXtext.g:1360:3: ( rule__EOF__Group__0 )
            {
             before(grammarAccess.getEOFAccess().getGroup()); 
            // InternalXtext.g:1361:3: ( rule__EOF__Group__0 )
            // InternalXtext.g:1361:4: rule__EOF__Group__0
            {
            pushFollow(FollowSets000.FOLLOW_2);
            rule__EOF__Group__0();

            state._fsp--;


            }

             after(grammarAccess.getEOFAccess().getGroup()); 

            }


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {

            	restoreStackSize(stackSize);

        }
        return ;
    }
960529
@Override
  public void executeReport (final Locale locale) throws MavenReportException
  {
    final Sink sink = getSink ();

    createReportHeader (getBundle (locale), sink);

    final File [] sourceDirs = getSourceDirectories ();
    for (final File sourceDir : sourceDirs)
    {
      final GrammarInfo [] grammarInfos = scanForGrammars (sourceDir);

      if (grammarInfos == null)
      {
        getLog ().debug ("Skipping non-existing source directory: " + sourceDir);
      }
      else
      {
        Arrays.sort (grammarInfos, GrammarInfoComparator.getInstance ());
        for (final GrammarInfo grammarInfo : grammarInfos)
        {
          final File grammarFile = grammarInfo.getGrammarFile ();

          String relativeOutputFileName = grammarInfo.getRelativeGrammarFile ();
          relativeOutputFileName = relativeOutputFileName.replaceAll ("(?i)\\.(jj|jjt|jtb)$",
                                                                      getOutputFileExtension ());

          final File jjdocOutputFile = new File (getJJDocOutputDirectory (), relativeOutputFileName);

          final JJDoc jjdoc = newJJDoc ();
          jjdoc.setInputFile (grammarFile);
          jjdoc.setOutputFile (jjdocOutputFile);
          try
          {
            jjdoc.run ();
          }
          catch (final Exception e)
          {
            throw new MavenReportException ("Failed to create BNF documentation: " + grammarFile, e);
          }

          createReportLink (sink, sourceDir, grammarFile, relativeOutputFileName);
        }
      }
    }

    createReportFooter (sink);
    sink.flush ();
    sink.close ();
  }
1126640
def consume_rules(flags = {})
      rules = []

      while token = @tokens.consume
        case token[:node]
          # Non-standard. Spec says to discard comments and whitespace, but we
          # keep them so we can serialize faithfully.
        when :comment, :whitespace
          rules << token

        when :cdc, :cdo
          unless flags[:top_level]
            @tokens.reconsume
            rule = consume_qualified_rule
            rules << rule if rule
          end

        when :at_keyword
          @tokens.reconsume
          rule = consume_at_rule
          rules << rule if rule

        else
          @tokens.reconsume
          rule = consume_qualified_rule
          rules << rule if rule
        end
      end

      rules
    end
1103478
function sink (msg, done) {
    var metric = msg.metric
    var as_text = JSON.stringify(metric, null, 1)

    console.log(as_text)

    done()
  }
671789
def get_collation(self):
        
        buf = readall(self, Collation.wire_size)
        return Collation.unpack(buf)