Exemplo n.º 1
0
 /** From label A build Graph o-A->o */
 public Handle tokenRef(TerminalAST node) {
   ATNState left = newState(node);
   ATNState right = newState(node);
   int ttype = g.getTokenType(node.getText());
   left.addTransition(new AtomTransition(right, ttype));
   node.atnState = left;
   return new Handle(left, right);
 }
Exemplo n.º 2
0
 @Override
 public Handle tokenRef(TerminalAST node) {
   // Ref to EOF in lexer yields char transition on -1
   if (node.getText().equals("EOF")) {
     ATNState left = newState(node);
     ATNState right = newState(node);
     left.addTransition(new AtomTransition(right, IntStream.EOF));
     return new Handle(left, right);
   }
   return _ruleRef(node);
 }
Exemplo n.º 3
0
 /**
  * For a lexer, a string is a sequence of char to match. That is, "fog" is treated as 'f' 'o' 'g'
  * not as a single transition in the DFA. Machine== o-'f'->o-'o'->o-'g'->o and has n+1
  * states for n characters.
  */
 @Override
 public Handle stringLiteral(TerminalAST stringLiteralAST) {
   String chars = stringLiteralAST.getText();
   chars = CharSupport.getStringFromGrammarStringLiteral(chars);
   int n = chars.length();
   ATNState left = newState(stringLiteralAST);
   ATNState prev = left;
   ATNState right = null;
   for (int i = 0; i < n; i++) {
     right = newState(stringLiteralAST);
     prev.addTransition(new AtomTransition(right, chars.charAt(i)));
     prev = right;
   }
   stringLiteralAST.atnState = left;
   return new Handle(left, right);
 }