• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala TerminalNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.antlr.v4.runtime.tree.TerminalNode的典型用法代码示例。如果您正苦于以下问题:Scala TerminalNode类的具体用法?Scala TerminalNode怎么用?Scala TerminalNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TerminalNode类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: ParserUtils

//设置package包名称以及导入依赖的类
package definiti.core.utils

import definiti.core.{ParameterDefinition, Position, Range, TypeReference}
import org.antlr.v4.runtime.tree.TerminalNode
import org.antlr.v4.runtime.{ParserRuleContext, Token}

import scala.collection.mutable.ListBuffer

private[core] object ParserUtils {
  def extractStringContent(string: String): String = {
    var temporaryResult = string
    if (temporaryResult.startsWith("\"")) {
      temporaryResult = temporaryResult.substring(1)
    }
    if (temporaryResult.endsWith("\"")) {
      temporaryResult = temporaryResult.substring(0, temporaryResult.length - 1)
    }
    temporaryResult
  }

  def extractDocComment(string: String): String = {
    var temporaryResult = string
    if (temporaryResult.startsWith("")) {
      temporaryResult = temporaryResult.substring(0, temporaryResult.length - 2)
    }
    temporaryResult
  }

  def getRangeFromContext(context: ParserRuleContext): Range = {
    def position(token: Token): Position = {
      if (token == null) {
        Position(0, 0)
      } else {
        Position(token.getLine, token.getCharPositionInLine)
      }
    }

    Range(position(context.getStart), position(context.getStop))
  }

  def getRangeFromTerminalNode(terminalNode: TerminalNode): Range = {
    val symbol = terminalNode.getSymbol
    Range(
      Position(symbol.getLine, symbol.getStartIndex),
      Position(symbol.getLine, symbol.getStopIndex)
    )
  }

  def getRangeFromToken(token: Token): Range = {
    Range(
      Position(token.getLine, token.getStartIndex),
      Position(token.getLine, token.getStopIndex)
    )
  }

  def appendIfDefined[A, B](element: A, buffer: ListBuffer[B], transformer: A => B): Unit = {
    if (element != null) {
      buffer.append(transformer(element))
    }
  }
} 
开发者ID:definiti,项目名称:definiti-core,代码行数:62,代码来源:ParserUtils.scala


示例2: VerificationContextMock

//设置package包名称以及导入依赖的类
package definiti.core.mock.antlr

import java.util

import definiti.core.parser.antlr.DefinitiParser.{VerifyingContext, _}
import definiti.core.utils.CollectionUtils._
import org.antlr.v4.runtime.Token
import org.antlr.v4.runtime.tree.TerminalNode

case class VerificationContextMock(
  verificationNameToken: Token,
  verificationMessageToken: Token,
  functionContext: FunctionContext,
  identifier: TerminalNode,
  string: TerminalNode,
  docComment: TerminalNode
) extends VerificationContext(null, 0) {
  this.verificationName = verificationNameToken

  this.verificationMessage = verificationMessageToken

  override def function(): FunctionContext = functionContext

  override def IDENTIFIER(): TerminalNode = identifier

  override def STRING(): TerminalNode = string

  override def DOC_COMMENT(): TerminalNode = docComment
}

case class VerifyingListContextMock(
  verifyingContexts: Seq[VerifyingContext]
) extends VerifyingListContext(null, 0) {
  override def verifying(): util.List[VerifyingContext] = javaList(verifyingContexts)

  override def verifying(i: Int): VerifyingContext = verifyingContexts(i)
}

case class VerifyingContextMock(
  verificationNameToken: Token,
  messageToken: Option[Token]
) extends VerifyingContext(null, 0) {
  this.verificationName = verificationNameToken
  this.message = messageToken.orNull

  override def IDENTIFIER(): TerminalNode = TerminalNodeMock(verificationNameToken)

  override def STRING(): TerminalNode = messageToken.map(TerminalNodeMock(_)).orNull
} 
开发者ID:definiti,项目名称:definiti-core,代码行数:50,代码来源:VerificationContextMock.scala


示例3: FunctionContextMock

//设置package包名称以及导入依赖的类
package definiti.core.mock.antlr

import java.util.{List => JList}

import definiti.core.parser.antlr.DefinitiParser._
import definiti.core.utils.CollectionUtils._
import org.antlr.v4.runtime.Token
import org.antlr.v4.runtime.tree.TerminalNode

case class FunctionContextMock(
  parameterListDefinitionContext: ParameterListDefinitionContext,
  chainedExpressionContext: ChainedExpressionContext,
  genericTypeListContext: GenericTypeListContext
) extends FunctionContext(null, 0) {
  override def parameterListDefinition(): ParameterListDefinitionContext = parameterListDefinitionContext

  override def chainedExpression(): ChainedExpressionContext = chainedExpressionContext

  override def genericTypeList(): GenericTypeListContext = genericTypeListContext
}

