Git Product home page Git Product logo

tcl-parser's Introduction

tcl-parser

An extension for Tcl, written in C, that lets Tcl scripts access Tcl's own parser via the parse command.

http://wiki.tcl.tk/1660

Overview

This command parses a Tcl script into "commands, words" and tokens.

Each of the commands below takes a script to parse and a range into the script. The command parses the script from the first index up to and including the last index.

The return of each command is a list of tuples indicating the ranges of each sub-element. Use the returned indices as arguments to [parse getString] to extract the parsed string from the script.

Example

load {} parser

proc stringRange {string start step} {
  tailcall string range $string $start [expr {$start+$step-1}]
}

proc ss {script} {
  set restRange {0 end}
  while {1} {
    lassign [parse command $script $restRange] commentRange commandRange restRange tree
    set comment [stringRange $script {*}$commentRange]
    set command [stringRange $script {*}$commandRange]
    if {$command eq ""} { break }
    lappend result [list $comment $command]
  }
  return $result
}

set parsed [ss {
  # set foo first
  set foo [list \
    one \
    two \
    three
  ]
  # set bar and puts the result
  set bar $foo;puts $bar
  if {$foo eq $bar} {
    puts "$foo is $bar"
    ::http::geturl http://www.google.com \
      -command [list myProc]
  }
}]

Useful Links & References

Copyright (c) 1999-2000 Ajuba Solutions

This is the Tcl parser component used by the checker to parse a Tcl script into commands, words and tokens.

tcl-parser's People

Contributors

bradennapier avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.