case class ParameterListDefinitionContextMock(
  parameterDefinitionContexts: Seq[ParameterDefinitionContext]
) extends ParameterListDefinitionContext(null, 0) {
  override def parameterDefinition(): JList[ParameterDefinitionContext] = javaList(parameterDefinitionContexts)

  override def parameterDefinition(i: Int): ParameterDefinitionContext = parameterDefinitionContexts(i)
}

case class ParameterDefinitionContextMock(
  parameterNameToken: Token,
  parameterTypeToken: Token,
  genericTypeListContext: GenericTypeListContext
) extends ParameterDefinitionContext(null, 0) {
  this.parameterName = parameterNameToken
  this.parameterType = parameterTypeToken

  override def IDENTIFIER(): JList[TerminalNode] = javaList(Seq(TerminalNodeMock(parameterNameToken), TerminalNodeMock(parameterTypeToken)))

  override def IDENTIFIER(i: Int): TerminalNode = IDENTIFIER().get(i)

  override def genericTypeList(): GenericTypeListContext = genericTypeListContext
} 
开发者ID:definiti,项目名称:definiti-core,代码行数:44,代码来源:FunctionContextMock.scala


示例4: GenericTypeListContextMock

//设置package包名称以及导入依赖的类
package definiti.core.mock.antlr

import java.util.{List => JList}

import definiti.core.parser.antlr.DefinitiParser._
import definiti.core.utils.CollectionUtils.javaList
import org.antlr.v4.runtime.tree.TerminalNode

case class GenericTypeListContextMock(
  genericTypeContexts: Seq[GenericTypeContext]
) extends GenericTypeListContext(null, 0) {
  override def genericType(): JList[GenericTypeContext] = javaList(genericTypeContexts)

  override def genericType(i: Int): GenericTypeContext = genericTypeContexts(i)
}

case class GenericTypeContextMock(
  identifier: TerminalNode,
  genericTypeListContext: Option[GenericTypeListContext]
) extends GenericTypeContext(null, 0) {
  override def IDENTIFIER(): TerminalNode = identifier

  override def genericTypeList(): GenericTypeListContext = genericTypeListContext.orNull
} 
开发者ID:definiti,项目名称:definiti-core,代码行数:25,代码来源:GenericTypesContextMock.scala


示例5: AntlrGenerator

//设置package包名称以及导入依赖的类
package definiti.core.generators.antlr

import definiti.core.generators.Generators
import definiti.core.mock.antlr.{TerminalNodeMock, TokenMock}
import org.antlr.v4.runtime.tree.TerminalNode
import org.antlr.v4.runtime.{ParserRuleContext, Token}
import org.scalacheck.Gen

object AntlrGenerator {
  lazy val anyBooleanNode: Gen[TerminalNode] = genNode(anyBooleanToken)
  lazy val anyBooleanToken: Gen[Token] = genToken(Generators.anyBooleanText)

  lazy val anyNumberNode: Gen[TerminalNode] = genNode(anyNumberToken)
  lazy val anyNumberToken: Gen[Token] = genToken(Generators.numberAsString)

  lazy val anyStringNode: Gen[TerminalNode] = genNode(anyStringToken)
  lazy val anyStringToken: Gen[Token] = genToken(Generators.anyString.map('"' + _ + '"'))

  lazy val anyIdentifierNode: Gen[TerminalNode] = genNode(anyIdentifierToken)
  lazy val anyIdentifierToken: Gen[Token] = genToken(Generators.anyIdentifier)

  lazy val anyBinaryOperatorNode: Gen[TerminalNode] = genNode(anyBinaryOperatorToken)
  lazy val anyBinaryOperatorToken: Gen[Token] = genToken(Gen.oneOf("*", "/", "%", "+", "-", "==", "!=", "<", "<=", ">", ">=", "&&", "||"))

  lazy val anyNotOperatorNode: Gen[TerminalNode] = genNode(anyNotOperatorToken)
  lazy val anyNotOperatorToken: Gen[Token] = genToken(Gen.const("!"))

  lazy val anyDocCommentNode: Gen[TerminalNode] = genNode(anyDocCommentToken)
  lazy val anyDocCommentToken: Gen[Token] = genToken(Generators.anyString.map(""))

  def genContext[A <: ParserRuleContext](gen: Gen[A]): Gen[A] = for {
    element <- gen
    startToken <- anyIdentifierToken
    stopToken <- anyIdentifierToken
  } yield {
    element.start = startToken
    element.stop = stopToken
    element
  }

  private def genNode(genToken: Gen[Token]): Gen[TerminalNode] = genToken.map(TerminalNodeMock(_))

  private def genToken(genText: Gen[String]): Gen[Token] = for {
    text <- genText
    line <- Gen.posNum[Int]
    startIndex <- Gen.posNum[Int]
    stopIndex <- Gen.posNum[Int]
  } yield {
    TokenMock(text, line, startIndex, stopIndex)
  }
} 
开发者ID:definiti,项目名称:definiti-core,代码行数:52,代码来源:AntlrGenerator.scala



注:本文中的org.antlr.v4.runtime.tree.TerminalNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Http类代码示例发布时间:2022-05-23
下一篇:
Scala PropSpec类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap